diff --git a/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx b/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx index f8e2e08f..b521418f 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; @@ -63,11 +68,27 @@ 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)); + }, []); + const { classes, cx } = useStyles({ "isMobile": !isPwa(), "isIOS": isIOS, @@ -108,22 +129,58 @@ 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), - [isModalDisplayed], + () => { + if (!isReviewerMode) { + if (specifiquesProps?.displayModal) { + validateAndNav(false, setIsModalDisplayed); + } else { + saveAndNavLocally(idSurvey); + } + } + navigateHome(); + }, + [isReviewerMode, isModalDisplayed, idSurvey, navigateHome, validateAndNav, saveAndNavLocally], ), + onNext: useCallback(() => { + if (!isReviewerMode) { + if (specifiquesProps?.displayModal) { + validateAndNav(false, setIsModalDisplayed); + } else { + saveAndNextStep(idSurvey, context.source, EdtRoutesNameEnum.ACTIVITY, currentPage); + } + } + }, [ + isReviewerMode, + isModalDisplayed, + saveAndNextStep, + validateAndNav, + idSurvey, + context, + currentPage, + ]), onPrevious: useCallback( - () => (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNavLocally(idSurvey)), - [], + () => { + if (!isReviewerMode) { + backRoute + ? saveAndNavFullPath(idSurvey, backRoute) + : saveAndNavLocally(idSurvey); + } + navigate( + backRoute + ? getNavigatePath(backRoute) + : `${getParameterizedNavigatePath( + EdtRoutesNameEnum.ACTIVITY, + idSurvey, + )}${getNavigatePath(EdtRoutesNameEnum.ACTIVITY_SUMMARY)}`, + ); + }, + [ + isReviewerMode, + backRoute, + idSurvey, + saveAndNavFullPath, + saveAndNavLocally + ], ), simpleHeader: true, simpleHeaderLabel: t("page.complementary-questions.simple-header-label"), @@ -142,18 +199,47 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { if (!validateButton) { return; } - validateButton(); - if (nextRoute) { - saveAndNavFullPath(idSurvey, nextRoute); - } else { - saveAndNextStep(idSurvey, context.source, context.surveyRootPage, currentPage); + if (!isReviewerMode) { + validateButton(); + if (nextRoute) { + saveAndNavFullPath(idSurvey, nextRoute); + } else { + saveAndNextStep(idSurvey, context.source, context.surveyRootPage, currentPage); + } } - }, []), + }, [ + isReviewerMode, + nextRoute, + saveAndNavFullPath, + saveAndNextStep, + idSurvey, + context, + currentPage, + ]), icon: errorIcon ? : undefined, - onNavigateBack: useCallback(() => saveAndNavLocally(idSurvey), []), + onNavigateBack: useCallback(() => { + if (!isReviewerMode) { + saveAndNavLocally(idSurvey); + } + navigateHome(); + }, [isReviewerMode, saveAndNavLocally, idSurvey, navigateHome]), onPrevious: useCallback( - () => (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNavLocally(idSurvey)), - [], + () => { + if (!isReviewerMode) { + 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), @@ -161,16 +247,6 @@ 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]); 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 (