Skip to content

Commit

Permalink
COM-3854: can sign as a trainee
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysseferreira committed Dec 19, 2024
1 parent c696cdf commit 511fa43
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 33 deletions.
55 changes: 39 additions & 16 deletions src/components/AttendanceEndScreen/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { View, Text, Image } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { MaterialIcons } from '@expo/vector-icons';
import { TRAINER } from '../../core/data/constants';
import NiPrimaryButton from '../form/PrimaryButton';
import { PINK } from '../../styles/colors';
import styles from './styles';
Expand All @@ -9,28 +10,50 @@ interface AttendanceEndScreenProps {
traineeName: string,
failUpload: boolean,
goToNextScreen: () => void,
mode?: string
}

const AttendanceEndScreen = ({ traineeName, failUpload, goToNextScreen }: AttendanceEndScreenProps) => (
const AttendanceEndScreen = ({ traineeName, failUpload, goToNextScreen, mode = TRAINER }: AttendanceEndScreenProps) => (
<SafeAreaView style={styles.safeArea} edges={['top']}>
{failUpload
? <View style={styles.errorContainer}>
<Text style={styles.title}>Echec de l&apos;envoi de la demande à {traineeName}</Text>
<MaterialIcons style={styles.icon} size={200} name={'warning'} color={PINK[500]} />
<Text style={styles.text}>Veuillez réitérer votre demande</Text>
</View>
: <>
<View style={styles.upperContainer}>
<Text style={styles.title}>Une demande d&apos;émargement a été envoyée à {traineeName}</Text>
{mode === TRAINER ? <>
{failUpload
? <View style={styles.errorContainer}>
<Text style={styles.title}>Echec de l&apos;envoi de la demande à {traineeName}</Text>
<MaterialIcons style={styles.icon} size={200} name={'warning'} color={PINK[500]} />
<Text style={styles.text}>Veuillez réitérer votre demande</Text>
</View>
<Text style={styles.text}>Elle est disponible sur la page de la formation sur son application mobile</Text>
<Image source={require('../../../assets/images/aux_fierte.webp')} style={styles.image} />
<Text style={styles.text}>
: <>
<View style={styles.upperContainer}>
<Text style={styles.title}>Une demande d&apos;émargement a été envoyée à {traineeName}</Text>
</View>
<Text style={styles.text}>Elle est disponible sur la page de la formation sur son application mobile</Text>
<Image source={require('../../../assets/images/aux_fierte.webp')} style={styles.image} />
<Text style={styles.text}>
N&apos;oubliez pas de reporter les émargements dans le tableau prévu à cet effet sur l&apos;application
web Compani
</Text>
</>
}
</Text>
</>
}
</>
: <>
{failUpload
? <View style={styles.errorContainer}>
<Text style={styles.title}>Echec lors de l&apos;envoi de votre signature</Text>
<MaterialIcons style={styles.icon} size={200} name={'warning'} color={PINK[500]} />
<Text style={styles.text}>Veuillez réitérer votre demande</Text>
</View>
: <>
<View style={styles.upperContainer}>
<Text style={styles.title}>Merci d&apos;avoir émargé les créneaux</Text>
</View>
<Image source={require('../../../assets/images/aux_fierte.webp')} style={styles.image} />
<Text style={styles.text}>
Vous pouvez désormais retourner sur votre formation pour émarger d&apos;autres créneaux ou poursuivre
votre apprentissage
</Text>
</>
}
</>}
<View style={styles.footer}>
<NiPrimaryButton caption={'Terminer'} onPress={goToNextScreen} />
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/components/AttendanceSignatureContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const AttendanceSignatureContainer = ({
<iframe
ref={iframeRef}
src={`data:text/html,${encodeURIComponent(htmlContent)}`}
style={{ width: '50%', height: 'auto', aspectRatio: 1, border: '1px solid #ccc' }}
style={{ width: '30%', height: 'auto', aspectRatio: 1, border: '1px solid #ccc' }}
/>
</View>
: <View style={styles.webviewContainer}>
Expand Down
20 changes: 10 additions & 10 deletions src/screens/courses/profile/LearnerCourseProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import * as IntentLauncher from 'expo-intent-launcher';
import { Buffer } from 'buffer';
import { Feather } from '@expo/vector-icons';
import { StackScreenProps } from '@react-navigation/stack';
import pick from 'lodash/pick';
import { RootStackParamList, RootBottomTabParamList } from '../../../../types/NavigationType';
import Courses from '../../../../api/courses';
import Questionnaires from '../../../../api/questionnaires';
Expand Down Expand Up @@ -56,7 +55,7 @@ StackScreenProps<RootBottomTabParamList>
const LearnerCourseProfile = ({ route, navigation }: LearnerCourseProfileProps) => {
const setStatusBarVisible = useSetStatusBarVisible();
const userId: string | null = useGetLoggedUserId();
const setCourseInStore = useSetCourse();
const setCourseToStore = useSetCourse();

const [course, setCourse] = useState<CourseType | null>(null);
const [questionnaires, setQuestionnaires] = useState<QuestionnaireType[]>([]);
Expand All @@ -81,17 +80,18 @@ const LearnerCourseProfile = ({ route, navigation }: LearnerCourseProfileProps)
Courses.getCourse(route.params.courseId, PEDAGOGY),
Questionnaires.getUserQuestionnaires({ course: route.params.courseId }),
]);
if (fetchedCourse.format === BLENDED) {
const formattedCourse = {
_id: fetchedCourse._id,
trainer: { identity: (fetchedCourse as BlendedCourseType).trainer.identity },
subProgram: { steps: fetchedCourse.subProgram.steps.map(s => ({ _id: s._id, name: s.name })) },
} as BlendedCourseType;
setCourseToStore(formattedCourse);
}
const programImage = get(fetchedCourse, 'subProgram.program.image.link') || '';
setCourse(fetchedCourse);
setQuestionnaires(fetchedQuestionnaires);
if (programImage) setSource({ uri: programImage });
if (fetchedCourse.format === BLENDED) {
const formattedCourse = pick(
fetchedCourse,
['subProgram.steps', 'trainer.identity', '_id']
) as BlendedCourseType;
setCourseInStore(formattedCourse);
}
} catch (e: any) {
console.error(e);
setCourse(null);
Expand All @@ -102,7 +102,7 @@ const LearnerCourseProfile = ({ route, navigation }: LearnerCourseProfileProps)
setStatusBarVisible(true);
getCourse();
}
}, [isFocused, setStatusBarVisible, route.params.courseId, setCourseInStore]);
}, [isFocused, setStatusBarVisible, route.params.courseId, setCourseToStore]);

