Skip to content

Commit

Permalink
Issue #PS-000 feat: Fixed lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvick committed Aug 12, 2024
1 parent 819f504 commit f149f38
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 313 deletions.
2 changes: 1 addition & 1 deletion src/components/AttendanceComparison.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const AttendanceComparison: React.FC<AttendanceComparisonProps> = ({
const dataMap: Record<string, string> = {};

results.forEach((result) => {
if (result.statusCode === 200 && result?.data?.result?.contextId) {
if (result?.statusCode === 200 && result?.data?.result?.contextId) {
Object.keys(result?.data?.result?.contextId).forEach((id) => {
dataMap[id] =
result?.data?.result?.contextId[id]?.present_percentage || '0';
Expand Down
312 changes: 2 additions & 310 deletions src/components/CohortSelectionSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ const CohortSelectionSection: React.FC<CohortSelectionSectionProps> = ({
{loading && <Loader showBackdrop={true} loadingText={t('LOADING')} />}
{!loading && cohortsData && (
<Box>
{loading && <Loader showBackdrop={true} loadingText={t('LOADING')} />}
{/* {loading && <Loader showBackdrop={true} loadingText={t('LOADING')} />} */}
{!loading && cohortsData && (
<Box>
{blockName ? (
Expand All @@ -304,7 +304,7 @@ const CohortSelectionSection: React.FC<CohortSelectionSectionProps> = ({
color={theme.palette.warning['300']}
textAlign={'left'}
>
{blockName}
{blockName} {t('DASHBOARD.BLOCK')}
</Typography>
<Box className="mt-md-16">
<Box sx={{ minWidth: 120, gap: '15px' }} display={'flex'}>
Expand Down Expand Up @@ -442,311 +442,3 @@ const CohortSelectionSection: React.FC<CohortSelectionSectionProps> = ({
};

export default CohortSelectionSection;

// import {
// Box,
// FormControl,
// MenuItem,
// Select,
// SelectChangeEvent,
// Typography,
// } from '@mui/material';
// import { usePathname, useRouter } from 'next/navigation';
// import React, { useEffect } from 'react';

// import { getCohortList } from '@/services/CohortServices';
// import useStore from '@/store/store';
// import { ICohort } from '@/utils/Interfaces';
// import { CustomField } from '@/utils/Interfaces';
// import { cohortHierarchy } from '@/utils/app.constant';
// import { useTheme } from '@mui/material/styles';
// import { useTranslation } from 'next-i18next';
// import ReactGA from 'react-ga4';
// import Loader from './Loader';
// import { showToastMessage } from './Toastify';
// import manageUserStore from '@/store/manageUserStore';

// interface CohortSelectionSectionProps {
// classId: string;
// setClassId: React.Dispatch<React.SetStateAction<string>>;
// userId: string | null;
// setUserId: React.Dispatch<React.SetStateAction<string | null>>;
// isAuthenticated?: boolean;
// setIsAuthenticated?: React.Dispatch<React.SetStateAction<boolean>>;
// loading: boolean;
// setLoading: React.Dispatch<React.SetStateAction<boolean>>;
// cohortsData: Array<ICohort>;
// setCohortsData: React.Dispatch<React.SetStateAction<Array<ICohort>>>;
// manipulatedCohortData?: Array<ICohort>;
// setManipulatedCohortData?: React.Dispatch<
// React.SetStateAction<Array<ICohort>>
// >;
// blockName: string;
// isManipulationRequired?: boolean;
// setBlockName: React.Dispatch<React.SetStateAction<string>>;
// handleSaveHasRun?: boolean;
// setHandleSaveHasRun?: React.Dispatch<React.SetStateAction<boolean>>;
// isCustomFieldRequired?: boolean;
// }

// interface ChildData {
// cohortId: string;
// name: string;
// parentId: string;
// type: string;
// customField: any[];
// childData: ChildData[];
// }
// interface NameTypePair {
// cohortId: string;
// name: string;
// cohortType: string;
// }

// const CohortSelectionSection: React.FC<CohortSelectionSectionProps> = ({
// classId,
// setClassId,
// userId,
// setUserId,
// isAuthenticated,
// setIsAuthenticated,
// loading,
// setLoading,
// cohortsData,
// setCohortsData,
// manipulatedCohortData,
// setManipulatedCohortData,
// isManipulationRequired = true,
// blockName,
// setBlockName,
// handleSaveHasRun,
// setHandleSaveHasRun,
// isCustomFieldRequired = true,
// }) => {
// const router = useRouter();
// const theme = useTheme<any>();
// const pathname = usePathname(); // Get the current pathname
// const { t } = useTranslation();
// const setCohorts = useStore((state) => state.setCohorts);

// const store = manageUserStore();
// const setDistrictCode = manageUserStore(
// (state: { setDistrictCode: any }) => state.setDistrictCode
// );
// const setDistrictId = manageUserStore(
// (state: { setDistrictId: any }) => state.setDistrictId
// );
// const setStateCode = manageUserStore(
// (state: { setStateCode: any }) => state.setStateCode
// );
// const setStateId = manageUserStore(
// (state: { setStateId: any }) => state.setStateId
// );
// const setBlockCode = manageUserStore(
// (state: { setBlockCode: any }) => state.setBlockCode
// );
// const setBlockId = manageUserStore(
// (state: { setBlockId: any }) => state.setBlockId
// );

// useEffect(() => {
// if (typeof window !== 'undefined' && window.localStorage) {
// const token = localStorage.getItem('token');
// const storedUserId = localStorage.getItem('userId');
// setClassId(localStorage.getItem('classId') || '');
// if (token) {
// setIsAuthenticated?.(true);
// } else {
// router.push('/login');
// }
// setUserId(storedUserId);
// }
// }, [router, setClassId, setIsAuthenticated, setUserId]);

// useEffect(() => {
// if (userId) {
// setLoading(true);
// const fetchCohorts = async () => {
// try {
// const response = await getCohortList(userId, {
// customField: 'true',
// });
// console.log('Response:', response);
// const cohortData = response[0];
// if (cohortData?.customField?.length) {
// const district = cohortData.customField.find(
// (item: CustomField) => item.label === 'DISTRICTS'
// );
// setDistrictCode(district?.code);
// setDistrictId(district?.fieldId);

// const state = cohortData.customField.find(
// (item: CustomField) => item.label === 'STATES'
// );
// setStateCode(state?.code);
// setStateId(state?.fieldId);

// const blockField = cohortData?.customField.find(
// (field: any) => field.label === 'BLOCKS'
// );
// setBlockCode(blockField?.code);
// setBlockId(blockField.fieldId);
// }

// if (response && response?.length > 0) {
// const extractNamesAndCohortTypes = (
// data: ChildData[]
// ): NameTypePair[] => {
// const nameTypePairs: NameTypePair[] = [];
// const recursiveExtract = (items: ChildData[]) => {
// items.forEach((item) => {
// const cohortType =
// item?.customField?.find(
// (field) => field.label === 'TYPE_OF_COHORT'
// )?.value || 'Unknown';
// if (item?.cohortId && item?.name) {
// nameTypePairs.push({
// cohortId: item?.cohortId,
// name: item?.name,
// cohortType,
// });
// }
// if (item?.childData && item?.childData?.length > 0) {
// recursiveExtract(item?.childData);
// }
// });
// };
// recursiveExtract(data);
// return nameTypePairs;
// };

// if (response?.length > 0) {
// const nameTypePairs = extractNamesAndCohortTypes(response);
// setCohorts(nameTypePairs);
// }
// }
// if (response && response.length > 0) {
// if (response[0].type === cohortHierarchy.COHORT) {
// const filteredData = response
// ?.map((item: any) => ({
// cohortId: item?.cohortId,
// parentId: item?.parentId,
// name: item?.cohortName || item?.name,
// }))
// ?.filter(Boolean);
// setCohortsData(filteredData);
// handleLocalStorage(filteredData);
// setManipulatedCohortDataFunc(filteredData);
// } else if (response[0].type === cohortHierarchy.BLOCK) {
// setBlockName(response[0].name || response[0].cohortName);
// const filteredData = response[0].childData
// ?.map((item: any) => ({
// cohortId: item?.cohortId,
// parentId: item?.parentId,
// name: item?.cohortName || item?.name,
// }))
// ?.filter(Boolean);
// setCohortsData(filteredData);
// handleLocalStorage(filteredData);
// setManipulatedCohortData?.(filteredData);
// }
// }
// setLoading(false);
// } catch (error) {
// console.error('Error fetching cohort list', error);
// setLoading(false);
// showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
// }
// };

// fetchCohorts();
// }
// }, [
// userId,
// setCohortsData,
// setLoading,
// setClassId,
// setManipulatedCohortData,
// setBlockName,
// isCustomFieldRequired,
// ]);

// const handleLocalStorage = (filteredData: any[]) => {
// if (filteredData.length > 0) {
// if (typeof window !== 'undefined' && window.localStorage) {
// const cohort = localStorage.getItem('classId') || '';
// if (cohort !== '') {
// setClassId(localStorage.getItem('classId') || '');
// } else {
// localStorage.setItem('classId', filteredData?.[0]?.cohortId);
// setClassId(filteredData?.[0]?.cohortId);
// }
// }
// }
// };

// const setManipulatedCohortDataFunc = (filteredData: any[]) => {
// if (isManipulationRequired) {
// setManipulatedCohortData?.(
// filteredData.concat({
// cohortId: 'all',
// name: 'All Centers',
// })
// );
// } else {
// setManipulatedCohortData?.(filteredData);
// }
// };

// const handleCohortSelection = (event: SelectChangeEvent<string>) => {
// setClassId(event.target.value as string);
// ReactGA.event('cohort-selection-dashboard', {
// selectedCohortID: event.target.value,
// });
// localStorage.setItem('classId', event.target.value);
// setHandleSaveHasRun?.(false);
// };
// const isAttendanceOverview = pathname === '/attendance-overview';
// return (
// <>
// <Typography
// sx={{
// fontSize: theme.typography.h6,
// color:theme.palette.warning['300']
// fontWeight: 'bold',
// marginBottom: theme.spacing(1),
// }}
// className={isAttendanceOverview ? 'w-100' : 'w-md-40'}
// >
// {blockName}
// </Typography>
// <Box sx={{ width: '50%', marginBottom: theme.spacing(2) }}>
// <FormControl fullWidth>
// {loading ? (
// <Loader showBackdrop={false} loadingText={''} />
// ) : (
// <>
// {cohortsData.length > 0 && (
// <Select
// value={classId}
// onChange={handleCohortSelection}
// displayEmpty
// inputProps={{ 'aria-label': 'Select cohort' }}
// >
// {manipulatedCohortData?.length &&
// manipulatedCohortData?.map((cohort) => (
// <MenuItem key={cohort?.cohortId} value={cohort?.cohortId}>
// {cohort?.name}
// </MenuItem>
// ))}
// </Select>
// )}
// </>
// )}
// </FormControl>
// </Box>
// </>
// );
// };

// export default CohortSelectionSection;
4 changes: 2 additions & 2 deletions src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
import {
AttendancePercentageProps,
CohortAttendancePercentParam,
ICohort,
CohortMemberList,
ICohort,
} from '../utils/Interfaces';
import { accessControl, lowLearnerAttendanceLimit } from './../../app.config';

Expand All @@ -31,6 +31,7 @@ import OverviewCard from '@/components/OverviewCard';
import { showToastMessage } from '@/components/Toastify';
import WeekCalender from '@/components/WeekCalender';
import { getMyCohortMemberList } from '@/services/MyClassDetailsService';
import { Role } from '@/utils/app.constant';
import { calculatePercentage } from '@/utils/attendanceStats';
import { logEvent } from '@/utils/googleAnalytics';
import withAccessControl from '@/utils/hoc/withAccessControl';
Expand All @@ -48,7 +49,6 @@ import calendar from '../assets/images/calendar.svg';
import Header from '../components/Header';
import Loader from '../components/Loader';
import useDeterminePathColor from '../hooks/useDeterminePathColor';
import { Role } from '@/utils/app.constant';

interface DashboardProps { }

Expand Down

0 comments on commit f149f38

Please sign in to comment.