Skip to content

Commit

Permalink
fix: remove put request at each step of activity
Browse files Browse the repository at this point in the history
  • Loading branch information
MailineN committed Jul 8, 2024
1 parent a5f40c7 commit 9b57448
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getOrchestratorPage,
saveAndNav,
saveAndNavFullPath,
saveAndNavLocally,
saveAndNextStep,
setEnviro,
validateAndNextStep,
Expand Down Expand Up @@ -106,7 +107,7 @@ const SurveyPageStep = (props: SurveyPageStepProps) => {
() =>
specifiquesProps?.displayModal
? validateAndNav(false, setIsModalDisplayed)
: saveAndNav(idSurvey),
: saveAndNavLocally(idSurvey),
[isModalDisplayed],
),
onNext: useCallback(
Expand All @@ -117,7 +118,7 @@ const SurveyPageStep = (props: SurveyPageStepProps) => {
[isModalDisplayed],
),
onPrevious: useCallback(
() => (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNav(idSurvey)),
() => (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNavLocally(idSurvey)),
[],
),
simpleHeader: true,
Expand All @@ -143,9 +144,9 @@ const SurveyPageStep = (props: SurveyPageStepProps) => {
[],
),
icon: errorIcon ? <IconError aria-label={t(errorAltIcon ?? "")} /> : undefined,
onNavigateBack: useCallback(() => saveAndNav(idSurvey), []),
onNavigateBack: useCallback(() => saveAndNavLocally(idSurvey), []),
onPrevious: useCallback(
() => (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNav(idSurvey)),
() => (backRoute ? saveAndNavFullPath(idSurvey, backRoute) : saveAndNavLocally(idSurvey)),
[],
),
firstName: getPrintedFirstName(idSurvey),
Expand All @@ -168,13 +169,14 @@ const SurveyPageStep = (props: SurveyPageStepProps) => {
forceQuit: boolean,
setIsModalDisplayed: (value: SetStateAction<boolean>) => void,
): void => {
console.log("validateAndNav");
if (forceQuit) {
saveAndNav(idSurvey);
} else {
setIsModalDisplayed(true);
}
};

console.log("SurveyPageStep,", isStep);
const surveyPageProps = isStep ? surveyPageStepProps : surveyPageNotStepProps;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import {
lockSurvey,
refreshSurvey,
saveData,
saveDataLocally,
setValue,
surveyLocked,
} from "service/survey-service";
Expand Down Expand Up @@ -165,6 +166,7 @@ const onFinish = (
) => {
if (closed) {
const data = setValue(idSurvey, FieldNameEnum.ISCLOSED, true);
console.log("Save data on closed");
saveData(idSurvey, data ?? callbackHolder.getData(), false, true).then(() => {
navigate(
getCurrentNavigatePath(
Expand Down Expand Up @@ -435,7 +437,8 @@ const ActivityOrRoutePlannerPage = () => {
contextIteration = loopSize - 1;
const routeData = setValue(idSurvey, FieldNameEnum.ISROUTE, isRouteBool, contextIteration);
console.log(routeData, isRouteBool);
saveData(idSurvey, routeData).then(() => {
saveDataLocally(idSurvey, routeData).then(() => {
console.log("Save Data on Add Activity or Route");
navToActivityOrRoute(idSurvey, contextIteration, isRouteBool);
});
};
Expand All @@ -455,7 +458,8 @@ const ActivityOrRoutePlannerPage = () => {
setValueOrNull(idSurvey, FieldNameEnum.START_TIME, startTime, contextIteration);
setValueOrNull(idSurvey, FieldNameEnum.END_TIME, endTime, contextIteration);
const updatedData = setValue(idSurvey, FieldNameEnum.ISROUTE, isRouteBool, contextIteration);
saveData(idSurvey, updatedData).then(() => {
saveDataLocally(idSurvey, updatedData).then(() => {
console.log("Save Data on Add Activity or Route from Gap");
onCloseAddActivityOrRoute();
setIsRoute(isRouteBool);
navigate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from "service/navigation-service";
import { isDesktop } from "service/responsive";
import { getActivitiesOrRoutes, surveyReadOnly } from "service/survey-activity-service";
import { getData, getValue, getValueOfData, saveData } from "service/survey-service";
import { getData, getValue, getValueOfData, saveDataLocally } from "service/survey-service";
import { getSurveyIdFromUrl } from "utils/utils";

const ActivityDurationPage = () => {
Expand Down Expand Up @@ -150,7 +150,7 @@ const ActivityDurationPage = () => {
}

if ((skip && isAfter) || !isAfter) {
saveData(idSurvey, callbackHolder.getData()).then(() => {
saveDataLocally(idSurvey, callbackHolder.getData()).then(() => {
navigate(
getLoopParameterizedNavigatePath(
idSurvey,
Expand All @@ -177,7 +177,7 @@ const ActivityDurationPage = () => {
if (!openSnackbar) {
if (!isCompleted) {
if (forceQuit) {
saveData(idSurvey, callbackHolder.getData()).then(() => {
saveDataLocally(idSurvey, callbackHolder.getData()).then(() => {
navIsClompleted(isCloture);
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
onClose,
onNext,
onPrevious,
saveAndLoopNavigate,
saveAndLoopNavigateLocally,
setEnviro,
validate,
} from "service/navigation-service";
Expand Down Expand Up @@ -119,7 +119,7 @@ const MainActivityPage = () => {
backClickEvent: backClickEvent,
nextClickEvent: nextClickEvent,
backClickCallback: () => {
saveAndLoopNavigate(
saveAndLoopNavigateLocally(
idSurvey,
context.source,
getPreviousLoopPage(currentPage),
Expand All @@ -131,7 +131,7 @@ const MainActivityPage = () => {
const codeActivity = getValueOfActivity(callbackHolder.getData(), currentIteration) ?? "";
const skip = filtrePage(EdtRoutesNameEnum.MAIN_ACTIVITY_GOAL, codeActivity);
if (routeToGoal && !skip) {
saveAndLoopNavigate(
saveAndLoopNavigateLocally(
idSurvey,
context.source,
EdtRoutesNameEnum.MAIN_ACTIVITY_GOAL,
Expand All @@ -140,7 +140,7 @@ const MainActivityPage = () => {
);
} else {
const skip = filtrePage(EdtRoutesNameEnum.SECONDARY_ACTIVITY, codeActivity);
saveAndLoopNavigate(
saveAndLoopNavigateLocally(
idSurvey,
context.source,
skip ? EdtRoutesNameEnum.ACTIVITY_LOCATION : getNextLoopPage(currentPage),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
onClose,
onNext,
onPrevious,
saveAndLoopNavigate,
saveAndNav,
saveAndLoopNavigateLocally,
saveAndNavLocally,
setEnviro,
validate,
} from "service/navigation-service";
Expand Down Expand Up @@ -54,7 +54,7 @@ const WithScreenPage = () => {
backClickEvent: backClickEvent,
nextClickEvent: nextClickEvent,
backClickCallback: () => {
saveAndLoopNavigate(
saveAndLoopNavigateLocally(
idSurvey,
context.source,
EdtRoutesNameEnum.WITH_SOMEONE_SELECTION,
Expand All @@ -65,7 +65,7 @@ const WithScreenPage = () => {
);
},
nextClickCallback: () => {
saveAndNav(
saveAndNavLocally(
idSurvey,
isCloture
? summaryRoutePath
Expand All @@ -79,7 +79,7 @@ const WithScreenPage = () => {
},
onSelectValue: () => {
validate(idSurvey).then(() => {
saveAndNav(
saveAndNavLocally(
idSurvey,
isCloture
? summaryRoutePath
Expand Down
4 changes: 2 additions & 2 deletions src/pages/activity/help/HelpWorkTime/HelpWorkTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
getPrintedFirstName,
getSource,
getSurveyDate,
saveData,
saveDataLocally,
} from "service/survey-service";

const HelpWorkTime = () => {
Expand Down Expand Up @@ -101,7 +101,7 @@ const HelpWorkTime = () => {
dates: "DATES",
datesStarted: "DATES_STARTED",
},
saveAll: () => saveData(idSurvey, data),
saveAll: () => saveDataLocally(idSurvey, data),
language: getLanguage(),
helpStep: helpStep,
moreIcon: <MoreHorizontalIcon aria-label={t("accessibility.asset.mui-icon.more-horizontal")} />,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/activity/phone-time/PhoneTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getNavigatePath,
getOrchestratorPage,
getParameterizedNavigatePath,
saveAndNav,
saveAndNavLocally,
saveAndNavFullPath,
setEnviro,
validateAndNextStep,
Expand All @@ -34,10 +34,10 @@ const PhoneTimePage = () => {

const surveyPageStepProps = {
idSurvey: idSurvey,
onNavigateBack: useCallback(() => saveAndNav(idSurvey), []),
onNavigateBack: useCallback(() => saveAndNavLocally(idSurvey), []),
onNext: useCallback(
() =>
saveAndNav(
saveAndNavLocally(
idSurvey,
getParameterizedNavigatePath(EdtRoutesNameEnum.ACTIVITY, idSurvey) +
getNavigatePath(EdtRoutesNameEnum.END_SURVEY),
Expand Down
2 changes: 1 addition & 1 deletion src/service/api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const requestPutSurveyData = (
data: SurveyData,
token?: string,
): Promise<SurveyData> => {
console.log("data", data);
//console.log("data", data);
const collectedData = token ? transformCollectedArray(data.data?.COLLECTED) : data.data?.COLLECTED;
if (data.data) {
data.data.COLLECTED = collectedData;
Expand Down
16 changes: 8 additions & 8 deletions src/service/loop-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
getValue,
getValueOfData,
getVariable,
saveData,
saveDataLocally,
setValue,
toIgnoreForActivity,
toIgnoreForRoute,
Expand All @@ -39,8 +39,8 @@ import {
getCurrentNavigatePath,
getLoopPage,
getOrchestratorPage,
saveAndLoopNavigate,
saveAndNav,
saveAndLoopNavigateLocally,
saveAndNavLocally,
} from "./navigation-service";
import { getNomenclatureRef } from "./referentiel-service";

Expand Down Expand Up @@ -353,7 +353,7 @@ const skipNextPage = (
nextPageRoute == EdtRoutesNameEnum.ACTIVITY_OR_ROUTE_PLANNER ||
(nextPageRoute == null && nextPageNextLoop == EdtRoutesNameEnum.ACTIVITY_OR_ROUTE_PLANNER)
) {
saveAndNav(
saveAndNavLocally(
idSurvey,
getCurrentNavigatePath(
idSurvey,
Expand All @@ -363,7 +363,7 @@ const skipNextPage = (
),
);
} else {
saveAndLoopNavigate(
saveAndLoopNavigateLocally(
idSurvey,
source,
nextPageRoute ?? nextPageNextLoop,
Expand Down Expand Up @@ -405,7 +405,7 @@ const skipBackPage = (
backPageRoute == EdtRoutesNameEnum.ACTIVITY_OR_ROUTE_PLANNER ||
backPageBackLoop == EdtRoutesNameEnum.ACTIVITY_OR_ROUTE_PLANNER
) {
saveAndNav(
saveAndNavLocally(
idSurvey,
getCurrentNavigatePath(
idSurvey,
Expand All @@ -415,7 +415,7 @@ const skipBackPage = (
),
);
} else {
saveAndLoopNavigate(
saveAndLoopNavigateLocally(
idSurvey,
source,
backPageRoute ?? backPageBackLoop,
Expand Down Expand Up @@ -633,7 +633,7 @@ const getCurrentLoopPage = (
const setLoopCompleted = (idSurvey: string, iteration: number | undefined, isCompleted: boolean) => {
const completed = setValue(idSurvey, FieldNameEnum.ISCOMPLETED, isCompleted, iteration);
if (completed) {
saveData(idSurvey, completed);
saveDataLocally(idSurvey, completed);
}
};

Expand Down
Loading

0 comments on commit 9b57448

Please sign in to comment.