diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 30b1a4d9..518751fc 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -42,6 +42,7 @@ "LAST_SIX_MONTHS": "Last Six Months", "CUSTOM_RANGE": "Custom Range", "NONE": "None", + "LEARNERS":"Learners", "LEARNER_NAME": "Learner Name", "DATE_RANGE": "Date Range", "SELECT_AN_OPTION": "Select an option" @@ -78,7 +79,7 @@ "MY_TEACHING_CENTERS": "My Teaching Centers", "UPCOMING_EXTRA_SESSION": "Upcoming Extra Sessions", "BACK_TO_TOP":"Back to Top", - "LEARNER":"Learners" + "LAST_SEVEN_DAYS_RANGE": "Last 7 Days {{date_range}})" }, "ATTENDANCE": { @@ -101,7 +102,10 @@ "DAY_WISE_ATTENDANCE": "Day-Wise Attendance", "ATTENDANCE_OVERVIEW": "Attendance Overview", "CENTER_ATTENDANCE": "Center Attendance", - "LOW_ATTENDANCE_STUDENTS": "Low Attendance Students" + "LOW_ATTENDANCE_STUDENTS": "Low Attendance Learners", + "N/A": "N/A.", + "CENTER_NAME": "Center Name", + "ALL_CENTERS": "All Centers" }, "PROFILE": { "EDIT_PROFILE": "Edit Profile", diff --git a/public/locales/hi/common.json b/public/locales/hi/common.json index 8b4f59ac..f8af3ec1 100644 --- a/public/locales/hi/common.json +++ b/public/locales/hi/common.json @@ -41,6 +41,7 @@ "AS_OF_LAST_WEEK": "पिछले सप्ताह तक", "AS_OF_LAST_SIX_MONTH": "पिछले छह महीने से", "NONE": "कोई नहीं", + "LEARNERS":"शिक्षार्थियों", "LEARNER_NAME": "शिक्षार्थी का नाम", "DATE_RANGE": "तिथि सीमा", "SELECT_AN_OPTION": "कोई विकल्प चुनें" @@ -76,7 +77,7 @@ "MY_TEACHING_CENTERS": "मेरे शिक्षण केंद्र", "UPCOMING_EXTRA_SESSION": "आगामी अतिरिक्त सत्र", "BACK_TO_TOP":"वापस शीर्ष पर", - "LEARNER":"शिक्षार्थियों" + "LAST_SEVEN_DAYS_RANGE": "पिछले 7 दिन {{date_range}}" }, "ATTENDANCE": { "TOTAL_STUDENTS": "कुल छात्रों की संख्या: {{count}}", @@ -99,7 +100,10 @@ "DAY_WISE_ATTENDANCE": "दिनविशेष उपस्थिति", "ATTENDANCE_OVERVIEW": "उपस्थिति अवलोकन", "CENTER_ATTENDANCE": "केंद्र उपस्थिति", - "LOW_ATTENDANCE_STUDENTS": "कम उपस्थिति वाले छात्र" + "LOW_ATTENDANCE_STUDENTS": "कम उपस्थिति वाले छात्र", + "N/A": "उपलब्ध नहीं", + "CENTER_NAME": "केंद्र का नाम", + "ALL_CENTERS": "सभी केंद्र" }, "PROFILE": { "EDIT_PROFILE": "प्रोफ़ाइल संपादित करें", diff --git a/public/locales/mr/common.json b/public/locales/mr/common.json index 9abf99eb..1c326041 100644 --- a/public/locales/mr/common.json +++ b/public/locales/mr/common.json @@ -40,6 +40,7 @@ "AS_OF_LAST_WEEK": "गेल्या आठवड्याप्रमाणे", "AS_OF_LAST_SIX_MONTH": "गेल्या सहा महिन्यांपासून", "NONE": "काहीही नाही", + "LEARNERS":"शिकणारे", "LEARNER_NAME": "शिकणाऱ्याचे नाव", "DATE_RANGE": "तारीख श्रेणी", "SELECT_AN_OPTION": "एक पर्याय निवडा" @@ -76,7 +77,7 @@ "MY_TEACHING_CENTERS": "माझे शिक्षण केंद्र", "UPCOMING_EXTRA_SESSION": "आगामी अतिरिक्त सत्रे", "BACK_TO_TOP":"परत वर जा", - "LEARNER":"शिकणारे" + "LAST_SEVEN_DAYS_RANGE": "शेवटचे 7 दिवस {{date_range}}" }, "ATTENDANCE": { "TOTAL_STUDENTS": "एकूण विद्यार्थी: {{count}}", @@ -94,7 +95,10 @@ "DAY_WISE_ATTENDANCE": "दिवस-विशेष उपस्थिती", "ATTENDANCE_OVERVIEW": "उपस्थिती विहंगावलोकन", "CENTER_ATTENDANCE": "केंद्र उपस्थिती", - "LOW_ATTENDANCE_STUDENTS": "कमी उपस्थिती विद्यार्थी" + "LOW_ATTENDANCE_STUDENTS": "कमी उपस्थिती विद्यार्थी", + "N/A": "उपलब्ध नाही", + "CENTER_NAME": "केंद्राचे नाव", + "ALL_CENTERS": "सर्व केंद्रे" }, "PROFILE": { "EDIT_PROFILE": "प्रोफाइल संपादित करा", diff --git a/src/components/DateRangePopup.tsx b/src/components/DateRangePopup.tsx index abee6d37..dee230f3 100644 --- a/src/components/DateRangePopup.tsx +++ b/src/components/DateRangePopup.tsx @@ -24,7 +24,7 @@ const modalStyle = { transform: 'translate(-50%, -50%)', width: 400, bgcolor: 'background.paper', - border: '2px solid #000', + // border: '2px solid #000', boxShadow: 24, p: 4, }; @@ -47,7 +47,7 @@ const DateRangePopup: React.FC = ({ onDateRangeSelected, }) => { const [isModalOpen, setIsModalOpen] = useState(false); - const [selectedIndex, setSelectedIndex] = useState(null); + const [selectedIndex, setSelectedIndex] = useState(1); const handleModalOpen = () => setIsModalOpen(true); const handleModalClose = () => setIsModalOpen(false); diff --git a/src/components/LearnerListHeader.tsx b/src/components/LearnerListHeader.tsx index 5910a56a..0cc87ba7 100644 --- a/src/components/LearnerListHeader.tsx +++ b/src/components/LearnerListHeader.tsx @@ -28,6 +28,7 @@ const LearnerListHeader: React.FC = ({ alignItems="center" textAlign={'center'} justifyContent="space-between" + p={'5px'} > = ({ ) : ( - 'none' + + + + + {t('ATTENDANCE.CENTER_NAME')} + + + + + {firstColumnName} + + + + )} ); diff --git a/src/components/MarkBulkAttendance.tsx b/src/components/MarkBulkAttendance.tsx index 6db294e9..b99f521a 100644 --- a/src/components/MarkBulkAttendance.tsx +++ b/src/components/MarkBulkAttendance.tsx @@ -111,7 +111,7 @@ const MarkBulkAttendance: React.FC = ({ page, filters, }); - const resp = response?.data?.userDetails; + const resp = response?.result?.results?.userDetails; if (resp) { const nameUserIdArray = resp?.map((entry: any) => ({ diff --git a/src/components/OverviewCard.tsx b/src/components/OverviewCard.tsx index 9e78dac3..4340563b 100644 --- a/src/components/OverviewCard.tsx +++ b/src/components/OverviewCard.tsx @@ -7,7 +7,7 @@ import { useTheme } from '@mui/material/styles'; interface OverviewCardProps { label: string; - value: string; + value: string | number; } const OverviewCard: React.FC = ({ label, value }) => { diff --git a/src/components/UpDownButton.tsx b/src/components/UpDownButton.tsx index 188c2bca..6826023a 100644 --- a/src/components/UpDownButton.tsx +++ b/src/components/UpDownButton.tsx @@ -70,7 +70,7 @@ const UpDownButton = () => { sx={{ height: '80px', width: '64px' }} className="flex-column-center" > - {t('DASHBOARD.LEARNER')} + {t('COMMON.LEARNER')} )} diff --git a/src/pages/attendance-history.tsx b/src/pages/attendance-history.tsx index fcf476f3..2ba22d1c 100644 --- a/src/pages/attendance-history.tsx +++ b/src/pages/attendance-history.tsx @@ -323,7 +323,7 @@ const UserAttendanceHistory = () => { }); } }); - if (newArray.length != 0) { + if (newArray.length !== 0) { setCohortMemberList(newArray); setDisplayStudentList(newArray); } else { @@ -595,6 +595,7 @@ const UserAttendanceHistory = () => { onChange={handleCohortSelection} displayEmpty inputProps={{ 'aria-label': 'Without label' }} + disabled={cohortsData?.length === 1 ? true : false} className="SelectLanguages fs-14 fw-500" style={{ borderRadius: '0.5rem', diff --git a/src/pages/attendance-overview.tsx b/src/pages/attendance-overview.tsx index ba51f7d0..c63907f9 100644 --- a/src/pages/attendance-overview.tsx +++ b/src/pages/attendance-overview.tsx @@ -28,8 +28,8 @@ import SearchIcon from '@mui/icons-material/Search'; import SortingModal from '@/components/SortingModal'; import StudentsStatsList from '@/components/LearnerAttendanceStatsListView'; import UpDownButton from '@/components/UpDownButton'; -import { classesMissedAttendancePercentList } from '@/services/AttendanceService'; -import { cohort } from '@/utils/Interfaces'; +import { classesMissedAttendancePercentList, getCohortAttendance,} from '@/services/AttendanceService'; +import { cohort, cohortAttendancePercentParam } from '@/utils/Interfaces'; import { cohortList } from '@/services/CohortServices'; import { getMyCohortMemberList } from '@/services/MyClassDetailsService'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; @@ -59,6 +59,8 @@ const AttendanceOverview: React.FC = () => { const [selectedValue, setSelectedValue] = React.useState( t('COMMON.AS_OF_TODAY') ); + const [presentPercentage, setPresentPercentage] = React.useState(''); + const [lowAttendanceLearnerList,setLowAttendanceLearnerList] = React.useState([]); const theme = useTheme(); const pathname = usePathname(); @@ -166,10 +168,53 @@ const AttendanceOverview: React.FC = () => { ); setLearnerData(mergedArray); setDisplayStudentList(mergedArray); - } + const presentPercentages = mergedArray.map((student) => + parseFloat(student.present_percent) + ); + + // Find the minimum present_percent + const minPresentPercent = Math.min(...presentPercentages); + + // Filter students with the minimum present_percent + const studentsWithLowestAttendance = mergedArray.filter( + (student) => + parseFloat(student.present_percent) === minPresentPercent + ); + + // Extract names of these students + const namesOfLowestAttendance: any[] = + studentsWithLowestAttendance.map((student) => student.name); + setLowAttendanceLearnerList(namesOfLowestAttendance) + } } } } + if (classId) { + const cohortAttendancePercent = async () => { + const cohortAttendanceData: cohortAttendancePercentParam = { + limit: 0, + page: 0, + filters: { + scope: 'student', + fromDate: isFromDate, + toDate: isToDate, + contextId: classId, + }, + facets: ['contextId'], + }; + const res = await getCohortAttendance(cohortAttendanceData); + const response = res?.data?.result; + const contextData = + response.contextId && response.contextId[classId]; + const presentPercentage = contextData ? ( + contextData.present_percentage + ) : ( + {t('ATTENDANCE.N/A')} + ); + setPresentPercentage(presentPercentage); + }; + cohortAttendancePercent(); + } } } catch (error) { console.error('Error fetching cohort list:', error); @@ -300,6 +345,9 @@ const AttendanceOverview: React.FC = () => {
+ {loading && ( + + )} @@ -307,7 +355,7 @@ const AttendanceOverview: React.FC = () => { - + @@ -315,7 +363,7 @@ const AttendanceOverview: React.FC = () => { value={classId} onChange={handleCohortSelection} displayEmpty - disabled = {cohortsData?.length == 1 ? true : false} + disabled={cohortsData?.length == 1 ? true : false} inputProps={{ 'aria-label': 'Without label' }} className="SelectLanguages fs-14 fw-500" style={{ @@ -326,11 +374,16 @@ const AttendanceOverview: React.FC = () => { }} > {cohortsData?.length !== 0 ? ( - cohortsData?.map((cohort) => ( + <> + {cohortsData?.map((cohort) => ( {cohort.name} - )) + ))} + + { t('ATTENDANCE.ALL_CENTERS')} + + ) : ( {t('COMMON.NO_DATA_FOUND')} @@ -349,18 +402,25 @@ const AttendanceOverview: React.FC = () => { /> - + - + {...loading && ( + + )} + value= { learnerData.length ? lowAttendanceLearnerList: {t('ATTENDANCE.N/A')}} + /> */} + @@ -439,11 +499,17 @@ const AttendanceOverview: React.FC = () => { routeName={pathname} /> - + />: + } + {loading && ( )} diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index 55173edd..9da92eb9 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -2,8 +2,8 @@ import { AttendancePercentageProps, - AttendanceStatusListProps, cohort, + cohortAttendancePercentParam, } from '../utils/Interfaces'; import { Box, @@ -21,39 +21,31 @@ import React, { useEffect } from 'react'; import Snackbar, { SnackbarOrigin } from '@mui/material/Snackbar'; import { attendanceInPercentageStatusList, - attendanceStatusList, - bulkAttendance, + getCohortAttendance, } from '../services/AttendanceService'; import { - formatDate, formatSelectedDate, getMonthName, getTodayDate, shortDateFormat, - toPascalCase, } from '../utils/Helper'; import { isAfter, startOfDay } from 'date-fns'; import ArrowForwardSharpIcon from '@mui/icons-material/ArrowForwardSharp'; -import AttendanceStatusListView from '../components/AttendanceStatusListView'; -import Backdrop from '@mui/material/Backdrop'; import CalendarMonthIcon from '@mui/icons-material/CalendarMonth'; -import CloseIcon from '@mui/icons-material/Close'; import Divider from '@mui/material/Divider'; -import Fade from '@mui/material/Fade'; import Header from '../components/Header'; import Link from 'next/link'; import Loader from '../components/Loader'; -import Modal from '@mui/material/Modal'; import OverviewCard from '@/components/OverviewCard'; import WeekCalender from '@/components/WeekCalender'; import { cohortList } from '../services/CohortServices'; -import { getMyCohortMemberList } from '../services/MyClassDetailsService'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import useDeterminePathColor from '../hooks/useDeterminePathColor'; import { useRouter } from 'next/navigation'; import { useTheme } from '@mui/material/styles'; import { useTranslation } from 'next-i18next'; +import MarkBulkAttendance from '@/components/MarkBulkAttendance'; interface State extends SnackbarOrigin { openModal: boolean; @@ -67,23 +59,26 @@ const Dashboard: React.FC = () => { const [open, setOpen] = React.useState(false); const [cohortsData, setCohortsData] = React.useState>([]); const [classId, setClassId] = React.useState(''); - const [cohortMemberList, setCohortMemberList] = React.useState>([]); - const [presentCount, setPresentCount] = React.useState(0); - const [absentCount, setAbsentCount] = React.useState(0); const [showDetails, setShowDetails] = React.useState(false); const [handleSaveHasRun, setHandleSaveHasRun] = React.useState(false); - const [selectedDate, setSelectedDate] = React.useState(''); + const [selectedDate, setSelectedDate] = React.useState(getTodayDate()); const [percentageAttendanceData, setPercentageAttendanceData] = React.useState(null); - const [numberOfCohortMembers, setNumberOfCohortMembers] = React.useState(0); const [percentageAttendance, setPercentageAttendance] = React.useState(null); - const [bulkAttendanceStatus, setBulkAttendanceStatus] = React.useState(''); const [loading, setLoading] = React.useState(false); - const [isAllAttendanceMarked, setIsAllAttendanceMarked] = - React.useState(false); - const [showUpdateButton, setShowUpdateButton] = React.useState(false); const [isAuthenticated, setIsAuthenticated] = React.useState(false); + const [cohortPresentPercentage, setCohortPresentPercentage] = + React.useState(''); + const [lowAttendanceLearnerList, setLowAttendanceLearnerList] = + React.useState([]); + const [fromDateFormatted, setFromDateFormatted] = React.useState< + Date | string + >(''); + const [toDateFormatted, setToDateFormatted] = React.useState( + '' + ); + const [dateRange, setDateRange] = React.useState(''); const [state, setState] = React.useState({ openModal: false, vertical: 'top', @@ -93,22 +88,28 @@ const Dashboard: React.FC = () => { const { vertical, horizontal, openModal } = state; const { t } = useTranslation(); const router = useRouter(); - const currentDate = getTodayDate(); const contextId = classId; const theme = useTheme(); const determinePathColor = useDeterminePathColor(); - const modalContainer = { - position: 'absolute', - top: '50%', - left: '50%', - transform: 'translate(-50%, -50%)', - width: 300, - bgcolor: theme.palette.warning['A400'], - border: '2px solid #000', - boxShadow: 24, - p: 4, - Height: '585px', - }; + + useEffect(() => { + let date = new Date(); + const dayOfWeek = date.getDay(); + const diffToMonday = + date.getDate() - dayOfWeek + (dayOfWeek === 0 ? -6 : 1); + let startDate = new Date(date); + startDate.setDate(diffToMonday); + startDate.setHours(0, 0, 0, 0); + const endDate = new Date(startDate); + endDate.setDate(startDate.getDate() + 6); + endDate.setHours(23, 59, 59, 999); + const startDay = startDate.getDate(); + const endDay = endDate.getDate(); + const month = endDate.toLocaleString('default', { month: 'long' }); + setDateRange(`(${startDay}-${endDay} ${month}`); + setFromDateFormatted(shortDateFormat(startDate)); + setToDateFormatted(shortDateFormat(endDate)); + }, []); useEffect(() => { if (typeof window !== 'undefined' && window.localStorage) { @@ -133,7 +134,7 @@ const Dashboard: React.FC = () => { const filters = { userId: userId }; const resp = await cohortList({ limit, page, filters }); - const extractedNames = resp?.data?.cohortDetails; + const extractedNames = resp?.results?.cohortDetails; localStorage.setItem( 'parentCohortId', extractedNames?.[0].cohortData.parentId @@ -148,7 +149,6 @@ const Dashboard: React.FC = () => { ?.filter(Boolean); setCohortsData(filteredData); setClassId(filteredData?.[0]?.cohortId); - // setShowUpdateButton(true); setLoading(false); } } catch (error) { @@ -161,131 +161,32 @@ const Dashboard: React.FC = () => { //API for getting student list useEffect(() => { - submitBulkAttendanceAction(true, '', ''); - const getCohortMemberList = async () => { - setLoading(true); - try { - if (classId) { - const limit = 300; - const page = 0; - const filters = { cohortId: classId }; - const response = await getMyCohortMemberList({ - limit, - page, - filters, - }); - const resp = response?.data?.userDetails; - - if (resp) { - const nameUserIdArray = resp?.map((entry: any) => ({ - userId: entry.userId, - name: toPascalCase(entry.name), - })); - console.log('name..........', nameUserIdArray); - if (nameUserIdArray && (selectedDate || currentDate)) { - const userAttendanceStatusList = async () => { - const attendanceStatusData: AttendanceStatusListProps = { - limit: 300, + const cohortAttendancePercent = async () => { + setLoading(true); + try { + const cohortAttendanceData: cohortAttendancePercentParam = { + limit: 0, page: 0, filters: { - fromDate: selectedDate || currentDate, - toDate: selectedDate || currentDate, + scope: 'student', + fromDate: fromDateFormatted, + toDate: toDateFormatted, contextId: classId, }, + facets: ['contextId'], }; - const res = await attendanceStatusList(attendanceStatusData); - const response = res?.data?.attendanceList; - console.log('attendanceStatusList', response); - if (nameUserIdArray && response) { - const getUserAttendanceStatus = ( - nameUserIdArray: any[], - response: any[] - ) => { - const userAttendanceArray: { - userId: any; - attendance: any; - }[] = []; - - nameUserIdArray.forEach((user) => { - const userId = user.userId; - const attendance = response.find( - (status) => status.userId === userId - ); - userAttendanceArray.push({ - userId, - attendance: attendance?.attendance - ? attendance.attendance - : '', - }); - }); - return userAttendanceArray; - }; - const userAttendanceArray = getUserAttendanceStatus( - nameUserIdArray, - response - ); - console.log('userAttendanceArray', userAttendanceArray); - - if (nameUserIdArray && userAttendanceArray) { - const mergeArrays = ( - nameUserIdArray: { userId: string; name: string }[], - userAttendanceArray: { - userId: string; - attendance: string; - }[] - ): { - userId: string; - name: string; - attendance: string; - }[] => { - const newArray: { - userId: string; - name: string; - attendance: string; - }[] = []; - nameUserIdArray.forEach((user) => { - const userId = user.userId; - const attendanceEntry = userAttendanceArray.find( - (entry) => entry.userId === userId - ); - if (attendanceEntry) { - newArray.push({ - userId, - name: user.name, - attendance: attendanceEntry.attendance, - }); - } - }); - if (newArray.length != 0) { - // newArray = newArray.filter(item => item.name); - setCohortMemberList(newArray); - setPresentCount( - newArray.filter( - (user) => user.attendance === 'present' - ).length - ); - setAbsentCount( - newArray.filter( - (user) => user.attendance === 'absent' - ).length - ); - setNumberOfCohortMembers(newArray?.length); - } else { - setCohortMemberList(nameUserIdArray); - setNumberOfCohortMembers(nameUserIdArray?.length); - } - return newArray; - }; - mergeArrays(nameUserIdArray, userAttendanceArray); - } - } - setLoading(false); - }; - userAttendanceStatusList(); + const res = await getCohortAttendance(cohortAttendanceData); + const response = res?.data?.result; + const contextData = + response?.contextId && response?.contextId[classId]; + const presentPercentage = contextData && contextData != undefined ? ( + contextData?.present_percentage + ) : ( + {t('ATTENDANCE.N/A')} + ); + setCohortPresentPercentage(presentPercentage); } - } - } - } catch (error) { + catch (error) { console.error('Error fetching cohort list:', error); setLoading(false); } finally { @@ -294,7 +195,7 @@ const Dashboard: React.FC = () => { }; if (classId?.length) { - getCohortMemberList(); + cohortAttendancePercent() } }, [classId, selectedDate]); @@ -314,17 +215,6 @@ const Dashboard: React.FC = () => { const getAttendaceData = async () => { try { if (contextId !== '') { - const currentDate = new Date(); - const dayOfWeek = currentDate.getDay(); - const diffToMonday = - currentDate.getDate() - dayOfWeek + (dayOfWeek === 0 ? -6 : 1); - const startDate = new Date(currentDate.setDate(diffToMonday)); - startDate.setHours(0, 0, 0, 0); - const endDate = new Date(startDate); - endDate.setDate(startDate.getDate() + 6); - endDate.setHours(23, 59, 59, 999); - const fromDateFormatted = shortDateFormat(startDate); - const toDateFormatted = shortDateFormat(endDate); const attendanceRequest: AttendancePercentageProps = { limit: 300, page: 0, @@ -377,84 +267,14 @@ const Dashboard: React.FC = () => { getAttendaceData(); }, [classId, handleSaveHasRun]); - const submitBulkAttendanceAction = ( - isBulkAction: boolean, - status: string, - id?: string | undefined - ) => { - const updatedAttendanceList = cohortMemberList?.map((user: any) => { - if (isBulkAction) { - user.attendance = status; - setBulkAttendanceStatus(status); - } else { - setBulkAttendanceStatus(''); - if (user.userId === id) { - user.attendance = status; - } - } - return user; - }); - setCohortMemberList(updatedAttendanceList); - const hasEmptyAttendance = () => { - const allAttendance = updatedAttendanceList.some( - (user) => user.attendance === '' - ); - setIsAllAttendanceMarked(!allAttendance); - if (allAttendance) { - setShowUpdateButton(true); - } - }; - hasEmptyAttendance(); - }; - const viewAttendanceHistory = () => { router.push('/attendance-history'); }; - const handleSave = () => { - handleModalToggle(); - const userAttendance = cohortMemberList?.map((user: any) => { - return { - userId: user.userId, - attendance: user.attendance, - }; - }); - if (userAttendance) { - const data = { - attendanceDate: selectedDate || currentDate, - contextId, - userAttendance, - }; - const markBulkAttendance = async () => { - setLoading(true); - try { - await bulkAttendance(data); - // console.log(`response bulkAttendance`, response?.responses); - // const resp = response?.data; - // console.log(`data`, data); - setShowUpdateButton(true); - handleModalToggle(); - setLoading(false); - setHandleSaveHasRun(true); - } catch (error) { - console.error('Error fetching cohort list:', error); - setLoading(false); - } - handleClick({ vertical: 'bottom', horizontal: 'center' })(); - }; - markBulkAttendance(); - } - }; - - const handleClick = (newState: SnackbarOrigin) => () => { - setState({ ...newState, openModal: true }); - }; const handleClose = () => { - setState({ ...state, openModal: false }); + setOpen(false); }; - // Get today's date in the format 'YYYY-MM-DD' - // const todayDate = new Date().toISOString().split('T')[0]; const todayDate = getTodayDate(); // Initialize currentAttendance based on today's date @@ -687,192 +507,13 @@ const Dashboard: React.FC = () => { - {/* Student Attendance Modal */} - - - - - - - - {t('COMMON.MARK_CENTER_ATTENDANCE')} - - - {formatDate(selectedDate || currentDate)} - - - handleModalToggle()}> - - - - - {loading && ( - - )} - - - {t('ATTENDANCE.TOTAL_STUDENTS', { - count: numberOfCohortMembers, - })} - - - - {t('ATTENDANCE.PRESENT_STUDENTS', { - count: presentCount, - })} - - - {t('ATTENDANCE.ABSENT_STUDENTS', { - count: absentCount, - })} - - - {cohortMemberList && cohortMemberList?.length != 0 ? ( - - - - {cohortMemberList?.map( - ( - user: any //cohort member list should have userId, attendance, name - ) => ( - - ) - )} - - - - - - - ) : ( - - {t('COMMON.NO_DATA_FOUND')} - - )} - - - - + onClose={handleClose} + classId={classId} + selectedDate={new Date(selectedDate)} + onSaveSuccess={() => setHandleSaveHasRun(!handleSaveHasRun)} + /> = () => { padding={'2px'} > - + {t('DASHBOARD.OVERVIEW')} + + {t('DASHBOARD.LAST_SEVEN_DAYS_RANGE', { + date_range: dateRange, + })} + = () => { - + diff --git a/src/services/AttendanceService.ts b/src/services/AttendanceService.ts index 75864335..0d841ba3 100644 --- a/src/services/AttendanceService.ts +++ b/src/services/AttendanceService.ts @@ -3,6 +3,7 @@ import { BulkAttendanceParams, AttendanceStatusListProps, AttendancePercentageProps, + cohortAttendancePercentParam, } from '../utils/Interfaces'; export const bulkAttendance = async ({ @@ -65,6 +66,20 @@ export const attendanceInPercentageStatusList = async ({ }); }; +export const getCohortAttendance = async ({ + limit, + page, + filters: {scope, fromDate, toDate, contextId}, + facets, +}: cohortAttendancePercentParam): Promise => { + return postAttendanceList({ + limit, + page, + filters: {scope, fromDate, toDate, contextId}, + facets, + }); +}; + export const classesMissedAttendancePercentList = async ({ filters, facets, diff --git a/src/services/CohortServices.ts b/src/services/CohortServices.ts index 3851b9c2..477d7a8e 100644 --- a/src/services/CohortServices.ts +++ b/src/services/CohortServices.ts @@ -9,7 +9,7 @@ export const cohortList = async ({ const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/search`; try { const response = await post(apiUrl, { limit, page, filters }); - return response?.data; + return response?.data?.result; } catch (error) { console.error('error in getting cohort list', error); throw error; diff --git a/src/utils/Interfaces.ts b/src/utils/Interfaces.ts index 5289361f..309744fe 100644 --- a/src/utils/Interfaces.ts +++ b/src/utils/Interfaces.ts @@ -113,8 +113,8 @@ export interface AttendancePercentageProps { filters: { contextId: string; scope: string; - toDate: string; - fromDate: string; + toDate: string | Date; + fromDate: string | Date; }; facets: Array; } @@ -135,7 +135,7 @@ export interface cohort { export interface LearListHeaderProps { numberOfColumns: number; firstColumnName: string; - secondColumnName: string; + secondColumnName?: string; } export interface MarksObtainedCardProps { @@ -147,11 +147,26 @@ export interface assesmentListServiceParam { userId: string; }; pagination: { - pageSize: Number; - page: Number; + pageSize: number; + page: number; }; sort: { field: string; order: String; }; } + + +export interface cohortAttendancePercentParam { + limit: number; + page: number; + filters: { + scope: string; + fromDate: Date | string; + toDate: Date | string; + contextId: string + }; + facets: Array; +} + +