-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from PrerakMathur20/Dash
Created User Dashboard
- Loading branch information
Showing
2 changed files
with
240 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,160 @@ | ||
/* | ||
* Dashboard Page Component | ||
*/ | ||
|
||
// Import Dependecies | ||
import React from 'react'; | ||
import Layout from '../../components/core/Layout'; | ||
import ManagementLayout from '../../components/Management/ManagementLayout'; | ||
import ExtractorLayout from '../../components/Extractor/ExtractorLayout'; | ||
import ProfileCard from './ProfileCard'; | ||
import { makeStyles } from '@material-ui/core'; | ||
import { | ||
Container, | ||
Typography, | ||
Box, | ||
Grid | ||
} from '@material-ui/core'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import TaskCard from '../../components/Admin/TaskCard'; | ||
|
||
|
||
// custom styles | ||
const useStyle = makeStyles((theme) => ({ | ||
root: { | ||
marginTop: '10vh', | ||
height: '82.5vh', | ||
width: '100%', | ||
padding: `${theme.spacing(1)}px ${theme.spacing(2)}px`, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
margin: '20px' | ||
}, | ||
TaskList: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
justifyContent: 'center' | ||
} | ||
})) | ||
|
||
// Main Profile Component | ||
const Dashboard = () => { | ||
return ( | ||
<Layout sidebarBool={true}> | ||
<h1>Dashboard</h1> | ||
</Layout> | ||
) | ||
// custom styles | ||
const classes = useStyle() | ||
|
||
// get tasks from admin reducer | ||
const auth = useSelector(state => state.auth) | ||
|
||
// fetch tasks | ||
const tasksAdmin = useSelector(state => state.admin.tasks) | ||
const tasksManagement = useSelector(state => state.management.todoTasks) | ||
const tasksExtractor = useSelector(state => state.management.todoTasks) | ||
|
||
// If the role is admin | ||
if (auth.user.role === 'admin') { | ||
return ( | ||
<Layout sidebarBool={true}> | ||
<Container component="main" className={classes.root}> | ||
<Grid container spacing={3}> | ||
<Grid item xs={12}> | ||
<Typography variant="h4" component="h1" gutterBottom> | ||
Dashboard | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
<Grid container spacing={5}> | ||
<Grid item xs={12} sm={12} md={6}> | ||
<ProfileCard /> | ||
</Grid> | ||
<Grid item xs={12} sm={12} md={6}> | ||
<Box> | ||
{ | ||
(tasksAdmin.length > 0) ? | ||
tasksAdmin.map((tasksAdmin) => { | ||
return (<TaskCard {...tasksAdmin} key={tasksAdmin.id} />) | ||
|
||
}) | ||
: ( | ||
<span> Not Tasks Found.</span> | ||
) | ||
} | ||
</Box> | ||
</Grid> | ||
</Grid> | ||
</Container> | ||
</Layout> | ||
) | ||
} | ||
|
||
// If the role is management | ||
else if (auth.user.role === 'management') { | ||
return ( | ||
<ManagementLayout sidebarBool={true}> | ||
<Container component="main" className={classes.root}> | ||
<Grid container spacing={3}> | ||
<Grid item xs={12}> | ||
<Typography variant="h4" component="h1" gutterBottom> | ||
Dashboard | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
<Grid container spacing={5} > | ||
<Grid item xs={12} sm={12} md={6}> | ||
<ProfileCard /> | ||
</Grid> | ||
<Grid item xs={12} sm={12} md={6}> | ||
<Box> | ||
{ | ||
(tasksManagement.length > 0) ? | ||
tasksManagement.map((tasksManagement) => { | ||
return (<TaskCard {...tasksManagement} key={tasksManagement.id} />) | ||
|
||
}) | ||
: ( | ||
<span> Not Tasks Found.</span> | ||
) | ||
} | ||
</Box> | ||
</Grid> | ||
</Grid> | ||
</Container> | ||
</ManagementLayout> | ||
) | ||
} | ||
|
||
// If the role is extractor | ||
else if (auth.user.role === 'extractor') { | ||
return ( | ||
<ExtractorLayout sidebarBool={true}> | ||
<Container component="main" className={classes.root}> | ||
<Grid container spacing={3}> | ||
<Grid item xs={12}> | ||
<Typography variant="h4" component="h1" gutterBottom> | ||
Dashboard | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
<Grid container spacing={5} > | ||
<Grid item xs={12} sm={12} md={6}> | ||
<ProfileCard /> | ||
</Grid> | ||
<Grid item xs={12} sm={12} md={6}> | ||
<Box> | ||
{ | ||
(tasksExtractor.length > 0) ? | ||
tasksExtractor.map((tasksExtractor) => { | ||
return (<TaskCard {...tasksExtractor} key={tasksExtractor.id} />) | ||
|
||
}) | ||
: ( | ||
<span> Not Tasks Found.</span> | ||
) | ||
} | ||
</Box> | ||
</Grid> | ||
</Grid> | ||
</Container> | ||
</ExtractorLayout> | ||
) | ||
} | ||
} | ||
|
||
export default Dashboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
Functional component to render | ||
profie card component | ||
*/ | ||
|
||
import React from 'react' | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { | ||
Container, | ||
Typography, | ||
Avatar, | ||
ListItemText, | ||
} from '@material-ui/core'; | ||
import { useSelector } from 'react-redux'; | ||
import VerifyButton from '../../components/Utils/VerifyButton'; | ||
|
||
|
||
// Custom styles | ||
const useStyles = makeStyles((theme) => ({ | ||
root: { | ||
minWidth: theme.spacing(35), | ||
maxWidth: theme.spacing(40), | ||
padding: theme.spacing(2), | ||
border: '1px solid #aaa', | ||
borderRadius: '4px', | ||
display: 'table', | ||
flexDirection: 'column', | ||
justifyContent: 'flex-start', | ||
alignItems: 'flex-start', | ||
margin: `${theme.spacing(4)}px`, | ||
overflowx: 'scroll', | ||
}, | ||
icon: { | ||
width: '90px', | ||
height: '90px', | ||
fontSize: '1.5rem', | ||
float: 'right', | ||
position: 'relative', | ||
}, | ||
name: { | ||
fontSize: '1.2rem', | ||
fontWeight: '500', | ||
} | ||
})) | ||
|
||
|
||
|
||
function ProfileCard() { | ||
// auth reducer | ||
const classes = useStyles() | ||
const auth = useSelector(state => state.auth) | ||
|
||
// Profile Card Component | ||
return ( | ||
<Container component="main" className={classes.root}> | ||
|
||
<Avatar className={classes.icon}> | ||
{(auth && auth.user) ? auth.user.name.charAt(0).toUpperCase() : (<span>wait...</span>)} | ||
</Avatar> | ||
|
||
<Typography | ||
className={classes.name} | ||
> | ||
{auth && auth.user && auth.user.name.toUpperCase()} | ||
</Typography> | ||
|
||
<Typography | ||
variant="body1" | ||
component="h4" | ||
> | ||
<ListItemText primary={auth && auth.user && auth.user.role} /> | ||
</Typography> | ||
|
||
<Typography | ||
variant="body1" | ||
component="h4" | ||
> | ||
<ListItemText primary={auth && auth.user && auth.user.email} /> | ||
</Typography> | ||
|
||
{/* Verification status button */} | ||
<Typography> | ||
{(auth.user && !auth.isLoading) ? | ||
(<VerifyButton />) : | ||
(<span>wait...</span>) | ||
} | ||
</Typography> | ||
|
||
</Container> | ||
) | ||
} | ||
|
||
export default ProfileCard |