Skip to content

Commit

Permalink
fix: double save when the user complete a survey
Browse files Browse the repository at this point in the history
  • Loading branch information
MailineN committed Aug 21, 2024
1 parent 09585dc commit 0664096
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
import { isDesktop } from "service/responsive";
import { getActivitiesOrRoutes, surveyReadOnly } from "service/survey-activity-service";
import { getData, getValue, getValueOfData, saveDataLocally } from "service/survey-service";
import { isSurveyCompleted } from "service/survey-state-service";
import { getSurveyIdFromUrl } from "utils/utils";

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

const onClose = (forceQuit: boolean) => {
const isCompleted = isSurveyCompleted(idSurvey);
const isCompleted = getValue(idSurvey, FieldNameEnum.ISCOMPLETED, currentIteration) as boolean;
const isCloture = getValue(idSurvey, FieldNameEnum.ISCLOSED) as boolean;
if (!openSnackbar) {
if (!isCompleted) {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/end-survey/EndSurvey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const EndSurveyPage = () => {
};

const saveDataAndInit = useCallback((surveyData: SurveyData, forceUpdate?: boolean) => {
saveData(idSurvey, surveyData.data, false, forceUpdate).then(() => {
saveData(idSurvey, surveyData, false, forceUpdate).then(() => {
initializeSurveysDatasCache().finally(() => {
setIsModalDisplayed(true);
});
Expand Down Expand Up @@ -112,10 +112,10 @@ const EndSurveyPage = () => {
if (!isDemoMode && navigator.onLine) {
if (isReviewer()) {
return remotePutSurveyDataReviewer(idSurvey, stateData, surveyData.data)
.then(handleSuccess)
.then(navToHome)
.catch(handleError);
} else {
return remotePutSurveyData(idSurvey, surveyData).then(handleSuccess).catch(handleError);
return remotePutSurveyData(idSurvey, surveyData).then(navToHome).catch(handleError);
}
} else {
return saveDataAndInit(surveyData, true);
Expand Down
2 changes: 1 addition & 1 deletion src/service/api-service/putRemoteData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const requestPutDataReviewer = (
): Promise<LunaticData> => {
console.log("requestPutDataReviewer", data);
data.COLLECTED = transformCollectedArray(data?.COLLECTED);
//TODO: Find another solution to avoid ui bug
//TODO: Find another solution to avoid ui problem
delete data.COLLECTED?.WEEKLYPLANNER;
return new Promise<LunaticData>(resolve => {
axios
Expand Down
3 changes: 3 additions & 0 deletions src/service/loop-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ const getCodesSubCategories = (
}
};

//TODO: Fix isCompleted here
const setIfLoopCompleted = (components: LunaticModelComponent[], notFilled: boolean, i: number) => {
return i == components.length && !notFilled;
};
Expand Down Expand Up @@ -635,7 +636,9 @@ const getCurrentLoopPage = (

//TODO: Edit this function to send state data with COMPLETED status instead
const setLoopCompleted = (idSurvey: string, iteration: number | undefined, isCompleted: boolean) => {
console.log("setLoopCompleted ", idSurvey, iteration, isCompleted);
const completed = setValue(idSurvey, FieldNameEnum.ISCOMPLETED, isCompleted, iteration);
console.log("setLoopCompleted -> completed", completed);
if (completed) {
saveData(idSurvey, completed);
}
Expand Down

0 comments on commit 0664096

Please sign in to comment.