Skip to content

Commit

Permalink
Merge branch 'shiksha-2.0' of https://github.com/tekdi/shiksha-frontend
Browse files Browse the repository at this point in the history
… into cachingLatest
  • Loading branch information
Aar-if committed Jun 27, 2024
2 parents 398a495 + a5e7cfd commit 8eb36f5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
20 changes: 19 additions & 1 deletion src/components/DateRangePopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Typography,
useStepContext,
} from '@mui/material';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { getDayAndMonthName, getTodayDate } from '@/utils/Helper';

import CloseIcon from '@mui/icons-material/Close';
Expand Down Expand Up @@ -78,6 +78,8 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
}) => {
const [isModalOpen, setIsModalOpen] = useState(false);
const [isCalendarModalOpen, setIsCalenderModalOpen] = useState(false);
const [selectedRangeArray, setSelectedRangeArray] = useState(null);

const [dateRangeArray, setDateRangeArray] = useState<any[]>([]);
const [selectedIndex, setSelectedIndex] = useState<number | null>(0);
const [displayCalendarFromDate, setDisplayCalendarFromDate] = React.useState(
Expand Down Expand Up @@ -113,6 +115,7 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
setCancelClicked(true);
setDisplayCalendarFromDate(getDayAndMonthName(getTodayDate()));
setDisplayCalendarToDate(getDayAndMonthName(getTodayDate()));
localStorage.removeItem('selectedRangeArray');
};

const onApply = () => {
Expand All @@ -135,6 +138,20 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
}
};

useEffect(() => {
if (typeof window !== 'undefined' && window.localStorage) {
const storedDates = localStorage.getItem('selectedRangeArray');
if (storedDates) {
try {
const dateArray = JSON.parse(storedDates);
setSelectedRangeArray(dateArray);
} catch (error) {
console.error('Failed to parse stored dates:', error);
}
}
}
}, []);

const getDateRange = (index: number | null) => {
const today = new Date();
const formatDate = (date: Date) => {
Expand Down Expand Up @@ -378,6 +395,7 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
onChange={handleActiveStartDateChange}
onDateChange={handleCalendarDateChange}
selectionType="range"
selectedRangeRetention={selectedRangeArray}
/>
</Box>
<Box
Expand Down
22 changes: 22 additions & 0 deletions src/components/MonthCalender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface CalendarWithAttendanceProps {
onChange: (date: Date) => void;
onDateChange: (date: Date | Date[] | null) => void;
selectionType?: 'single' | 'range';
selectedRangeRetention?:Date | null | undefined | [Date | null, Date | null];
}

type AttendanceData = {
Expand All @@ -39,6 +40,7 @@ const MonthCalender: React.FC<CalendarWithAttendanceProps> = ({
onChange,
onDateChange,
selectionType,
selectedRangeRetention
}) => {
const [date, setDate] = useState<
Date | null | undefined | [Date | null, Date | null]
Expand Down Expand Up @@ -200,6 +202,21 @@ const MonthCalender: React.FC<CalendarWithAttendanceProps> = ({
}
}

useEffect(() => {
if (typeof window !== 'undefined' && window.localStorage) {
const retentionDate = localStorage.getItem('selectedRangeArray');
if (retentionDate) {
try {
let retention = JSON.parse(retentionDate);
if (retention) {
handleDateChange(retention);
}
} catch (error) {
console.error('Failed to parse date range:', error);
}
}
}
}, []);
function tileClassName({ date, view }: { date: Date; view: string }) {
if (view !== 'month') return null;
const classes = [
Expand Down Expand Up @@ -257,6 +274,11 @@ const MonthCalender: React.FC<CalendarWithAttendanceProps> = ({
};
setDate(newDate);
if (newDate !== undefined) {
localStorage.setItem('selectedRangeArray', JSON.stringify(newDate));
} else {
console.error('newDate is undefined');
}
if (newDate !== undefined) {
let datesToSet: [Date | null, Date | null];
if (Array.isArray(newDate)) {
datesToSet = [newDate[0] || null, newDate[1] || null];
Expand Down
7 changes: 6 additions & 1 deletion src/pages/centers/[cohortId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const TeachingCenterDetails = () => {
borderRadius: '100px',
height: '40px',
width: '126px',
color: theme.palette.error.contrastText,
}}
className="text-1E"
endIcon={<AddIcon />}
Expand All @@ -150,7 +151,11 @@ const TeachingCenterDetails = () => {
/>
</Box>
<Box>
<CohortLearnerList cohortId={cohortId} reloadState={reloadState} setReloadState={setReloadState}/>
<CohortLearnerList
cohortId={cohortId}
reloadState={reloadState}
setReloadState={setReloadState}
/>
</Box>
</>
)}
Expand Down
21 changes: 19 additions & 2 deletions src/pages/centers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const TeachingCenters = () => {
borderRadius: '100px',
height: '40px',
width: '91px',
color: theme.palette.error.contrastText,
}}
className="text-1E"
endIcon={<AddIcon />}
Expand All @@ -97,7 +98,15 @@ const TeachingCenters = () => {
}}
sx={{ cursor: 'pointer', marginBottom: '20px' }}
>
<Box>{cohort?.['customFields']?.address?.value}</Box>
<Box
sx={{
fontSize: '12px',
fontWeight: '500',
color: theme.palette.warning['300'],
}}
>
{cohort?.['customFields']?.address?.value}
</Box>
<Box
sx={{
display: 'flex',
Expand Down Expand Up @@ -131,7 +140,15 @@ const TeachingCenters = () => {
padding: '0 10px',
}}
>
<Box>{cohort?.name}</Box>
<Box
sx={{
fontSize: '16px',
fontWeight: '400',
color: theme.palette.warning['300'],
}}
>
{cohort?.name}
</Box>
<ChevronRightIcon />
</Box>
</Box>
Expand Down
4 changes: 3 additions & 1 deletion src/styles/customTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const customTheme = extendTheme({
error: {
main: '#BA1A1A',
light: '#FFDAD6',
contrastText: ' #1E1B16',
},
action: {
activeChannel: '#987100',
Expand Down Expand Up @@ -91,6 +92,7 @@ const customTheme = extendTheme({
error: {
main: '#BA1A1A',
light: '#FFDAD6',
contrastText: ' #1E1B16',
},
action: {
activeChannel: '#987100',
Expand Down Expand Up @@ -158,7 +160,7 @@ const customTheme = extendTheme({
styleOverrides: {
root: {
'&.Mui-focused': {
color: '#1F1B13',
color: '#1F1B13',
},
},
},
Expand Down

0 comments on commit 8eb36f5

Please sign in to comment.