frontend_adaptive_learning/src/roles/user/dashboard/views/Dashboard.jsx

171 lines
5.2 KiB
React
Raw Normal View History

import { Container, Row, Col, Card, Button, ProgressBar } from 'react-bootstrap'
import newBie from '../../../../assets/images/illustration/emptyJourney.png'
import { Link, NavLink } from 'react-router-dom'
import useDashboards from '../hooks/useDashboards'
import { slugify } from '../../../../utils/Constant'
import Skeleton from 'react-loading-skeleton'
2024-10-31 02:32:14 +00:00
2024-11-25 10:00:25 +00:00
function validName(fullName) {
const nameArray = fullName.split(' ')
const firstTwoWords = nameArray.slice(0, 2).join(' ')
return firstTwoWords
2024-11-25 10:00:25 +00:00
}
2024-10-31 02:32:14 +00:00
const Dashboard = () => {
const { username } = JSON.parse(localStorage.getItem('userData'))
2024-10-31 02:32:14 +00:00
const { journey, loading, error, thumbPath } = useDashboards()
const noData = () => {
return journey.lenght == 0
}
2024-10-31 02:32:14 +00:00
if (error) {
return <div>Error: {error.message}</div>
}
2024-10-31 02:32:14 +00:00
return (
<div className="home-page">
<h1 className="text-blue text-capitalize fw-bold mb-1">
Hi, {validName(username)} !
</h1>
<p className="text-secondary">
Lets evolve together with adaptive learning tailored just for you.
</p>
<h4 className="text-blue mt-4 fw-bold">Your Last Journey!</h4>
<Container fluid className="bg-white rounded rounded-4 p-4">
<Row xs={1} className="filled-journey">
<Col className="mb-3">
{loading ? (
<>
<Card className="flex-row p-3 mb-3 border-0 shadow shadow-sm rounded-4">
<div className="w-100 d-flex">
<Skeleton
containerClassName="mb-2"
className="mb-2 rounded-4"
style={{ width: '10vw', height: '10vw' }}
/>
<div className="ps-2 d-flex flex-column justify-content-between">
<Skeleton
containerClassName="mb-2"
className="mb-2 rounded-4"
style={{ width: '20vw', height: '3vw' }}
/>
<Skeleton
containerClassName="mb-2"
className="mb-2 rounded-4"
style={{ width: '30vw', height: '2vw' }}
/>
</div>
<Skeleton
containerClassName="mb-2 mt-auto ms-auto"
className="mb-2 rounded-4"
style={{ width: '17vw', height: '4vw' }}
/>
</div>
</Card>
<Card className="flex-row p-3 mb-3 border-0 shadow shadow-sm rounded-4">
<div className="w-100 d-flex">
<Skeleton
containerClassName="mb-2"
className="mb-2 rounded-4"
style={{ width: '10vw', height: '10vw' }}
/>
<div className="ps-2 d-flex flex-column justify-content-between">
<Skeleton
containerClassName="mb-2"
className="mb-2 rounded-4"
style={{ width: '20vw', height: '3vw' }}
/>
<Skeleton
containerClassName="mb-2"
className="mb-2 rounded-4"
style={{ width: '30vw', height: '2vw' }}
/>
</div>
<Skeleton
containerClassName="mb-2 mt-auto ms-auto"
className="mb-2 rounded-4"
style={{ width: '17vw', height: '4vw' }}
/>
</div>
</Card>
</>
) : noData() ? (
<Col className="d-flex flex-column items-center">
<h4 className="mb-0">Still new?</h4>
<p className="fs-5 text-muted fw-light">Begin your journey!</p>
<img src={newBie} alt="" />
<Button
as={Link}
to={'/learning/module'}
variant="warning"
className="mt-4 py-2 px-5 rounded-35"
>
Explore
</Button>
</Col>
) : (
2024-12-20 09:56:29 +00:00
journey.map((data, index) => (
<Card
2024-12-20 09:56:29 +00:00
key={index}
className="flex-row p-3 mb-3 border-0 shadow shadow-sm rounded-4"
>
<Card.Img
variant="top"
src={
data.THUMBNAIL ? `${thumbPath}${data.THUMBNAIL}` : newBie
}
className="ratio ratio-1x1 rounded rounded-3 me-3"
/>
<Card.Body className="p-0 d-flex flex-column justify-content-between">
<div className="w-75">
<Card.Title>{data.NAME_SECTION}</Card.Title>
<Card.Text className="text-muted">
{data.DESCRIPTION_SECTION}
</Card.Text>
</div>
<div className="w-100 d-flex align-items-end">
<div className="w-75">
<div className="d-flex align-items-center">
<ProgressBar
now={(
(data.COMPLETED_TOPICS / data.TOTAL_TOPICS) *
100
).toFixed(0)}
className="w-75"
/>
<span className="text-blue ms-2">
{(
(data.COMPLETED_TOPICS / data.TOTAL_TOPICS) *
100
).toFixed(0)}
%
</span>
</div>
<p className="text-muted m-0">
{data.COMPLETED_TOPICS} / {data.TOTAL_TOPICS} Topics
</p>
</div>
<Button
as={NavLink}
to={`/learning/module/${slugify(data.NAME_SECTION)}`}
variant="warning"
className="ms-auto py-2 px-5 rounded-35"
>
Continue
</Button>
</div>
</Card.Body>
</Card>
))
)}
</Col>
</Row>
</Container>
</div>
)
}
2024-10-31 02:32:14 +00:00
export default Dashboard