From bffa79e7ce8e0c78b19383095b9742a62fc07ddb Mon Sep 17 00:00:00 2001 From: Mailine Nguyen Date: Tue, 18 Mar 2025 13:40:31 +0100 Subject: [PATCH 1/2] fix: opening a non started planner no locker lock the planner --- .../SurveyPageStep/SurveyPageStep.tsx | 97 ++++++++++++++----- src/pages/day-of-survey/DayOfSurvey.tsx | 14 ++- yarn.lock | 8 +- 3 files changed, 89 insertions(+), 30 deletions(-) diff --git a/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx b/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx index d2f7ec3f..f7be22d1 100644 --- a/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx +++ b/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx @@ -13,7 +13,9 @@ import { useTranslation } from "react-i18next"; import { useNavigate, useOutletContext } from "react-router"; import { useLocation } from "react-router-dom"; import { + getNavigatePath, getOrchestratorPage, + getParameterizedNavigatePath, saveAndNav, saveAndNavFullPath, saveAndNavLocally, @@ -28,6 +30,9 @@ import { surveyReadOnly } from "../../../../service/survey-activity-service"; import { getData, getPrintedFirstName, getPrintedSurveyDate } from "../../../../service/survey-service"; import { getSurveyIdFromUrl } from "../../../../utils/utils"; import SurveyPage from "../SurveyPage"; +import { EdtUserRightsEnum } from "../../../../enumerations/EdtUserRightsEnum"; +import { getUserRights } from "../../../../service/user-service"; +import _ from "lodash"; export interface SurveyPageStepProps { currentPage: EdtRoutesNameEnum; @@ -68,6 +73,10 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { setEnviro(context, navigate, callbackHolder); }); + const navigateHome = useCallback(() => { + return navigate(getNavigatePath(EdtRoutesNameEnum.SURVEYED_HOME)); + }, []); + const { classes, cx } = useStyles({ "isMobile": !isPwa(), "isIOS": isIOS, @@ -108,22 +117,47 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { const surveyPageStepProps = { idSurvey: idSurvey, onNavigateBack: useCallback( - () => - specifiquesProps?.displayModal - ? validateAndNav(false, setIsModalDisplayed) - : saveAndNavLocally(idSurvey), - [isModalDisplayed], - ), - onNext: useCallback( - () => - specifiquesProps?.displayModal - ? validateAndNav(false, setIsModalDisplayed) - : saveAndNextStep(idSurvey, context.source, EdtRoutesNameEnum.ACTIVITY, currentPage), + () => { + const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; + if (!isReviewerMode) { + console.log("saveData"); + if (specifiquesProps?.displayModal) { + validateAndNav(false, setIsModalDisplayed); + } else { + saveAndNavLocally(idSurvey); + } + } + navigateHome(); + }, + [isModalDisplayed], ), + onNext: useCallback(() => { + const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; + if (!isReviewerMode) { + if (specifiquesProps?.displayModal) { + validateAndNav(false, setIsModalDisplayed); + } else { + saveAndNextStep(idSurvey, context.source, EdtRoutesNameEnum.ACTIVITY, currentPage); + } + } + + }, [isModalDisplayed]), onPrevious: useCallback( - () => (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNavLocally(idSurvey)), - [], + () => { + const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; + if (!isReviewerMode) { + (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNavLocally(idSurvey)) + + } + navigate( + backRoute + ? getNavigatePath(backRoute) + : `${getParameterizedNavigatePath(EdtRoutesNameEnum.ACTIVITY, idSurvey)}${getNavigatePath(EdtRoutesNameEnum.ACTIVITY_SUMMARY)}` + ); + }, + + [] ), simpleHeader: true, simpleHeaderLabel: t("page.complementary-questions.simple-header-label"), @@ -142,25 +176,44 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { if (!validateButton) { return; } - validateButton(); - if (nextRoute) { - saveAndNavFullPath(idSurvey, nextRoute); - } else { - saveAndNextStep(idSurvey, context.source, context.surveyRootPage, currentPage); + const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; + if (!isReviewerMode) { + validateButton(); + if (nextRoute) { + saveAndNavFullPath(idSurvey, nextRoute); + } else { + saveAndNextStep(idSurvey, context.source, context.surveyRootPage, currentPage); + } } + + }, []), icon: errorIcon ? : undefined, - onNavigateBack: useCallback(() => saveAndNavLocally(idSurvey), []), + onNavigateBack: useCallback(() => { + const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; + if (!isReviewerMode) { + saveAndNavLocally(idSurvey); + } + + navigateHome(); + }, []), onPrevious: useCallback( - () => (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNavLocally(idSurvey)), - [], + () => { + const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; + if (!isReviewerMode) { + (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNavLocally(idSurvey)) + + } + navigate(getNavigatePath(backRoute ?? EdtRoutesNameEnum.ACTIVITY)); + }, + [] ), firstName: getPrintedFirstName(idSurvey), surveyDate: getPrintedSurveyDate(idSurvey, context.surveyRootPage), disableNav: disableButton, modifiable: modifiable, }; - + const validateAndNav = ( forceQuit: boolean, setIsModalDisplayed: (value: SetStateAction) => void, diff --git a/src/pages/day-of-survey/DayOfSurvey.tsx b/src/pages/day-of-survey/DayOfSurvey.tsx index 4fc62ffb..34588c05 100644 --- a/src/pages/day-of-survey/DayOfSurvey.tsx +++ b/src/pages/day-of-survey/DayOfSurvey.tsx @@ -22,6 +22,8 @@ import { setValue, } from "../../service/survey-service"; import { getSurveyIdFromUrl } from "../../utils/utils"; +import { getUserRights } from "../../service/user-service"; +import { EdtUserRightsEnum } from "../../enumerations/EdtUserRightsEnum"; const DayOfSurveyPage = () => { const context: OrchestratorContext = useOutletContext(); @@ -99,10 +101,14 @@ const DayOfSurveyPage = () => { personAct?.data?.questionnaireModelId == SourcesEnum.WORK_TIME_SURVEY ? EdtRoutesNameEnum.WORK_TIME : EdtRoutesNameEnum.ACTIVITY; - const dataUpdated = setSurveyDate(input); - saveData(idSurvey, dataUpdated, false, true).then(() => { - navigate(navToPlanner(idSurvey, surveyRootPage)); - }); + + const isReviewerMode = getUserRights() == EdtUserRightsEnum.REVIEWER; + if (!isReviewerMode) { + const dataUpdated = setSurveyDate(input); + saveData(idSurvey, dataUpdated, false, true).then(() => { + navigate(navToPlanner(idSurvey, surveyRootPage)); + }) + } }, []); return ( diff --git a/yarn.lock b/yarn.lock index 2544f462..95afd459 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1202,10 +1202,10 @@ dependencies: antlr4 "4.8.0" -"@inseefrlab/lunatic-edt@^0.14.6": - version "0.14.6" - resolved "https://registry.yarnpkg.com/@inseefrlab/lunatic-edt/-/lunatic-edt-0.14.6.tgz#1994526ed7d699137cd6e19c740eb53cc796b6b2" - integrity sha512-1abnuK4IK9WMMw+t27d6SBYqHP02D8ewwq8BSD7RmxXDd1KiZZzs09lD1UVLGVEXPOP2yQ2hsKRk5lrsTRB5jQ== +"@inseefrlab/lunatic-edt@^0.14.8": + version "0.14.8" + resolved "https://registry.yarnpkg.com/@inseefrlab/lunatic-edt/-/lunatic-edt-0.14.8.tgz#f3c07bf1bb9ca2fd04f4362980c54185fddab733" + integrity sha512-VKWgeMF0ZIvlrirWEWf3YeZkrEHYCO8qQTyxh2eRMy3IrGk+1RC7aSTwZ5s2+ZF5SfP2i7ZcJ2kjpltMDZ7Veg== dependencies: "@date-io/dayjs" "^2.16.0" "@emotion/react" "^11.10.4" From 1825a1ec7bbca4c1d4c3f1878788aae90b82068f Mon Sep 17 00:00:00 2001 From: Mailine Nguyen Date: Thu, 20 Mar 2025 07:56:47 +0100 Subject: [PATCH 2/2] fix: missing dependencies in callback --- .../SurveyPageStep/SurveyPageStep.tsx | 92 ++++++++++++------- 1 file changed, 58 insertions(+), 34 deletions(-) diff --git a/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx b/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx index f7be22d1..226afa8d 100644 --- a/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx +++ b/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx @@ -68,11 +68,23 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { const idSurvey = getSurveyIdFromUrl(context, location); const navigate = useNavigate(); + const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; useEffect(() => { setEnviro(context, navigate, callbackHolder); }); + const validateAndNav = ( + forceQuit: boolean, + setIsModalDisplayed: (value: SetStateAction) => void, + ): void => { + if (forceQuit) { + saveAndNav(idSurvey); + } else { + setIsModalDisplayed(true); + } + }; + const navigateHome = useCallback(() => { return navigate(getNavigatePath(EdtRoutesNameEnum.SURVEYED_HOME)); }, []); @@ -118,9 +130,7 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { idSurvey: idSurvey, onNavigateBack: useCallback( () => { - const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; if (!isReviewerMode) { - console.log("saveData"); if (specifiquesProps?.displayModal) { validateAndNav(false, setIsModalDisplayed); } else { @@ -129,11 +139,9 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { } navigateHome(); }, - - [isModalDisplayed], + [isReviewerMode, isModalDisplayed, idSurvey, navigateHome, validateAndNav, saveAndNavLocally], ), onNext: useCallback(() => { - const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; if (!isReviewerMode) { if (specifiquesProps?.displayModal) { validateAndNav(false, setIsModalDisplayed); @@ -141,23 +149,38 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { saveAndNextStep(idSurvey, context.source, EdtRoutesNameEnum.ACTIVITY, currentPage); } } - - }, [isModalDisplayed]), + }, [ + isReviewerMode, + isModalDisplayed, + saveAndNextStep, + validateAndNav, + idSurvey, + context, + currentPage, + ]), onPrevious: useCallback( () => { - const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; if (!isReviewerMode) { - (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNavLocally(idSurvey)) - + backRoute + ? saveAndNavFullPath(idSurvey, backRoute) + : saveAndNavLocally(idSurvey); } navigate( backRoute ? getNavigatePath(backRoute) - : `${getParameterizedNavigatePath(EdtRoutesNameEnum.ACTIVITY, idSurvey)}${getNavigatePath(EdtRoutesNameEnum.ACTIVITY_SUMMARY)}` + : `${getParameterizedNavigatePath( + EdtRoutesNameEnum.ACTIVITY, + idSurvey, + )}${getNavigatePath(EdtRoutesNameEnum.ACTIVITY_SUMMARY)}`, ); }, - - [] + [ + isReviewerMode, + backRoute, + idSurvey, + saveAndNavFullPath, + saveAndNavLocally + ], ), simpleHeader: true, simpleHeaderLabel: t("page.complementary-questions.simple-header-label"), @@ -176,7 +199,6 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { if (!validateButton) { return; } - const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; if (!isReviewerMode) { validateButton(); if (nextRoute) { @@ -185,28 +207,39 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { saveAndNextStep(idSurvey, context.source, context.surveyRootPage, currentPage); } } - - - }, []), + }, [ + isReviewerMode, + nextRoute, + saveAndNavFullPath, + saveAndNextStep, + idSurvey, + context, + currentPage, + ]), icon: errorIcon ? : undefined, onNavigateBack: useCallback(() => { - const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; if (!isReviewerMode) { saveAndNavLocally(idSurvey); } - navigateHome(); - }, []), + }, [isReviewerMode, saveAndNavLocally, idSurvey, navigateHome]), onPrevious: useCallback( () => { - const isReviewerMode = getUserRights() === EdtUserRightsEnum.REVIEWER; if (!isReviewerMode) { - (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNavLocally(idSurvey)) - + backRoute + ? saveAndNavFullPath(idSurvey, backRoute) + : saveAndNavLocally(idSurvey); } navigate(getNavigatePath(backRoute ?? EdtRoutesNameEnum.ACTIVITY)); }, - [] + [ + isReviewerMode, + backRoute, + saveAndNavFullPath, + saveAndNavLocally, + idSurvey, + getNavigatePath, + ], ), firstName: getPrintedFirstName(idSurvey), surveyDate: getPrintedSurveyDate(idSurvey, context.surveyRootPage), @@ -214,16 +247,7 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { modifiable: modifiable, }; - const validateAndNav = ( - forceQuit: boolean, - setIsModalDisplayed: (value: SetStateAction) => void, - ): void => { - if (forceQuit) { - saveAndNav(idSurvey); - } else { - setIsModalDisplayed(true); - } - }; + const surveyPageProps = isStep ? surveyPageStepProps : surveyPageNotStepProps; const surveyData = useMemo(() => getData(idSurvey), [idSurvey]);