-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #698 from sophiemoustard/COM-3855
COM-3855: receive notification
- Loading branch information
Showing
7 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/screens/courses/profile/HandleAttendanceSheetNotification/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useEffect } from 'react'; | ||
import groupBy from 'lodash/groupBy'; | ||
import { StackScreenProps } from '@react-navigation/stack'; | ||
import { useSetGroupedSlotsToBeSigned } from '../../../../store/attendanceSheets/hooks'; | ||
import Courses from '../../../../api/courses'; | ||
import { RootStackParamList } from '../../../../types/NavigationType'; | ||
import { BlendedCourseType, SlotType } from '../../../../types/CourseTypes'; | ||
|
||
interface HandleAttendanceSheetNotificationProps extends StackScreenProps< | ||
RootStackParamList, 'HandleAttendanceSheetNotification'>{} | ||
|
||
const HandleAttendanceSheetNotification = ({ route, navigation }: HandleAttendanceSheetNotificationProps) => { | ||
const { attendanceSheetId, courseId } = route.params; | ||
const setGroupedSlotsToBeSigned = useSetGroupedSlotsToBeSigned(); | ||
|
||
useEffect(() => { | ||
const storeDataAndRedirect = async () => { | ||
try { | ||
const course = await Courses.getCourse(courseId, 'pedagogy') as BlendedCourseType; | ||
const attendanceSheet = course.attendanceSheets?.find(as => as._id === attendanceSheetId); | ||
const groupedSlots = groupBy(attendanceSheet?.slots, 'step'); | ||
const groupedSlotsToBeSigned = course.subProgram.steps.reduce<Record<string, SlotType[]>>((acc, step) => { | ||
if (groupedSlots[step._id]) acc[step.name] = groupedSlots[step._id]; | ||
return acc; | ||
}, {}); | ||
|
||
setGroupedSlotsToBeSigned(groupedSlotsToBeSigned); | ||
|
||
navigation.replace('UpdateAttendanceSheet', { attendanceSheetId }); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
storeDataAndRedirect(); | ||
}, [attendanceSheetId, courseId, navigation, setGroupedSlotsToBeSigned]); | ||
|
||
return null; | ||
}; | ||
|
||
export default HandleAttendanceSheetNotification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters