Skip to content

Commit 0ff6fdd

Browse files
ux-gitFussuChalice
andauthored
fix(dashboard): exclude past assignments from meeting counter
Co-authored-by: ux-git <ux-git@users.noreply.github.com> Co-authored-by: Max Makaluk <70341920+FussuChalice@users.noreply.github.com>
1 parent aa6606f commit 0ff6fdd

File tree

4 files changed

+50
-33
lines changed

4 files changed

+50
-33
lines changed

src/features/meetings/my_assignments/useAssignments.ts

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
import { DisplayRange } from './indextypes';
1111
import { localStorageGetItem } from '@utils/common';
1212
import { assignmentsHistoryState } from '@states/schedules';
13-
import { addWeeks, formatDate, getWeekDate } from '@utils/date';
13+
import { addWeeks, formatDate } from '@utils/date';
1414
import { AssignmentHistoryType } from '@definition/schedules';
15-
import { schedulesGetMeetingDate } from '@services/app/schedules';
15+
import { resolveAssignmentDate } from '@utils/assignments';
1616

1717
const useMyAssignments = () => {
1818
const navigate = useNavigate();
@@ -41,31 +41,9 @@ const useMyAssignments = () => {
4141
const now = new Date();
4242
const maxDate = addWeeks(now, displayRange);
4343

44-
const remapAssignmentsDate = assignmentsHistory.map((record) => {
45-
const obj = structuredClone(record);
46-
47-
const isMidweek = obj.assignment.key.startsWith('MM_');
48-
49-
const meetingDate = schedulesGetMeetingDate({
50-
week: obj.weekOf,
51-
meeting: isMidweek ? 'midweek' : 'weekend',
52-
dataView: obj.assignment.dataView,
53-
});
54-
55-
if (meetingDate.date.length > 0) {
56-
obj.weekOf = meetingDate.date;
57-
obj.weekOfFormatted = formatDate(
58-
new Date(meetingDate.date),
59-
shortDateFormat
60-
);
61-
}
62-
63-
if (obj.weekOf.length === 0) {
64-
obj.weekOf = formatDate(getWeekDate(), 'yyyy/MM/dd');
65-
}
66-
67-
return obj;
68-
});
44+
const remapAssignmentsDate = assignmentsHistory.map((record) =>
45+
resolveAssignmentDate(record, shortDateFormat)
46+
);
6947

7048
const filterAssignments = (uid: string) => {
7149
return remapAssignmentsDate.filter(

src/pages/dashboard/meetings/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const MeetingsCard = ({ assignmentCount }: MeetingsCardProps) => {
3030
<DashboardMenu
3131
icon={<IconAssignment color="var(--black)" />}
3232
primaryText={t('tr_viewMyAssignments')}
33-
badgeText={assignmentCount.toString()}
33+
badgeText={assignmentCount ? assignmentCount.toString() : ''}
3434
onClick={handleOpenMyAssignments}
3535
/>
3636
</ListItem>

src/pages/dashboard/useDashboard.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import {
44
congNewState,
55
firstnameState,
66
settingsState,
7+
shortDateFormatState,
78
userLocalUIDState,
89
} from '@states/settings';
910
import { isMyAssignmentOpenState } from '@states/app';
1011
import { assignmentsHistoryState } from '@states/schedules';
11-
import { formatDate, getWeekDate } from '@utils/date';
12+
import { formatDate } from '@utils/date';
1213
import { isTest } from '@constants/index';
14+
import { resolveAssignmentDate } from '@utils/assignments';
1315

1416
const useDashboard = () => {
1517
const setIsMyAssignmentOpen = useSetAtom(isMyAssignmentOpenState);
@@ -18,6 +20,7 @@ const useDashboard = () => {
1820
const isCongNew = useAtomValue(congNewState);
1921
const userUID = useAtomValue(userLocalUIDState);
2022
const assignmentsHistory = useAtomValue(assignmentsHistoryState);
23+
const shortDateFormat = useAtomValue(shortDateFormatState);
2124
const settings = useAtomValue(settingsState);
2225

2326
const isMigrated = useMemo(() => {
@@ -31,16 +34,20 @@ const useDashboard = () => {
3134
const [newCongSnack, setNewCongSnack] = useState(initialSnackValue);
3235

3336
const countFutureAssignments = useMemo(() => {
34-
const now = formatDate(getWeekDate(), 'yyyy/MM/dd');
37+
const now = new Date();
3538

36-
const personAssignments = assignmentsHistory.filter(
39+
const remapAssignmentsDate = assignmentsHistory.map((record) =>
40+
resolveAssignmentDate(record, shortDateFormat)
41+
);
42+
43+
const personAssignments = remapAssignmentsDate.filter(
3744
(record) =>
3845
record.assignment.person === userUID &&
39-
formatDate(new Date(record.weekOf), 'yyyy/MM/dd') >= now
46+
record.weekOf >= formatDate(now, 'yyyy/MM/dd')
4047
);
4148

4249
return personAssignments.length;
43-
}, [assignmentsHistory, userUID]);
50+
}, [assignmentsHistory, shortDateFormat, userUID]);
4451

4552
const handleCloseNewCongNotice = async () => {
4653
setNewCongSnack(false);

src/utils/assignments.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { AssignmentCode } from '@definition/assignment';
22
import { PersonType, AssignmentType } from '@definition/person';
3+
import { AssignmentHistoryType } from '@definition/schedules';
34
import { personIsFR, personIsFS } from '@services/app/persons';
5+
import { formatDate, getWeekDate } from './date';
6+
import { schedulesGetMeetingDate } from '@services/app/schedules';
47

58
const duplicateAssignmentsCode = new Set([
69
AssignmentCode.MINISTRY_HOURS_CREDIT,
@@ -156,3 +159,32 @@ export const toggleAssignment = (
156159

157160
return newPerson;
158161
};
162+
163+
export const resolveAssignmentDate = (
164+
record: AssignmentHistoryType,
165+
shortDateFormat: string
166+
) => {
167+
const obj = structuredClone(record);
168+
169+
const isMidweek = obj.assignment.key.startsWith('MM_');
170+
171+
const meetingDate = schedulesGetMeetingDate({
172+
week: obj.weekOf,
173+
meeting: isMidweek ? 'midweek' : 'weekend',
174+
dataView: obj.assignment.dataView,
175+
});
176+
177+
if (meetingDate.date.length > 0) {
178+
obj.weekOf = meetingDate.date;
179+
obj.weekOfFormatted = formatDate(
180+
new Date(meetingDate.date),
181+
shortDateFormat
182+
);
183+
}
184+
185+
if (obj.weekOf.length === 0) {
186+
obj.weekOf = formatDate(getWeekDate(), 'yyyy/MM/dd');
187+
}
188+
189+
return obj;
190+
};

0 commit comments

Comments
 (0)