Commit 69bfdd59 authored by janithgamage1.ed's avatar janithgamage1.ed

fix: update

Desc : update project
parent 124b8d76
...@@ -26,9 +26,12 @@ import { GlobalFilter } from 'utils/react-table'; ...@@ -26,9 +26,12 @@ import { GlobalFilter } from 'utils/react-table';
// assets // assets
import { BookOutlined } from '@ant-design/icons'; import { BookOutlined } from '@ant-design/icons';
import { userProgress } from 'data/userProgress'; import useAuth from 'hooks/useAuth';
import CurriculumSection from 'sections/learning-management/learning-curriculums-subscribed/CurriculumSection'; import CurriculumSection from 'sections/learning-management/learning-curriculums-subscribed/CurriculumSection';
import EmptyCurriculumCard from 'sections/learning-management/learning-curriculums-subscribed/skeleton/EmptyCurriculumCard'; import EmptyCurriculumCard from 'sections/learning-management/learning-curriculums-subscribed/skeleton/EmptyCurriculumCard';
import { useDispatch, useSelector } from 'store';
import { openSnackbar } from 'store/reducers/snackbar';
import { fetchUserProgress, toInitialState } from 'store/reducers/userProgress';
import { curriculumTypeUserProgress, userProgressType } from 'types/userProgress'; import { curriculumTypeUserProgress, userProgressType } from 'types/userProgress';
// ==============================|| List ||============================== // // ==============================|| List ||============================== //
...@@ -46,6 +49,9 @@ const allColumns = [ ...@@ -46,6 +49,9 @@ const allColumns = [
const List = () => { const List = () => {
const theme = useTheme(); const theme = useTheme();
const dispatch = useDispatch();
const { userProgress, error, success, isLoading } = useSelector(state => state.userProgress);
const { user } = useAuth();
const [data, setData] = useState<userProgressType["curriculums"]>([]) const [data, setData] = useState<userProgressType["curriculums"]>([])
...@@ -61,7 +67,9 @@ const List = () => { ...@@ -61,7 +67,9 @@ const List = () => {
}; };
// search // search
useEffect(() => { useEffect(() => {
if (!data || data.length == 0) return
const newData = data?.filter((value: any) => { const newData = data?.filter((value: any) => {
if (globalFilter) { if (globalFilter) {
return value.curriculumTitle.toLowerCase().includes(globalFilter.toLowerCase()); return value.curriculumTitle.toLowerCase().includes(globalFilter.toLowerCase());
...@@ -83,16 +91,96 @@ const List = () => { ...@@ -83,16 +91,96 @@ const List = () => {
_DATA.jump(p); _DATA.jump(p);
}; };
useEffect(() => {
setData(userProgress.curriculums)
}, [])
const [expanded, setExpanded] = useState<string | false>('panel0'); const [expanded, setExpanded] = useState<string | false>('panel0');
const handleAccordionChange = (panel: string) => (event: React.SyntheticEvent, newExpanded: boolean) => { const handleAccordionChange = (panel: string) => (event: React.SyntheticEvent, newExpanded: boolean) => {
setExpanded(newExpanded ? panel : false); setExpanded(newExpanded ? panel : false);
}; };
/**
* API Config
* User Progress API
*/
useEffect(() => {
if (!user) {
// User is missing
dispatch(
openSnackbar({
open: true,
message: 'User data is missing',
variant: 'alert',
alert: {
color: 'warning',
},
close: true,
})
);
} else if (!user.id) {
// User ID is missing
dispatch(
openSnackbar({
open: true,
message: 'User ID is missing',
variant: 'alert',
alert: {
color: 'warning',
},
close: true,
})
);
} else {
dispatch(fetchUserProgress(user.id));
}
}, [dispatch]);
useEffect(() => {
if (userProgress) {
setData(userProgress?.curriculums);
}
}, [userProgress])
// handel error
useEffect(() => {
if (error != null) {
dispatch(
openSnackbar({
open: true,
//@ts-ignore
message: error ? error.Message : "Something went wrong ...",
variant: 'alert',
alert: {
color: 'error'
},
close: true
})
);
dispatch(toInitialState())
}
}, [error])
// handel success
useEffect(() => {
if (success != null) {
dispatch(
openSnackbar({
open: true,
message: success,
variant: 'alert',
alert: {
color: 'success'
},
close: true
})
);
dispatch(toInitialState())
}
}, [success])
if (isLoading) {
return <div>Loading...</div>;
}
return ( return (
<> <>
<Box sx={{ position: 'relative', marginBottom: 3 }}> <Box sx={{ position: 'relative', marginBottom: 3 }}>
......
...@@ -84,7 +84,7 @@ const CurriculumSection = ({ curriculum }: { curriculum: curriculumTypeUserProgr ...@@ -84,7 +84,7 @@ const CurriculumSection = ({ curriculum }: { curriculum: curriculumTypeUserProgr
</MainCard> </MainCard>
<MainCard title="Tutorials"> <MainCard title="Tutorials">
<Grid container spacing={2}> <Grid container spacing={2}>
{curriculum.tutorials?.map((tutorial, index) => { {curriculum.tutorials && curriculum.tutorials?.map((tutorial, index) => {
return (<TutorialSection tutorial={tutorial!} />) return (<TutorialSection tutorial={tutorial!} />)
})} })}
</Grid> </Grid>
......
...@@ -52,9 +52,7 @@ const CurriculumCard = ({ curriculum }: { curriculum: curriculumType }) => { ...@@ -52,9 +52,7 @@ const CurriculumCard = ({ curriculum }: { curriculum: curriculumType }) => {
* User Progress API * User Progress API
*/ */
const FollowCurriculum = () => { const FollowCurriculum = () => {
console.log(user);
if (!user) { if (!user) {
// User is missing // User is missing
dispatch( dispatch(
......
...@@ -50,7 +50,7 @@ const slice = createSlice({ ...@@ -50,7 +50,7 @@ const slice = createSlice({
// GET USER_PROGRESS // GET USER_PROGRESS
fetchUserProgressSuccess(state, action) { fetchUserProgressSuccess(state, action) {
state.userProgress = action.payload; state.userProgress = action.payload.userProgress;
state.success = null state.success = null
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment