From bf9bf858269532af2451b6bf37d2f89de6b9c56a Mon Sep 17 00:00:00 2001 From: ulysse Date: Mon, 6 Jan 2025 15:54:46 +0100 Subject: [PATCH] COM-3855: receive notification --- src/core/data/constants.ts | 1 + src/core/data/tabs.ts | 1 + src/core/helpers/notifications.ts | 11 +++-- src/navigation/AppNavigation/index.tsx | 2 + .../index.tsx | 41 +++++++++++++++++++ .../profile/UpdateAttendanceSheet/index.tsx | 18 ++++++-- src/types/NavigationType.ts | 5 +-- 7 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 src/screens/courses/profile/HandleAttendanceSheetNotification/index.tsx diff --git a/src/core/data/constants.ts b/src/core/data/constants.ts index f90d5794e..d8529953f 100644 --- a/src/core/data/constants.ts +++ b/src/core/data/constants.ts @@ -104,6 +104,7 @@ export const DENIED = 'denied'; export const GRANTED = 'granted'; export const BLENDED_COURSE_REGISTRATION = 'blended_course_registration'; export const NEW_ELEARNING_COURSE = 'new_elearning_course'; +export const ATTENDANCE_SHEET_SIGNATURE_REQUEST = 'attendance_sheet_signature_request'; // CONTEXT export const BEFORE_SIGNIN = 'beforeSignin'; diff --git a/src/core/data/tabs.ts b/src/core/data/tabs.ts index 11f948926..08ab29ae6 100644 --- a/src/core/data/tabs.ts +++ b/src/core/data/tabs.ts @@ -15,4 +15,5 @@ export const tabsNames = { Profile: 'Profil', ActivityCardContainer: 'Activité', QuestionnaireCardContainer: 'Questionnaire', + UpdateAttendanceSheet: 'Emargement des créneaux', }; diff --git a/src/core/helpers/notifications.ts b/src/core/helpers/notifications.ts index 3321bf5a2..a73690f85 100644 --- a/src/core/helpers/notifications.ts +++ b/src/core/helpers/notifications.ts @@ -8,6 +8,7 @@ import { NEW_ELEARNING_COURSE, PEDAGOGY, LEARNER, + ATTENDANCE_SHEET_SIGNATURE_REQUEST, } from '../data/constants'; import { navigationRef } from '../../navigationRef'; import asyncStorage from './asyncStorage'; @@ -54,12 +55,13 @@ export const registerForPushNotificationsAsync = async (): Promise { - const { type, _id } = response.notification.request.content.data as NotificationRequestDataType; + const { type, _id, courseId } = response.notification.request.content.data as NotificationRequestDataType; switch (type) { case BLENDED_COURSE_REGISTRATION: { @@ -72,6 +74,9 @@ export const handleNotificationResponse = async (response: Notifications.Notific return navigationRef.current?.navigate('ElearningAbout', { program: program[0] as ELearningProgramType }); } + case ATTENDANCE_SHEET_SIGNATURE_REQUEST: { + return navigationRef.current?.navigate('HandleAttendanceSheetNotification', { attendanceSheetId: _id, courseId }); + } default: return null; } diff --git a/src/navigation/AppNavigation/index.tsx b/src/navigation/AppNavigation/index.tsx index 6e319eda7..6e9ff3ec9 100644 --- a/src/navigation/AppNavigation/index.tsx +++ b/src/navigation/AppNavigation/index.tsx @@ -12,6 +12,7 @@ import LoginCodeForm from '../../screens/LoginCodeForm'; import CreateAccount from '../../screens/CreateAccount'; import CreateAttendanceSheet from '../../screens/courses/profile/CreateAttendanceSheet'; import UpdateAttendanceSheet from '../../screens/courses/profile/UpdateAttendanceSheet'; +import HandleAttendanceSheetNotification from '../../screens/courses/profile/HandleAttendanceSheetNotification'; import BlendedAbout from '../../screens/explore/BlendedAbout'; import ElearningAbout from '../../screens/explore/ELearningAbout'; import LearnerCourseProfile from '../../screens/courses/profile/LearnerCourseProfile'; @@ -44,6 +45,7 @@ const AppNavigation = () => { AdminCourseProfile, CreateAttendanceSheet, UpdateAttendanceSheet, + HandleAttendanceSheetNotification, ...Profile, ...Courses, }; diff --git a/src/screens/courses/profile/HandleAttendanceSheetNotification/index.tsx b/src/screens/courses/profile/HandleAttendanceSheetNotification/index.tsx new file mode 100644 index 000000000..cede5d9b3 --- /dev/null +++ b/src/screens/courses/profile/HandleAttendanceSheetNotification/index.tsx @@ -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>((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; diff --git a/src/screens/courses/profile/UpdateAttendanceSheet/index.tsx b/src/screens/courses/profile/UpdateAttendanceSheet/index.tsx index 34bb8727d..b3a89e8d7 100644 --- a/src/screens/courses/profile/UpdateAttendanceSheet/index.tsx +++ b/src/screens/courses/profile/UpdateAttendanceSheet/index.tsx @@ -16,6 +16,7 @@ import AttendanceSheetSummary from '../../../../components/AttendanceSheetSummar import AttendanceEndScreen from '../../../../components/AttendanceEndScreen'; import { useGetLoggedUser } from '../../../../store/main/hooks'; import { formatIdentity } from '../../../../core/helpers/utils'; +import { tabsNames } from '../../../../core/data/tabs'; import { generateSignatureFile } from '../helper'; interface UpdateAttendanceSheetProps extends CompositeScreenProps< @@ -129,10 +130,19 @@ const UpdateAttendanceSheet = ({ route, navigation }: UpdateAttendanceSheetProps return ( - {renderSlotSelection} - {renderSignatureContainer} - {renderSummary} - {renderEndScreen} + + {renderSlotSelection} + + + {renderSignatureContainer} + + + {renderSummary} + + + {renderEndScreen} + ); }; diff --git a/src/types/NavigationType.ts b/src/types/NavigationType.ts index 3f4d39020..791578ab2 100644 --- a/src/types/NavigationType.ts +++ b/src/types/NavigationType.ts @@ -20,12 +20,11 @@ export type RootStackParamList = { endedActivity?: string | null, endedQuestionnaire?: string | null, }; - TrainerCourseProfile: { - courseId: string, - }; + TrainerCourseProfile: { courseId: string }; SubProgramProfile: { subProgramId: string }; CourseProfileHeader: undefined, LoginCodeForm: undefined, + HandleAttendanceSheetNotification: { attendanceSheetId: string, courseId: string } } export type RootBottomTabParamList = {