Skip to content

Commit

Permalink
fix(clear): fix clear bdd in mode demo
Browse files Browse the repository at this point in the history
  • Loading branch information
lailabjil committed Jul 18, 2023
1 parent e964588 commit 7a2a262
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pages/home-surveyed/HomeSurveyed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import ErrorPage from "pages/error/Error";
import React, { useCallback, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { logout, remotePutSurveyData } from "service/api-service";
import { logout, remotePutSurveyData, remotePutSurveyDataReviewer } from "service/api-service";
import { lunaticDatabase } from "service/lunatic-database";
import {
getNavigatePath,
Expand Down Expand Up @@ -120,6 +120,7 @@ const HomeSurveyedPage = () => {
data: {},
};
promises.push(remotePutSurveyData(idSurvey, surveyData));
promises.push(remotePutSurveyDataReviewer(idSurvey, stateData, {}));
});
Promise.all(promises).then(() => {
lunaticDatabase.clear().then(() => {
Expand All @@ -129,10 +130,13 @@ const HomeSurveyedPage = () => {
}, []);

const resetDemoDataAndReload = useCallback(() => {
const promises: any[] = [];
surveysIds[SurveysIdsEnum.ALL_SURVEYS_IDS].forEach(idSurvey => {
saveData(idSurvey, {});
promises.push(saveData(idSurvey, {}));
});
Promise.all(promises).then(data => {

Check warning on line 137 in src/pages/home-surveyed/HomeSurveyed.tsx

View workflow job for this annotation

GitHub Actions / test_lint

'data' is defined but never used

Check warning on line 137 in src/pages/home-surveyed/HomeSurveyed.tsx

View workflow job for this annotation

GitHub Actions / test_lint

'data' is defined but never used
window.location.replace(process.env.REACT_APP_PUBLIC_URL || "");
});
window.location.replace(process.env.REACT_APP_PUBLIC_URL || "");
}, []);

const navWorkTime = useCallback(
Expand Down
7 changes: 7 additions & 0 deletions src/service/survey-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,13 @@ const saveData = (idSurvey: string, data: LunaticData, localSaveOnly = false): P
//We ignore the error because user is stuck on EndSurveyPage if he couldn't submit in any moment his survey.
}),
);
} else if (isDemoMode || localSaveOnly) {
promisesToWait.push(
new Promise(resolve => {
setLocalDatabase(getSurveyStateData(data, idSurvey), data, idSurvey);
resolve(data);
}),
);
}
}
return new Promise(resolve => {
Expand Down

0 comments on commit 7a2a262

Please sign in to comment.