From c5d25e2c3161145b61fdfa8db151d34a492210f8 Mon Sep 17 00:00:00 2001 From: Manon Palin Date: Thu, 9 Jan 2025 20:32:56 +0100 Subject: [PATCH 1/2] COM-3877 - display qrcode and questionnaireForm at every courseTimeline --- src/api/questionnaires.ts | 2 +- .../QuestionnaireQRCodeCell/index.tsx | 7 ++-- src/core/data/constants.ts | 2 + .../profile/AdminCourseProfile/index.tsx | 41 +++++++++++++++---- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/api/questionnaires.ts b/src/api/questionnaires.ts index 6ced55c1e..5d620fffb 100644 --- a/src/api/questionnaires.ts +++ b/src/api/questionnaires.ts @@ -26,7 +26,7 @@ export default { return response.data.data.questionnaires; }, - getQRCode: async (params: { course: string }): Promise => { + getQRCode: async (params: { course: string, courseTimeline: string }): Promise => { const baseURL = await Environment.getBaseUrl(); const response: AxiosResponse = await axiosLogged.get(`${baseURL}/questionnaires/qrcode`, { params }); diff --git a/src/components/QuestionnaireQRCodeCell/index.tsx b/src/components/QuestionnaireQRCodeCell/index.tsx index d6390d633..8ae6796be 100644 --- a/src/components/QuestionnaireQRCodeCell/index.tsx +++ b/src/components/QuestionnaireQRCodeCell/index.tsx @@ -9,9 +9,10 @@ interface QuestionnaireQRCodeCellProps { img: string, types: string[], courseId: string, + courseTimeline: string, } -const QuestionnaireQRCodeCell = ({ img, types, courseId }: QuestionnaireQRCodeCellProps) => { +const QuestionnaireQRCodeCell = ({ img, types, courseId, courseTimeline }: QuestionnaireQRCodeCellProps) => { const [questionnaireTypeTitle, setQuestionnaireTypeTitle] = useState(''); const [qrCodePlaceHolder, setQrCodePlaceHolder] = useState(''); const [url, setUrl] = useState(''); @@ -20,11 +21,11 @@ const QuestionnaireQRCodeCell = ({ img, types, courseId }: QuestionnaireQRCodeCe const defineURL = async () => { const webappURL = await Environment.getWebappUrl(); - setUrl(`${webappURL}/ni/questionnaires?courseId=${courseId}`); + setUrl(`${webappURL}/ni/questionnaires?courseId=${courseId}&courseTimeline=${courseTimeline}`); }; defineURL(); - }, [courseId]); + }, [courseId, courseTimeline]); useEffect(() => { const title = getQuestionnaireTitle(types); diff --git a/src/core/data/constants.ts b/src/core/data/constants.ts index d8529953f..4f6a2e565 100644 --- a/src/core/data/constants.ts +++ b/src/core/data/constants.ts @@ -64,6 +64,8 @@ export const PUBLISHED = 'published'; export const EXPECTATIONS = 'expectations'; export const END_OF_COURSE = 'end_of_course'; export const SELF_POSITIONNING = 'self_positionning'; +export const START_COURSE = 'start_course'; +export const END_COURSE = 'end_course'; // ROLE export const VENDOR_ADMIN = 'vendor_admin'; diff --git a/src/screens/courses/profile/AdminCourseProfile/index.tsx b/src/screens/courses/profile/AdminCourseProfile/index.tsx index 875a7f8d5..5454f35b4 100644 --- a/src/screens/courses/profile/AdminCourseProfile/index.tsx +++ b/src/screens/courses/profile/AdminCourseProfile/index.tsx @@ -40,6 +40,10 @@ import { PDF, SHORT_FIRSTNAME_LONG_LASTNAME, SINGLE_COURSES_SUBPROGRAM_IDS, + EXPECTATIONS, + END_OF_COURSE, + START_COURSE, + END_COURSE, } from '../../../../core/data/constants'; import CompaniDate from '../../../../core/helpers/dates/companiDates'; import PersonCell from '../../../../components/PersonCell'; @@ -73,6 +77,8 @@ interface imagePreviewProps { type: string, } +type QRCodeType = { img: string, courseTimeline: string }; + const AdminCourseProfile = ({ route, navigation }: AdminCourseProfileProps) => { const course = useGetCourse(); const setCourse = useSetCourse(); @@ -139,7 +145,7 @@ const AdminCourseProfile = ({ route, navigation }: AdminCourseProfileProps) => { const [imagePreview, setImagePreview] = useState({ visible: false, id: '', link: '', type: '' }); - const [questionnaireQRCode, setQuestionnaireQRCode] = useState(''); + const [questionnaireQRCodes, setQuestionnaireQRCodes] = useState([]); const [questionnairesType, setQuestionnairesType] = useState([]); const refreshAttendanceSheets = async (courseId: string) => { @@ -151,15 +157,25 @@ const AdminCourseProfile = ({ route, navigation }: AdminCourseProfileProps) => { const getQuestionnaireQRCode = async (courseId: string) => { try { const publishedQuestionnaires = await Questionnaires.list({ course: courseId }); - setQuestionnairesType(publishedQuestionnaires.map(q => q.type).sort((a, b) => sortStrings(a, b))); + const questionnairesTypeList = publishedQuestionnaires.map(q => q.type).sort((a, b) => sortStrings(a, b)); + setQuestionnairesType(questionnairesTypeList); + const qrCodes = []; if (publishedQuestionnaires.length) { - const qrCode = await Questionnaires.getQRCode({ course: courseId }); - setQuestionnaireQRCode(qrCode); + if (questionnairesTypeList.includes(EXPECTATIONS)) { + const img = await Questionnaires.getQRCode({ course: courseId, courseTimeline: START_COURSE }); + qrCodes.push({ img, courseTimeline: START_COURSE }); + } + if (questionnairesTypeList.includes(END_OF_COURSE)) { + const img = await Questionnaires.getQRCode({ course: courseId, courseTimeline: END_COURSE }); + qrCodes.push({ img, courseTimeline: END_COURSE }); + } + + setQuestionnaireQRCodes(qrCodes); } } catch (e: any) { console.error(e); - setQuestionnaireQRCode(''); + setQuestionnaireQRCodes([]); } }; @@ -278,6 +294,14 @@ const AdminCourseProfile = ({ route, navigation }: AdminCourseProfileProps) => { const goToAttendanceSheetUpload = () => navigation.navigate('CreateAttendanceSheet', { isSingle }); + const renderQuestionnaireCell = (item: QRCodeType) => { + const types = questionnairesType + .filter(qType => (item.courseTimeline === START_COURSE ? qType !== END_OF_COURSE : qType !== EXPECTATIONS)); + + return ; + }; + return course && has(course, 'subProgram.program') ? ( @@ -328,11 +352,12 @@ const AdminCourseProfile = ({ route, navigation }: AdminCourseProfileProps) => { } {!!course.trainees && course.trainees.map(item => {renderTrainee(item)})} - {!!questionnaireQRCode && + {!!questionnaireQRCodes.length && Questionnaires - + `qrcode_${idx}`} + renderItem={({ item }) => renderQuestionnaireCell(item)} + showsHorizontalScrollIndicator={false} /> } {course.type !== INTER_B2B && From 225405a0ed8f24bb45ba47974053e665b426ec36 Mon Sep 17 00:00:00 2001 From: Manon Palin Date: Wed, 15 Jan 2025 14:06:54 +0100 Subject: [PATCH 2/2] COM-3877 - fix reviews --- src/screens/courses/profile/AdminCourseProfile/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screens/courses/profile/AdminCourseProfile/index.tsx b/src/screens/courses/profile/AdminCourseProfile/index.tsx index 5454f35b4..b1a81df15 100644 --- a/src/screens/courses/profile/AdminCourseProfile/index.tsx +++ b/src/screens/courses/profile/AdminCourseProfile/index.tsx @@ -355,7 +355,7 @@ const AdminCourseProfile = ({ route, navigation }: AdminCourseProfileProps) => { {!!questionnaireQRCodes.length && Questionnaires - `qrcode_${idx}`} + `qrcode_${idx}`} scrollEnabled={false} renderItem={({ item }) => renderQuestionnaireCell(item)} showsHorizontalScrollIndicator={false} /> }