Skip to content

Commit

Permalink
fix: double request that lead to init data in reviewer mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MailineN committed Aug 26, 2024
1 parent 2da944b commit 8bab513
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
21 changes: 12 additions & 9 deletions src/pages/home-surveyed/HomeSurveyed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
surveysIds,
userDatasMap,
initializeDatas,
createNameSurveyMap,
} from "service/survey-service";
import { isDemoMode, lockAllSurveys, validateAllEmptySurveys } from "service/survey-state-service";
import { getUserRights } from "service/user-service";
Expand All @@ -72,14 +73,16 @@ const HomeSurveyedPage = () => {

const initHome = (idsSurveysSelected: string[]) => {
initializeHomeSurveys(idHousehold ?? "").then(() => {
initializeSurveysDatasCache(idsSurveysSelected).finally(() => {
userDatas = userDatasMap();
if (getData(idsSurveysSelected[0]) != undefined) {
setState(getData(idsSurveysSelected[0]));
setInitialized(true);
}
setDatas(userDatas);
});
// initializeSurveysDatasCache(idsSurveysSelected).finally(() => {

// });

userDatas = userDatasMap();
if (getData(idsSurveysSelected[0]) != undefined) {
setState(getData(idsSurveysSelected[0]));
setInitialized(true);
}
setDatas(userDatas);
});
};

Expand Down Expand Up @@ -258,7 +261,6 @@ const HomeSurveyedPage = () => {
const renderHomeInterviewer = () => {
let userDataGroupedInterv = nameSurveyGroupMap();
let groups = Object.keys(userDataGroupedInterv);
console.log("groups", groups);
return (
<>
{renderReminderNote()}
Expand Down Expand Up @@ -310,6 +312,7 @@ const HomeSurveyedPage = () => {

const renderHomeReviewer = () => {
let userDatas = groupBy(userDatasMap(), nameSurveyData => nameSurveyData.num);
console.log("userDatas", userDatas);
let groups = Object.keys(userDatas);
return renderPageOrLoadingOrError(
<ErrorBoundary FallbackComponent={ErrorProvider}>
Expand Down
18 changes: 18 additions & 0 deletions src/service/api-service/getRemoteData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ const remoteGetSurveyStateData = (
});
});
};
const remoteGetSurveyDataSurveyed = (
idSurvey: string,
setError: (error: ErrorCodeEnum) => void,
): Promise<SurveyData> => {
return remoteGetSurveyData(idSurvey, setError).then(data => {
return remoteGetSurveyStateData(idSurvey, setError).then((stateData: StateData) => {
return new Promise(resolve => {
const surveyData: SurveyData = {
stateData: stateData,
data: data,
};
resolve(surveyData);
});
});
});
};

const requestGetDataReviewer = (
idSurvey: string,
Expand Down Expand Up @@ -325,6 +341,8 @@ export {
fetchSurveysSourcesByIds,
fetchUserSurveysInfo,
remoteGetSurveyData,
requestGetDataReviewer,
remoteGetSurveyStateData,
remoteGetSurveyDataReviewer,
remoteGetSurveyDataSurveyed,
};
8 changes: 6 additions & 2 deletions src/service/survey-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ import {
} from "interface/lunatic/Lunatic";
import { AuthContextProps } from "oidc-react";
import { NavigateFunction } from "react-router-dom";
import { fetchReviewerSurveysAssignments } from "service/api-service/getRemoteData";
import {
fetchReviewerSurveysAssignments,
requestGetDataReviewer,
} from "service/api-service/getRemoteData";
import { lunaticDatabase } from "service/lunatic-database";
import { LABEL_WORK_TIME_SURVEY, getCurrentPageSource } from "service/orchestrator-service";
import {
Expand Down Expand Up @@ -533,7 +536,7 @@ const getRemoteSavedSurveyData = (
return Promise.reject(new Error("Offline"));
}

const urlRemote = isReviewer() ? remoteGetSurveyDataReviewer : remoteGetSurveyData;
const urlRemote = isReviewer() ? requestGetDataReviewer : remoteGetSurveyData;

return urlRemote(surveyId, setError)
.then((remoteSurveyData: any) => {
Expand Down Expand Up @@ -1696,6 +1699,7 @@ export {
addToAutocompleteActivityReferentiel,
arrayOfSurveysPersonDemo,
createDataEmpty,
createNameSurveyMap,
existVariableEdited,
getAuthCache,
getComponentId,
Expand Down

0 comments on commit 8bab513

Please sign in to comment.