Skip to content

Commit

Permalink
Merge pull request #698 from sophiemoustard/COM-3855
Browse files Browse the repository at this point in the history
COM-3855: receive notification
  • Loading branch information
manonpalin authored Jan 7, 2025
2 parents 8f0a642 + bf9bf85 commit dde65f1
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/core/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions src/core/data/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export const tabsNames = {
Profile: 'Profil',
ActivityCardContainer: 'Activité',
QuestionnaireCardContainer: 'Questionnaire',
UpdateAttendanceSheet: 'Emargement des créneaux',
};
11 changes: 8 additions & 3 deletions src/core/helpers/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -54,12 +55,13 @@ export const registerForPushNotificationsAsync = async (): Promise<ExpoTokenAndS
};

type NotificationRequestDataType = {
type: typeof BLENDED_COURSE_REGISTRATION | typeof NEW_ELEARNING_COURSE,
_id: string
type: typeof BLENDED_COURSE_REGISTRATION | typeof NEW_ELEARNING_COURSE | typeof ATTENDANCE_SHEET_SIGNATURE_REQUEST,
_id: string,
courseId: string,
};

export const handleNotificationResponse = async (response: Notifications.NotificationResponse) => {
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: {
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/navigation/AppNavigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -44,6 +45,7 @@ const AppNavigation = () => {
AdminCourseProfile,
CreateAttendanceSheet,
UpdateAttendanceSheet,
HandleAttendanceSheetNotification,
...Profile,
...Courses,
};
Expand Down
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;
18 changes: 14 additions & 4 deletions src/screens/courses/profile/UpdateAttendanceSheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -129,10 +130,19 @@ const UpdateAttendanceSheet = ({ route, navigation }: UpdateAttendanceSheetProps

return (
<Stack.Navigator screenOptions={{ headerShown: false, cardStyle: { flex: 1 } }} initialRouteName={SLOTS_SELECTION}>
<Stack.Screen key={1} name={SLOTS_SELECTION}>{renderSlotSelection}</Stack.Screen>
<Stack.Screen key={2} name={ATTENDANCE_SIGNATURE}>{renderSignatureContainer}</Stack.Screen>
<Stack.Screen key={3} name={ATTENDANCE_SUMMARY}>{renderSummary}</Stack.Screen>
<Stack.Screen options={{ gestureEnabled: false }} key={4} name={END_SCREEN}>{renderEndScreen}</Stack.Screen>
<Stack.Screen key={1} name={SLOTS_SELECTION} options={{ title: tabsNames.UpdateAttendanceSheet }}>
{renderSlotSelection}
</Stack.Screen>
<Stack.Screen key={2} name={ATTENDANCE_SIGNATURE} options={{ title: tabsNames.UpdateAttendanceSheet }}>
{renderSignatureContainer}
</Stack.Screen>
<Stack.Screen key={3} name={ATTENDANCE_SUMMARY} options={{ title: tabsNames.UpdateAttendanceSheet }}>
{renderSummary}
</Stack.Screen>
<Stack.Screen options={{ gestureEnabled: false, title: tabsNames.UpdateAttendanceSheet }} key={4}
name={END_SCREEN}>
{renderEndScreen}
</Stack.Screen>
</Stack.Navigator>
);
};
Expand Down
5 changes: 2 additions & 3 deletions src/types/NavigationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit dde65f1

Please sign in to comment.