Skip to content

Commit

Permalink
Merge pull request #47 from InseeFrLab/feat/sprint20
Browse files Browse the repository at this point in the history
Feat/sprint20
  • Loading branch information
MichaelC67 authored Apr 12, 2024
2 parents 44200f1 + 26c556f commit 7ee9ad6
Show file tree
Hide file tree
Showing 22 changed files with 589 additions and 302 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "edt",
"version": "3.13.2",
"dateVersion": "05/03/2024",
"version": "3.14.12",
"dateVersion": "11/04/2024",
"licence": "MIT",
"dependencies": {
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@inseefr/lunatic": "2.0.7-v2",
"@inseefrlab/lunatic-edt": "^0.12.3",
"@inseefrlab/lunatic-edt": "0.12.4",
"@mui/material": "^5.10.7",
"@mui/styles": "^5.12.0",
"@react-pdf/font": "2.2.0",
Expand Down
5 changes: 3 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"icons": [
{
"src": "favicon.ico",
"sizes": "48x48 32x32 16x16",
"sizes": "32x32 16x16",
"type": "image/x-icon"
},
{
Expand Down Expand Up @@ -219,5 +219,6 @@
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
"background_color": "#ffffff",
"prefer_related_applications": true
}
71 changes: 61 additions & 10 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import LoadingFull from "components/commons/LoadingFull/LoadingFull";
import { EdtUserRightsEnum } from "enumerations/EdtUserRightsEnum";
import { ErrorCodeEnum } from "enumerations/ErrorCodeEnum";
import "i18n/i18n";
import { useAuth } from "oidc-react";
import { User, useAuth } from "oidc-react";
import ErrorPage from "pages/error/Error";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { EdtRoutes } from "routes/EdtRoutes";
import { getDatas, initializeDatas, initializeListSurveys } from "service/survey-service";
import {
getAuthCache,
getDatas,
initPropsAuth,
initializeDatas,
initializeListSurveys,
} from "service/survey-service";
import { getUserRights, setAuth, setUser, setUserToken } from "service/user-service";
import { getCookie } from "utils/utils";

const App = () => {
const { t } = useTranslation();
const [initialized, setInitialized] = useState(false);
Expand All @@ -28,6 +35,7 @@ const App = () => {
setError(ErrorCodeEnum.COMMON);
}
};
const promisesToWait: Promise<any>[] = [];

useEffect(() => {
if (
Expand All @@ -38,7 +46,6 @@ const App = () => {
localStorage.setItem("setauth", "yes");
window.location.search = "";
}

if (auth?.userData?.access_token && getDatas().size === 0 && error === undefined) {
setUserToken(auth.userData?.access_token);
setUser(auth.userData);
Expand Down Expand Up @@ -70,15 +77,59 @@ const App = () => {
}
});

initializeDatas(setError).then(() => {
setInitialized(true);
});

if (getUserRights() === EdtUserRightsEnum.REVIEWER) {
initializeListSurveys(setError).then(() => {
//auth.userManager.startSilentRenew();
promisesToWait.push(
initializeDatas(setError).then(() => {
setInitialized(true);
});
return initPropsAuth(auth).then(() => {
setInitialized(true);
});
}),
);

if (getUserRights() === EdtUserRightsEnum.REVIEWER && navigator.onLine) {
promisesToWait.push(
initializeListSurveys(setError).then(() => {
setInitialized(true);
}),
);
}
Promise.all(promisesToWait);
} else if (!navigator.onLine) {
getAuthCache().then(auth => {
console.log(auth);
if (auth?.data.userData?.access_token) {
const user: User = {
access_token: auth.data.userData?.access_token,
expires_at: auth.data.userData?.expires_at,
id_token: auth.data.userData?.id_token,
profile: auth.data.userData?.profile,
refresh_token: auth.data.userData?.refresh_token,
scope: auth.data.userData?.scope,
session_state: auth.data.userData?.session_state ?? "",
token_type: auth.data.userData?.token_type ?? "",
state: auth.data.userData.state,
expires_in: auth.data.userData.expires_in,
expired: auth.data.userData.expired,
scopes: auth.data.userData.scopes ?? [],
toStorageString: () => "",
};
setUserToken(auth.data.userData?.access_token);
setUser(user);
}

promisesToWait.push(
initializeDatas(setError).then(() => {
if (getUserRights() === EdtUserRightsEnum.REVIEWER) {
return initializeListSurveys(setError).then(() => {
setInitialized(true);
});
} else setInitialized(true);
}),
);

Promise.all(promisesToWait);
});
}
}, [auth]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ const LoopSurveyPageStep = (props: LoopSurveyPageStepProps) => {
);
},
labels: getLabels(labelOfPage),
errorIcon: IconError,
errorIcon: (
<IconError aria-label={t("component.activity-selecter.clickable-list-icon-no-result-alt")} />
),
onSelectValue: () => {
validate(idSurvey).then(() => {
skipNextPage(
Expand Down
35 changes: 32 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,49 @@ const oidcConfigSSO = {
userManager: createUserManager(),
};

const oidcConfig = {
const currentHost = `${window.location.protocol}//${window.location.hostname}`;

const oidcConfigOnline = {
onSignIn: () => {
//to remove keycloak params in url
window.history.replaceState(null, "", window.location.pathname);
},
authority: getAuthority(),
clientId: process.env.REACT_APP_KEYCLOAK_CLIENT_ID,
redirectUri: process.env.REACT_APP_KEYCLOAK_REDIRECT_URI,
automaticSilentRenew: !navigator.onLine,
};

const oidcConfigOffline = {
automaticSilentRenew: !navigator.onLine,
silent_redirect_uri: currentHost,
};

const oidcProps = isSSO ? Object.assign(oidcConfig, oidcConfigSSO) : oidcConfig;
let oidcPropss = {};

if (navigator.onLine) {
console.log("nav online");
if (isSSO) {
console.log("isSSO");
oidcPropss = Object.assign(oidcConfigOnline, oidcConfigSSO);
} else {
oidcPropss = oidcConfigOnline;
}
} else {
console.log("nav offline");
oidcPropss = oidcConfigOnline;
}

const oidcProps = navigator.onLine
? isSSO
? Object.assign(oidcConfigOnline, oidcConfigSSO)
: oidcConfigOnline
: oidcConfigOffline;

console.log(navigator.onLine, oidcProps, oidcPropss);

root.render(
<AuthProvider {...oidcProps}>
<AuthProvider {...oidcPropss}>
<React.StrictMode>
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
Expand Down
22 changes: 22 additions & 0 deletions src/interface/lunatic/Lunatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const REFERENTIELS_ID = "referentiels";
export const SOURCES_MODELS = "sources";
export const SURVEYS_IDS = "surveysIds";
export const USER_SURVEYS_DATA = "userSurveysData";
export const DATA_STATE = "dataState";

export interface Collected {
COLLECTED: string | boolean | null;
Expand Down Expand Up @@ -72,6 +73,27 @@ export interface UserSurveysData extends LunaticData {
data: UserSurveys[];
}

export interface DataState extends LunaticData {
data: {
userData: AuthData | undefined;
};
}

export interface AuthData {
access_token?: string;
expires_at?: number;
id_token?: string;
profile?: any;
refresh_token?: string;
scope?: string;
session_state?: string;
token_type?: string;
state?: any;
expires_in?: number;
expired?: boolean;
scopes?: string[];
}

export interface LunaticModel {
variables: LunaticModelVariable[];
components: LunaticModelComponent[];
Expand Down
3 changes: 0 additions & 3 deletions src/pages/activity/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ const ActivityPage = () => {
if (idSurvey && source) {
navToActivityOrPlannerOrSummary(idSurvey, source.maxPage, navigate, source);
} else {
console.error(
`Activité - Erreur recuperation du idSurvey: ${idSurvey} et source: ${source}`,
);
navigate(getParameterizedNavigatePath(EdtRoutesNameEnum.ERROR, ErrorCodeEnum.COMMON));
}
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,24 +594,25 @@ const ActivityOrRoutePlannerPage = () => {
const onDeleteActivity = useCallback(
(idSurvey: string, source: LunaticModel, iteration: number) => () =>
onDeleteActivityOrRoute(idSurvey, source, iteration),
[],
[idSurvey],
);

const onAddActivity = useCallback(
(idSurvey: string, isRoute: boolean) => () => onAddActivityOrRoute(isRoute, idSurvey),
[],
[idSurvey],
);

const onAddActivityGap = useCallback(
(idSurvey: string, isRoute: boolean, startTime?: string, endTime?: string) => () =>
onAddActivityOrRouteFromGap(idSurvey, isRoute, startTime, endTime),
[],
[idSurvey],
);

const navToCard = useCallback(
(iteration: number, isRoute?: boolean) => () =>
navToActivityOrRoute(idSurvey, iteration, isRoute),
[],
(iteration: number, isRoute?: boolean) => () => {
navToActivityOrRoute(idSurvey, iteration, isRoute);
},
[idSurvey],
);

const closeActivity = useCallback(
Expand Down Expand Up @@ -772,14 +773,14 @@ const ActivityOrRoutePlannerPage = () => {
<Typography className={classes.label}>
{t("page.activity-planner.activity-for-day")}
</Typography>
<Typography className={classes.date}>
<Box className={classes.date}>
<h1 className={classes.h1}>
{formateDateToFrenchFormat(
generateDateFromStringInput(surveyDate),
getLanguage(),
)}
</h1>
</Typography>
</Box>
</>
)}
</Box>
Expand Down
5 changes: 4 additions & 1 deletion src/pages/activity/activity-summary/ActivitySummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ const ActivitySummaryPage = () => {
context.idSurvey = idSurvey;
});

const navToCard = useCallback((iteration: number) => () => navToActivityOrRoute(iteration), []);
const navToCard = useCallback(
(iteration: number) => () => navToActivityOrRoute(iteration),
[idSurvey],
);

const navToActivityOrRoute = (iteration: number): void => {
const isEditedSummary: { [key: string]: string } = {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/end-survey/EndSurvey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const EndSurveyPage = () => {
data: dataWithIsEnvoyed ?? callbackHolder.getData(),
};

if (!isDemoMode && !isReviewer()) {
if (!isDemoMode && !isReviewer() && navigator.onLine) {
remotePutSurveyData(idSurvey, surveyData)
.then(surveyDataAnswer => {
surveyData.data.lastRemoteSaveDate = surveyDataAnswer.stateData?.date;
Expand All @@ -110,7 +110,7 @@ const EndSurveyPage = () => {
.catch(() => {
setErrorSubmit(true);
});
} else if (!isDemoMode && isReviewer()) {
} else if (!isDemoMode && isReviewer() && navigator.onLine) {
remotePutSurveyDataReviewer(idSurvey, stateData, surveyData.data)
.then(surveyDataAnswer => {
surveyData.data.lastRemoteSaveDate = surveyDataAnswer.stateData?.date;
Expand Down
1 change: 0 additions & 1 deletion src/pages/error/Error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const ErrorPage = (props: ErrorPageProps) => {
}, []);

const getErrorText = (errorCode: ErrorCodeEnum | undefined): string => {
console.error(`Type d'erreur: ${errorCode}`);
switch (errorCode) {
case ErrorCodeEnum.NO_RIGHTS:
return t("common.error.error-no-rights");
Expand Down
17 changes: 13 additions & 4 deletions src/pages/help/contact/ContactPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ContactPage = () => {
onNavigateBack={useCallback(() => navToHome(), [])}
backgroundWhite={false}
/>
<FlexCenter>
<FlexCenter className={classes.imageBox}>
<ContactImg aria-label={t("accessibility.asset.mui-icon.download")} />
</FlexCenter>
<Box className={classes.innerBox}>
Expand Down Expand Up @@ -71,26 +71,29 @@ const ContactPage = () => {

const useStyles = makeStylesEdt<{ innerHeight: number }>({ "name": { ContactPage } })(theme => ({
installBox: {
padding: "1rem",
padding: "0rem 1rem",
},
contentBox: {
height: "100vh",
height: innerHeight + "px",
maxHeight: innerHeight + "px",
},
contentBoxMobile: {
height: "95vh",
maxHeight: "95vh",
},
innerContentBox: {
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
height: innerHeight - 78 + "px",
maxHeight: innerHeight - 78 + "px",
},
innerBox: {
display: "flex",
justifyContent: "center",
},
textBox: { textAlign: "center", width: "50%", fontSize: "14px" },
textBoxMobile: { textAlign: "center", width: "100%", fontSize: "14px" },
textBoxMobile: { textAlign: "center", width: "100%", fontSize: "74%" },
actionsBox: { display: "flex", flexDirection: "column", alignItems: "center" },
actionBox: { maxWidth: "300px", margin: "0.5rem 0", width: "90%" },
button: { width: "100%", backgroundColor: theme.palette.text.primary },
Expand All @@ -111,6 +114,12 @@ const useStyles = makeStylesEdt<{ innerHeight: number }>({ "name": { ContactPage
paddingBox: {
marginBottom: "2rem",
},
imageBox: {
height: "15%",
svg: {
height: "100%",
},
},
}));

export default ContactPage;
Loading

0 comments on commit 7ee9ad6

Please sign in to comment.