Skip to content

Commit

Permalink
fix: lunatic-edt alert component
Browse files Browse the repository at this point in the history
  • Loading branch information
MailineN committed Aug 6, 2024
1 parent 7afc7d0 commit 9447a33
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/orchestrator/Orchestrator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export const OrchestratorForStories = (props: OrchestratorProps) => {
source,
),
);
console.log("Value", value);
return (
<div className="lunatic lunatic-component" key={`component-${id}`}>
<Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import {
getSurveyRights,
refreshSurvey,
saveData,
saveDataLocally,
setValue,
} from "service/survey-service";
import { isDemoMode, isSurveyLocked, lockSurvey } from "service/survey-state-service";
Expand Down Expand Up @@ -692,7 +691,7 @@ const ActivityOrRoutePlannerPage = () => {
>
<Box id="inner-content-scroll" className={classes.innerContentScroll}>
<FlexCenter>
{/* <Alert
<Alert
isAlertDisplayed={isAlertDisplayed}
onCompleteCallBack={closeActivity(true, idSurvey)}
onCancelCallBack={displayAlert(setIsAlertDisplayed, false)}
Expand All @@ -702,7 +701,7 @@ const ActivityOrRoutePlannerPage = () => {
aria-label={t("page.alert-when-quit.alt-alert-icon")}
/>
}
></Alert> */}
></Alert>
<Box
className={getClassCondition(
isReviewerMode() && activitiesRoutesOrGaps.length !== 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
onNext,
onPrevious,
saveAndLoopNavigate,
saveAndLoopNavigateLocally,
setEnviro,
validateLocally,
} from "service/navigation-service";
Expand Down
4 changes: 2 additions & 2 deletions src/pages/activity/activity-summary/ActivitySummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ const ActivitySummaryPage = () => {
{activitiesRoutesOrGaps.length !== 0 &&
(isReviewerMode ? (
<Box className={classes.headerActivityLockBox}>
{/* <Alert
<Alert
isAlertDisplayed={isAlertLockDisplayed}
onCompleteCallBack={lock}
onCancelCallBack={displayAlert(setIsAlertLockDisplayed, false)}
Expand All @@ -532,7 +532,7 @@ const ActivitySummaryPage = () => {
aria-label={t("page.alert-when-quit.alt-alert-icon")}
/>
}
></Alert> */}
></Alert>
<Box className={classes.headerActivityBox}>
<Typography className={classes.label}>
{t("page.activity-planner.activity-for-day")}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home-surveyed/HomeSurveyed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ const HomeSurveyedPage = () => {

return (
<>
{/* <FlexCenter>
<FlexCenter>
<Alert {...alertProps} />
</FlexCenter> */}
</FlexCenter>
<Box className={classes.headerBox}>
{isReviewer ? (
<Box className={classes.reviewerButtonBox}>
Expand Down
58 changes: 57 additions & 1 deletion src/service/api-service/getRemoteData.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import axios from "axios";
import { ErrorCodeEnum } from "enumerations/ErrorCodeEnum";
import { StateData, SurveyData, UserSurveys } from "interface/entity/Api";
import { LunaticData, SourceData } from "interface/lunatic/Lunatic";
import { LunaticData, ReferentielData, SourceData } from "interface/lunatic/Lunatic";
import { initStateData, initSurveyData } from "../survey-service";
import { getUserToken, isReviewer } from "../user-service";
import { AuthContextProps } from "oidc-react";
import { NomenclatureActivityOption } from "@inseefrlab/lunatic-edt";
import { ReferentielsEnum } from "enumerations/ReferentielsEnum";

export const edtOrganisationApiBaseUrl = process.env.REACT_APP_EDT_ORGANISATION_API_BASE_URL;
export const stromaeBackOfficeApiBaseUrl = process.env.REACT_APP_STROMAE_BACK_OFFICE_API_BASE_URL;
Expand Down Expand Up @@ -31,6 +34,57 @@ export const getHeader = (origin?: string, userToken?: string) => {
};
};

const fetchRemoteReferentiel = (auth: AuthContextProps, idReferentiel: ReferentielsEnum) => {
return axios.get<NomenclatureActivityOption[]>(
stromaeBackOfficeApiBaseUrl + "api/nomenclature/" + idReferentiel,
getHeader(stromaeBackOfficeApiBaseUrl),
);
};

const fetchRemoteReferentiels = (setError: (error: ErrorCodeEnum) => void): Promise<ReferentielData> => {
let refs: ReferentielData = {
[ReferentielsEnum.ACTIVITYNOMENCLATURE]: [],
[ReferentielsEnum.ACTIVITYAUTOCOMPLETE]: [],
[ReferentielsEnum.ROUTE]: [],
[ReferentielsEnum.MEANOFTRANSPORT]: [],
[ReferentielsEnum.ACTIVITYSECONDARYACTIVITY]: [],
[ReferentielsEnum.ROUTESECONDARYACTIVITY]: [],
[ReferentielsEnum.LOCATION]: [],
[ReferentielsEnum.KINDOFWEEK]: [],
[ReferentielsEnum.KINDOFDAY]: [],
[ReferentielsEnum.ACTIVITYGOAL]: [],
};
let refsEndPoints: string[] = [];
Object.values(ReferentielsEnum).forEach(value => {
refsEndPoints.push("api/nomenclature/" + value);
});

return new Promise(resolve => {
axios
.all(
refsEndPoints.map(endPoint =>
axios.get(
stromaeBackOfficeApiBaseUrl + endPoint,
getHeader(stromaeBackOfficeApiBaseUrl),
),
),
)
.then(res => {
Object.values(ReferentielsEnum).forEach((key, index) => {
refs[key as ReferentielsEnum] = res[index].data;
});
resolve(refs);
})
.catch(err => {
if (err.response?.status === 403) {
setError(ErrorCodeEnum.NO_RIGHTS);
} else {
setError(ErrorCodeEnum.UNREACHABLE_NOMENCLATURES);
}
});
});
};

const revertTransformedArray = (dataAct: any) => {
const revertedDataAct: { [key: string]: any } = {};
Object.keys(dataAct).forEach(key => {
Expand Down Expand Up @@ -240,6 +294,8 @@ const remoteGetSurveyDataReviewer = (
};

export {
fetchRemoteReferentiel,
fetchRemoteReferentiels,
fetchReviewerSurveysAssignments,
fetchSurveysSourcesByIds,
fetchUserSurveysInfo,
Expand Down
10 changes: 6 additions & 4 deletions src/service/survey-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ const NUM_MAX_WORKTIME_SURVEYS = 3;

let referentielsData: ReferentielData;
let sourcesData: SourceData;
let surveysIds: SurveysIds;
let surveysIds: SurveysIds = {
[SurveysIdsEnum.ALL_SURVEYS_IDS]: [],
[SurveysIdsEnum.ACTIVITY_SURVEYS_IDS]: [],
[SurveysIdsEnum.WORK_TIME_SURVEYS_IDS]: [],
};
let userDatasActivity: UserSurveys[] = [];
let userDatasWorkTime: UserSurveys[] = [];
let userDatas: UserSurveys[] = [];
Expand Down Expand Up @@ -175,7 +179,6 @@ const initializeRefs = () => {
return lunaticDatabase.get(REFERENTIELS_ID).then(refData => {
if (!refData && navigator.onLine) {
return fetchReferentiels().then(refs => {
console.log("refs", refs);
return saveReferentiels(refs);
});
} else {
Expand Down Expand Up @@ -797,7 +800,7 @@ const dataIsChange = (idSurvey: string, dataAct: LunaticData, lastData: LunaticD
if (!dataCollected || !currentDataCollected) {
return true;
}
console.log("dataIsChange", !_.isEqual(dataCollected, currentDataCollected));
//console.log("dataIsChange", !_.isEqual(dataCollected, currentDataCollected));
return !_.isEqual(dataCollected, currentDataCollected);
};

Expand Down Expand Up @@ -967,7 +970,6 @@ const saveData = (
forceUpdate = false,
stateDataForced?: StateData,
): Promise<LunaticData> => {
console.log("saveData");
data.lastLocalSaveDate = navigator.onLine ? Date.now() : Date.now() + 1;
if (!data.houseReference) {
const regexp = new RegExp(process.env.REACT_APP_HOUSE_REFERENCE_REGULAR_EXPRESSION || "");
Expand Down

0 comments on commit 9447a33

Please sign in to comment.