53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
import React, { useEffect } from "react";
|
|
import { Link } from "react-router-dom";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import DashboardActions from "./DashboardActions";
|
|
import Experience from "./Experience";
|
|
import Education from "./Education";
|
|
import { getCurrentProfile, deleteAccount } from "../../actions/profile";
|
|
|
|
const Dashboard = () => {
|
|
const dispatch = useDispatch();
|
|
useEffect(() => {
|
|
function fetchData() {
|
|
dispatch(getCurrentProfile());
|
|
}
|
|
fetchData();
|
|
}, [dispatch]);
|
|
const user = useSelector((state) => state.auth.user);
|
|
const profile = useSelector((state) => state.profile.profile);
|
|
return (
|
|
<section className="container">
|
|
<h1 className="large text-primary">Dashboard</h1>
|
|
<p className="lead">
|
|
<i className="fas fa-user" /> Welcome {user && user.name}
|
|
</p>
|
|
{profile !== null ? (
|
|
<>
|
|
<DashboardActions />
|
|
<Experience experience={profile.experience} />
|
|
<Education education={profile.education} />
|
|
|
|
<div className="my-2">
|
|
<button
|
|
className="btn btn-danger"
|
|
onClick={async () => await dispatch(deleteAccount())}
|
|
>
|
|
<i className="fas fa-user" /> Delete My Account
|
|
</button>
|
|
</div>
|
|
</>
|
|
) : (
|
|
<>
|
|
<p>You have not yet setup a profile, please add some info</p>
|
|
<Link to="/create-profile" className="btn btn-primary my-1">
|
|
Create Profile
|
|
</Link>
|
|
</>
|
|
)}
|
|
</section>
|
|
);
|
|
};
|
|
|
|
export default Dashboard;
|