Skip to content

Commit

Permalink
fix: delete state data only for the put request
Browse files Browse the repository at this point in the history
  • Loading branch information
MailineN committed Aug 23, 2024
1 parent 524947a commit 2da944b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/pages/home-surveyed/HomeSurveyed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ const HomeSurveyedPage = () => {
setInitialized(true);
});
});

return (
<>
{renderReminderNote()}
Expand All @@ -259,6 +258,7 @@ const HomeSurveyedPage = () => {
const renderHomeInterviewer = () => {
let userDataGroupedInterv = nameSurveyGroupMap();
let groups = Object.keys(userDataGroupedInterv);
console.log("groups", groups);
return (
<>
{renderReminderNote()}
Expand Down
21 changes: 11 additions & 10 deletions src/service/api-service/putRemoteData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ const requestPutSurveyData = (
token?: string,
): Promise<SurveyData> => {
const collectedData = transformCollectedArray(data?.data?.COLLECTED);
const stateData = data.stateData;
if (data.data) {
data.data.COLLECTED = collectedData;
delete data.data.COLLECTED?.WEEKLYPLANNER;
delete data.data.stateData;
}
console.log("requestPutSurveyData", data);
const stateData = data.stateData;
const tempData = { ...data };
delete tempData.data.COLLECTED?.WEEKLYPLANNER;
delete tempData.data.stateData;
console.log("requestPutSurveyData", tempData);
const putLunaticData = axios.put(
`${stromaeBackOfficeApiBaseUrl}api/survey-unit/${idSurvey}/data`,
data.data,
tempData.data,
getHeader(stromaeBackOfficeApiBaseUrl, token),
);

Expand Down Expand Up @@ -68,8 +69,6 @@ const remotePutSurveyDataReviewer = (
stateData: StateData,
data: LunaticData,
): Promise<SurveyData> => {
//Temporar check on token validity to avoid 401 error, if not valid, reload page
//
const now = new Date();
const tokenExpiresAt = jwt<JwtPayload>(getUserToken() ?? "").exp;
// * 1000 because tokenExpiresAt is in seconds and now.getTime() in milliseconds
Expand All @@ -96,13 +95,15 @@ const requestPutDataReviewer = (
): Promise<LunaticData> => {
console.log("requestPutDataReviewer", data);
data.COLLECTED = transformCollectedArray(data?.COLLECTED);
//TODO: Find another solution to avoid ui problem
delete data.COLLECTED?.WEEKLYPLANNER;
const tempData = { ...data };
delete tempData.COLLECTED?.WEEKLYPLANNER;
delete tempData.stateData;
console.log("requestPutSurveyData", tempData);
return new Promise<LunaticData>(resolve => {
axios
.put(
stromaeBackOfficeApiBaseUrl + "api/survey-unit/" + idSurvey + "/data",
data,
tempData,
getHeader(stromaeBackOfficeApiBaseUrl, token),
)
.then(() => {
Expand Down
1 change: 0 additions & 1 deletion src/service/survey-state-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ const validateAllEmptySurveys = (idHousehold: string) => {
};

const value = getValue(idSurvey, FieldNameEnum.FIRSTNAME) as string;

if (value == null || value.length == 0) {
data.stateData = validatedStateData;
promisesToWait.push(saveData(idSurvey, data, false, true, validatedStateData));
Expand Down
5 changes: 3 additions & 2 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ function getSurveyIdFromUrl(context: OrchestratorContext, location: Location) {
}

function addItemToSession(idSurvey: string, item: any) {
console.log("Add item to session", idSurvey, item);
sessionStorage.setItem(idSurvey, JSON.stringify(item));
}

function getItemFromSession(idSurvey: string) {
console.log("getItemFromSession", idSurvey, sessionStorage.getItem(idSurvey));
return JSON.parse(sessionStorage.getItem(idSurvey ?? "") ?? "{}");
const item = JSON.parse(sessionStorage.getItem(idSurvey ?? "") ?? "{}");
return item;
}

function addArrayToSession(nameItem: string, array: any[]) {
Expand Down

0 comments on commit 2da944b

Please sign in to comment.