Skip to content

Commit

Permalink
Merge pull request #116 from Rushikesh-Sonawane99/shiksha-2.0
Browse files Browse the repository at this point in the history
Issue #PS-387 feat: Added functionality to mark and update learner backdated attendance along with retention feature if attendance already marked
  • Loading branch information
itsvick authored May 16, 2024
2 parents a701386 + 7c7b86f commit b43ecff
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 43 deletions.
2 changes: 1 addition & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"LOADING": "Loading",
"MARK": "Mark",
"MARK_MY_ATTENDANCE": "Mark My Attendance",
"MARK_STUDENT_ATTENDANCE": "Mark Student Attendance",
"MARK_CENTER_ATTENDANCE": "Mark Center Attendance",
"MARK_ATTENDANCE": "Mark Attendance",
"UPDATE_ATTENDANCE": "Update Attendance",
"SAVE": "Save",
Expand Down
2 changes: 1 addition & 1 deletion public/locales/hi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"LANGUAGE": "भाषा",
"MARK": "मार्क",
"MARK_MY_ATTENDANCE": "मेरी उपस्थिति चिह्नित करें",
"MARK_STUDENT_ATTENDANCE": "छात्र उपस्थिति चिह्नित करें",
"MARK_CENTER_ATTENDANCE": "केंद्र पर उपस्थिति दर्ज करें",
"MARK_ATTENDANCE": "उपस्थिति चिह्नित करें",
"UPDATE_ATTENDANCE": "उपस्थिति अपडेट करें",
"LOADING": "लोडिंग",
Expand Down
2 changes: 1 addition & 1 deletion public/locales/mr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"LANGUAGE": "भाषा",
"MARK": "मार्क",
"MARK_MY_ATTENDANCE": "माझ्या उपस्थितीचा चिन्ह करा",
"MARK_STUDENT_ATTENDANCE": "विद्यार्थी उपस्थितीचा चिन्ह करा",
"MARK_CENTER_ATTENDANCE": "केंद्र उपस्थिती चिन्हांकित करा",
"LOADING": "लोड होत आहे",
"SAVE": "साठवा",
"CLEAR_ALL": "सर्व काढा",
Expand Down
38 changes: 18 additions & 20 deletions src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import Snackbar, { SnackbarOrigin } from '@mui/material/Snackbar';
import {
attendanceInPercentageStatusList,
attendanceStatusList,
bulkAttendance,
markAttendance,
bulkAttendance
} from '../services/AttendanceService';
import {
formatDate,
Expand Down Expand Up @@ -92,7 +91,7 @@ const Dashboard: React.FC<DashboardProps> = () => {
const [openMarkAttendance, setOpenMarkAttendance] = React.useState(false);
const [openMarkUpdateAttendance, setOpenMarkUpdateAttendance] =
React.useState(false);
const [cohortMemberList, setCohortMemberList] = React.useState<Array<user>>(
const [cohortMemberList, setCohortMemberList] = React.useState<Array<{}>>(
[]
);
const [showDetails, setShowDetails] = React.useState(false);
Expand Down Expand Up @@ -191,6 +190,7 @@ const Dashboard: React.FC<DashboardProps> = () => {

//API for getting student list
useEffect(() => {
submitBulkAttendanceAction(true, '', '')
const getCohortMemberList = async () => {
setLoading(true);
// const parentCohortId = localStorage.getItem('parentCohortId');
Expand Down Expand Up @@ -274,33 +274,31 @@ const Dashboard: React.FC<DashboardProps> = () => {
name: string;
attendance: string;
}[] = [];

// Iterate over nameUserIdArray
nameUserIdArray.forEach((user) => {
const userId = user.userId;
// Find corresponding entry in userAttendanceArray
const attendanceEntry = userAttendanceArray.find(
(entry) => entry.userId === userId
);
if (attendanceEntry) {
// If found, merge properties and push to newArray
newArray.push({
userId,
name: user.name,
attendance: attendanceEntry.attendance,
});
}
});
// setCohortMemberList(newArray); //Getting issue updating attendance regardless of cohort id for mark all
if(newArray.length !=0){
setCohortMemberList(newArray);
setNumberOfCohortMembers(newArray?.length);
}else{
setCohortMemberList(nameUserIdArray);
setNumberOfCohortMembers(nameUserIdArray?.length);
}
return newArray;
};
mergeArrays(nameUserIdArray, userAttendanceArray);
}
}

//Add logic to merge response2 and nameUserIdArray
setCohortMemberList(nameUserIdArray); //check where to set cohort member list
setNumberOfCohortMembers(nameUserIdArray?.length);
setLoading(false);
};
userAttendanceStatusList();
Expand Down Expand Up @@ -334,7 +332,7 @@ const Dashboard: React.FC<DashboardProps> = () => {
if (classId.length) {
getCohortMemberList();
}
}, [classId]);
}, [classId, selectedDate]);

