Skip to content

Commit

Permalink
Merge pull request #202 from suvarnakale/shiksha-2.0
Browse files Browse the repository at this point in the history
Issue #PS-294 chore: Build issues fixed
  • Loading branch information
itsvick authored Jun 1, 2024
2 parents 92aa7d9 + b4d6b70 commit b57f8f1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 24 deletions.
25 changes: 17 additions & 8 deletions src/components/AttendanceStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
CreateOutlined,
} from '@mui/icons-material';
import useDeterminePathColor from '../hooks/useDeterminePathColor';
import { useTheme } from '@mui/material/styles';
import { useTranslation } from 'next-i18next';

interface AttendanceStatusProps {
Expand All @@ -24,14 +23,17 @@ type AttendanceData = {
present_percentage: number;
present_students: number;
total_students: number;
attendanceStatus: string;
};

type FormattedAttendanceData = {
[date: string]: AttendanceData;
};

type learnerAttendanceData = {
[date: string]: AttendanceData;
[date: string]: {
attendanceStatus: string;
};
};

function AttendanceStatus({
Expand All @@ -42,7 +44,6 @@ function AttendanceStatus({
onUpdate,
}: AttendanceStatusProps) {
const { t } = useTranslation();
const theme = useTheme<any>();
const determinePathColor = useDeterminePathColor();
const selectedDate = shortDateFormat(onDateSelection);
const dateString = shortDateFormat(onDateSelection);
Expand Down Expand Up @@ -92,7 +93,10 @@ function AttendanceStatus({
break;
}

const presentPercentage = currentAttendance?.present_percentage;
const presentPercentage =
typeof currentAttendance !== 'string'
? currentAttendance.present_percentage
: 0;
const pathColor = determinePathColor(presentPercentage);

return (
Expand Down Expand Up @@ -144,8 +148,7 @@ function AttendanceStatus({
color={pathColor}
>
{t('DASHBOARD.PERCENT_ATTENDANCE', {
percent_students:
currentAttendance?.present_percentage,
percent_students: presentPercentage,
})}
</Typography>
&nbsp;
Expand All @@ -155,8 +158,14 @@ function AttendanceStatus({
color={pathColor}
>
{t('DASHBOARD.PRESENT_STUDENTS', {
present_students: currentAttendance?.present_students,
total_students: currentAttendance?.totalcount,
present_students:
typeof currentAttendance !== 'string'
? currentAttendance.present_students
: 0,
total_students:
typeof currentAttendance !== 'string'
? currentAttendance.totalcount
: 0,
})}
</Typography>
</Box>
Expand Down
8 changes: 4 additions & 4 deletions src/components/MarkBulkAttendance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ const MarkBulkAttendance: React.FC<MarkBulkAttendanceProps> = ({
userAttendanceArray.push({
userId,
attendance: attendance?.attendance
? attendance.attendance
: '',
});
});
? attendance.attendance
: '',
});
});
return userAttendanceArray;
};
const userAttendanceArray = getUserAttendanceStatus(
Expand Down
5 changes: 3 additions & 2 deletions src/components/MonthCalender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ interface CalendarWithAttendanceProps {
}

type AttendanceData = {
present_percentage: number;
present_percentage?: number;
attendanceStatus?: string;
};

type FormattedAttendanceData = {
Expand Down Expand Up @@ -59,7 +60,7 @@ const MonthCalender: React.FC<CalendarWithAttendanceProps> = ({
console.log('formattedAttendanceData', formattedAttendanceData);
const attendanceData = formattedAttendanceData?.[dateString];
if (!attendanceData) return null;
const presentPercentage = attendanceData?.present_percentage;
const presentPercentage = attendanceData?.present_percentage || 0;

const pathColor = determinePathColor(presentPercentage);

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useDeterminePathColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const useDeterminePathColor = () => {
const theme = useTheme();

const determinePathColor = (presentPercentage) => {
if (isNaN(presentPercentage)) return;
if (presentPercentage == 0) return theme.palette.warning['400'];
if (presentPercentage < 25) return theme.palette.error.main;
if (presentPercentage < 50) return theme.palette.action.activeChannel;
return theme.palette.success.main;
Expand Down
33 changes: 25 additions & 8 deletions src/pages/learner-attendance-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ import { LearnerAttendanceProps } from '@/utils/Interfaces';
import { getLearnerAttendanceStatus } from '@/services/AttendanceService';
import MarkAttendance from '@/components/MarkAttendance';

type LearnerAttendanceData = {
[date: string]: {
attendanceStatus: string;
};
};

type AttendanceRecord = {
attendanceDate: string;
attendance: string;
};

const LearnerAttendanceHistory = () => {
const { t } = useTranslation();
const theme = useTheme<any>();
Expand All @@ -22,7 +33,9 @@ const LearnerAttendanceHistory = () => {
const [open, setOpen] = useState(false);
const [modalOpen, setModalOpen] = useState(false);
const [attendanceUpdated, setAttendanceUpdated] = useState(false);
const [learnerAttendance, setLearnerAttendance] = React.useState<any>(null);
const [learnerAttendance, setLearnerAttendance] = useState<
LearnerAttendanceData | undefined
>(undefined);

useEffect(() => {
handleSelectedDateChange(selectedDate);
Expand Down Expand Up @@ -83,12 +96,15 @@ const LearnerAttendanceHistory = () => {
};
const response = await getLearnerAttendanceStatus(attendanceRequest);
const attendanceStats = response?.data?.attendanceList;
const attendanceData = attendanceStats?.reduce((acc, record) => {
acc[record.attendanceDate] = {
attendanceStatus: record.attendance,
};
return acc;
}, {});
const attendanceData = attendanceStats?.reduce(
(acc: LearnerAttendanceData, record: AttendanceRecord) => {
acc[record.attendanceDate] = {
attendanceStatus: record.attendance,
};
return acc;
},
{}
);
setLearnerAttendance(attendanceData);
setLoading(false);
}
Expand Down Expand Up @@ -182,7 +198,8 @@ const LearnerAttendanceHistory = () => {
date={shortDateFormat(selectedDate)}
isSelfAttendance={false}
currentStatus={
learnerAttendance?.[shortDateFormat(selectedDate)]?.attendanceStatus
learnerAttendance?.[shortDateFormat(selectedDate)]
?.attendanceStatus || ''
}
handleClose={handleModalClose}
onAttendanceUpdate={() => setAttendanceUpdated(!attendanceUpdated)}
Expand Down
1 change: 0 additions & 1 deletion src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface MarkAttendanceProps {
currentStatus: string;
handleClose: () => void;
onAttendanceUpdate: () => void;
handleSubmit: (attendanceDate: string, attendance: string) => void;
}

export interface AttendanceStatusListViewProps {
Expand Down

0 comments on commit b57f8f1

Please sign in to comment.