const goBack = useCallback(() => {
navigation.navigate('LearnerCourses');
Expand Down
12 changes: 6 additions & 6 deletions src/screens/courses/profile/UpdateAttendanceSheet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useCallback, useEffect, useMemo, useReducer, useState } from 'react';
import { useEffect, useMemo, useReducer, useState } from 'react';
import { createStackNavigator, StackScreenProps } from '@react-navigation/stack';
import { CompositeScreenProps } from '@react-navigation/native';
import keyBy from 'lodash/keyBy';
import AttendanceSheets from '../../../../api/attendanceSheets';
import { RootStackParamList, RootUpdateAttendanceSheetParamList } from '../../../../types/NavigationType';
import { DD_MM_YYYY, HH_MM, IS_WEB, LONG_FIRSTNAME_LONG_LASTNAME } from '../../../../core/data/constants';
import { DD_MM_YYYY, HH_MM, IS_WEB, LEARNER, LONG_FIRSTNAME_LONG_LASTNAME } from '../../../../core/data/constants';
import { errorReducer, initialErrorState, RESET_ERROR, SET_ERROR } from '../../../../reducers/error';
import AttendanceSheetSelectionForm from '../../../../components/AttendanceSheetSelectionForm';
import { useGetCourse, useGetGroupedSlotsToBeSigned } from '../../../../store/attendanceSheets/hooks';
Expand All @@ -28,7 +28,7 @@ const ATTENDANCE_SIGNATURE = 'attendance-signature';
const ATTENDANCE_SUMMARY = 'attendance-summary';
const END_SCREEN = 'end-screen';

const CreateAttendanceSheet = ({ route, navigation }: UpdateAttendanceSheetProps) => {
const UpdateAttendanceSheet = ({ route, navigation }: UpdateAttendanceSheetProps) => {
const { attendanceSheetId } = route.params;
const course = useGetCourse();
const loggedUser = useGetLoggedUser();
Expand All @@ -43,7 +43,6 @@ const CreateAttendanceSheet = ({ route, navigation }: UpdateAttendanceSheetProps
const [errorSignature, dispatchErrorSignature] = useReducer(errorReducer, initialErrorState);
const [errorConfirmation, dispatchErrorConfirmation] = useReducer(errorReducer, initialErrorState);
const stepsById = useMemo(() => keyBy(course?.subProgram.steps, '_id'), [course]);
console.log(stepsById);
const stepsName = useMemo(() =>
Object.keys(groupedSlotsToBeSigned).map(stepId => (stepsById[stepId].name)),
[groupedSlotsToBeSigned, stepsById]);
Expand Down Expand Up @@ -140,7 +139,8 @@ const CreateAttendanceSheet = ({ route, navigation }: UpdateAttendanceSheetProps
traineeName={traineeName} slotsOptions={slotsOptions} />
);
const renderEndScreen = () => (
<AttendanceEndScreen goToNextScreen={navigation.goBack} traineeName={traineeName} failUpload={failUpload} />
<AttendanceEndScreen goToNextScreen={navigation.goBack} traineeName={traineeName} failUpload={failUpload}
mode={LEARNER} />
);

const Stack = createStackNavigator<RootUpdateAttendanceSheetParamList>();
Expand All @@ -155,4 +155,4 @@ const CreateAttendanceSheet = ({ route, navigation }: UpdateAttendanceSheetProps
);
};

export default CreateAttendanceSheet;
export default UpdateAttendanceSheet;

0 comments on commit 511fa43

Please sign in to comment.