const showDetailsHandle = (dayStr: string) => {
setSelectedDate(formatSelectedDate(dayStr));
Expand Down Expand Up @@ -638,9 +636,9 @@ const Dashboard: React.FC<DashboardProps> = () => {
</Typography>
</Box>
</Box>
{/* {loading && (
{loading && (
<Loader showBackdrop={true} loadingText={t('COMMON.LOADING')} />
)} */}
)}
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Box
sx={{
Expand Down Expand Up @@ -902,7 +900,7 @@ const Dashboard: React.FC<DashboardProps> = () => {
fontSize={'16px'}
sx={{ color: theme.palette.warning['A200'] }}
>
{t('COMMON.MARK_STUDENT_ATTENDANCE')}
{t('COMMON.MARK_CENTER_ATTENDANCE')}
</Typography>
<Typography
variant="h2"
Expand All @@ -928,12 +926,12 @@ const Dashboard: React.FC<DashboardProps> = () => {
<Box
sx={{ height: '1px', background: '#D0C5B4' }}
></Box>
{/* {loading && (
{loading && (
<Loader
showBackdrop={true}
loadingText={t('COMMON.LOADING')}
/>
)} */}
)}

<Typography
sx={{
Expand Down Expand Up @@ -1083,12 +1081,12 @@ const Dashboard: React.FC<DashboardProps> = () => {
</Link>
</Box>
</Stack>
{/* {loading && (
{loading && (
<Loader
showBackdrop={true}
loadingText={t('COMMON.LOADING')}
/>
)} */}
)}
</Box>
{userType == 'Students' ? (
<Box display={'flex'} className="card_overview">
Expand Down
40 changes: 20 additions & 20 deletions src/services/AttendanceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ import {
AttendancePercentageProps,
} from '../utils/Interfaces';

export const markAttendance = async ({
userId,
attendanceDate,
attendance,
contextId,
}: AttendanceParams): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/attendance`;
try {
const response = await post(apiUrl, {
userId,
attendanceDate,
attendance,
contextId,
});
return response?.data;
} catch (error) {
console.error('error in marking attendance', error);
throw error;
}
};
// export const markAttendance = async ({
// userId,
// attendanceDate,
// attendance,
// contextId,
// }: AttendanceParams): Promise<any> => {
// const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/attendance`;
// try {
// const response = await post(apiUrl, {
// userId,
// attendanceDate,
// attendance,
// contextId,
// });
// return response?.data;
// } catch (error) {
// console.error('error in marking attendance', error);
// throw error;
// }
// };

export const bulkAttendance = async ({
attendanceDate,
Expand Down
18 changes: 18 additions & 0 deletions src/utils/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,21 @@ export const truncateURL = (
}
return url;
};

// debounce function
export const debounce = <T extends (...args: any[]) => any>(
func: T,
wait: number,
immediate?: boolean
) => {
let timeout: ReturnType<typeof setTimeout> | undefined;
return function (this: ThisParameterType<T>, ...args: Parameters<T>) {
const context = this;
clearTimeout(timeout!);
if (immediate && !timeout) func.apply(context, args);
timeout = setTimeout(() => {
timeout = undefined;
if (!immediate) func.apply(context, args);
}, wait);
};
};

0 comments on commit b43ecff

Please sign in to comment.