diff --git a/app/package.json b/app/package.json index fdc5aae554..be67038a9e 100644 --- a/app/package.json +++ b/app/package.json @@ -18,8 +18,8 @@ "clean": "rm -fr node_modules .turbo build .swc" }, "devDependencies": { - "@types/react-redux-toastr": "^7.0.0", "@swc/plugin-styled-components": "1.5.111", + "@types/react-redux-toastr": "^7.0.0", "@vitejs/plugin-react-swc": "^3.3.2", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", @@ -72,6 +72,7 @@ "react-tooltip": "^4.5.1", "reactstrap": "8.10.1", "redux": "4.2.1", + "redux-thunk": "^2.4.0", "regenerator-runtime": "0.13.9", "remark-gfm": "^4.0.0", "slugify": "^1.6.5", diff --git a/app/src/Espace.jsx b/app/src/Espace.jsx index 498bc69c7c..9890adbfb2 100644 --- a/app/src/Espace.jsx +++ b/app/src/Espace.jsx @@ -1,6 +1,6 @@ import React, { lazy, Suspense, useEffect, useState } from "react"; -import { useSelector } from "react-redux"; -import { getCohort } from "./utils/cohorts"; +import useAuth from "./services/useAuth"; +import useCohort from "./services/useCohort"; import API from "./services/api"; import { ENABLE_PM, FEATURES_NAME, YOUNG_STATUS, isFeatureEnabled, permissionPhase2, shouldReAcceptRI } from "./utils"; import { Redirect, Switch } from "react-router-dom"; @@ -34,8 +34,8 @@ const Espace = () => { const [isModalCGUOpen, setIsModalCGUOpen] = useState(false); const [isModalRIOpen, setIsModalRIOpen] = useState(false); - const young = useSelector((state) => state.Auth.young); - const cohort = getCohort(young.cohort); + const { young } = useAuth(); + const { cohort } = useCohort(); const handleModalCGUConfirm = async () => { setIsModalCGUOpen(false); @@ -69,7 +69,7 @@ const Espace = () => { if (young.status === YOUNG_STATUS.NOT_ELIGIBLE && location.pathname !== "/noneligible") return ; - if (shouldForceRedirectToEmailValidation(young)) { + if (shouldForceRedirectToEmailValidation(young, cohort)) { return ; } diff --git a/app/src/app.jsx b/app/src/app.jsx index d894df09dc..4e93904e22 100644 --- a/app/src/app.jsx +++ b/app/src/app.jsx @@ -26,6 +26,7 @@ import useAuth from "./services/useAuth"; import PageLoader from "./components/PageLoader"; import FallbackComponent from "./components/FallBackComponent"; +import store from "./redux/store"; const AccountAlreadyExists = lazy(() => import("./scenes/account/AccountAlreadyExists")); const AllEngagements = lazy(() => import("./scenes/all-engagements/index")); @@ -65,7 +66,8 @@ function App() { await login(user); - if (shouldForceRedirectToEmailValidation(user)) { + const { cohort } = store.getState().Cohort; + if (shouldForceRedirectToEmailValidation(user, cohort)) { history.push("/preinscription/email-validation"); } } catch (e) { diff --git a/app/src/index.jsx b/app/src/index.jsx index 82280c6388..f7f88bb509 100644 --- a/app/src/index.jsx +++ b/app/src/index.jsx @@ -16,10 +16,10 @@ window.addEventListener("vite:preloadError", (event) => { }); ReactDOM.createRoot(document.getElementById("root")).render( - - - - - - , + // + + + + , + // , ); diff --git a/app/src/redux/auth/actions.ts b/app/src/redux/auth/actions.ts index 555a96428f..335c26c34f 100644 --- a/app/src/redux/auth/actions.ts +++ b/app/src/redux/auth/actions.ts @@ -1,12 +1,29 @@ +import { fetchCohort } from "@/utils/cohorts"; import * as Sentry from "@sentry/react"; +import { Dispatch } from "redux"; import { YoungType } from "snu-lib"; +import { setCohort } from "../cohort/actions"; export const authActions = { SETYOUNG: "SETYOUNG", }; export function setYoung(young?: YoungType) { - if (young) Sentry.setUser({ id: young._id, email: young.email, username: `${young.firstName} ${young.lastName}` }); - else Sentry.setUser(null); - return { type: authActions.SETYOUNG, young }; + return async (dispatch: Dispatch, getState: () => any) => { + const oldCohortId = getState().Auth.young?.cohortId; + + dispatch({ type: authActions.SETYOUNG, young }); + + // Side effects + if (young) Sentry.setUser({ id: young._id, email: young.email, username: `${young.firstName} ${young.lastName}` }); + else Sentry.setUser(null); + + const newCohortId = young?.cohortId; + if (newCohortId && oldCohortId !== newCohortId) { + const cohort = await fetchCohort(newCohortId); + if (!cohort) return; + console.log(`Updating stored cohort. New cohort name: ${cohort.name}`); + dispatch(setCohort(cohort)); + } + }; } diff --git a/app/src/redux/store.ts b/app/src/redux/store.ts index 5fbd0ad46e..139327cee8 100644 --- a/app/src/redux/store.ts +++ b/app/src/redux/store.ts @@ -1,7 +1,9 @@ -import { createStore, combineReducers } from "redux"; +import { createStore, combineReducers, applyMiddleware, compose } from "redux"; import reducers from "./reducers"; import * as Sentry from "@sentry/react"; +import thunk from "redux-thunk"; const sentryReduxEnhancer = Sentry.createReduxEnhancer(); +const enhancer = compose(applyMiddleware(thunk), sentryReduxEnhancer); -export default createStore(combineReducers({ ...reducers }), sentryReduxEnhancer); +export default createStore(combineReducers({ ...reducers }), enhancer); diff --git a/app/src/scenes/changeSejour/scenes/ChangeSejourMenu.tsx b/app/src/scenes/changeSejour/scenes/ChangeSejourMenu.tsx index 8f04c1fb5f..9ed1d326d7 100644 --- a/app/src/scenes/changeSejour/scenes/ChangeSejourMenu.tsx +++ b/app/src/scenes/changeSejour/scenes/ChangeSejourMenu.tsx @@ -1,6 +1,6 @@ import React from "react"; import { Link } from "react-router-dom"; -import useAuth from "@/services/useAuth"; +import useCohort from "@/services/useCohort"; import { HiArrowRight } from "react-icons/hi"; import { CohortGroupType, CohortType, getCohortPeriod, getCohortYear } from "snu-lib"; import plausibleEvent from "@/services/plausible"; @@ -14,7 +14,6 @@ import { capitalizeFirstLetter } from "@/scenes/inscription2023/steps/stepConfir import usePermissions from "@/hooks/usePermissions"; import { useLocation } from "react-router-dom"; import ErrorNotice from "@/components/ui/alerts/ErrorNotice"; -import useCohort from "@/services/useCohort"; export default function ChangeSejour() { const groups = useCohortGroups(); diff --git a/app/src/scenes/home/index.tsx b/app/src/scenes/home/index.tsx index a9fdc24a06..6dc1d7bf4f 100644 --- a/app/src/scenes/home/index.tsx +++ b/app/src/scenes/home/index.tsx @@ -1,7 +1,7 @@ import React from "react"; import useDocumentTitle from "../../hooks/useDocumentTitle"; import { YOUNG_STATUS, hasAccessToReinscription, hasCompletedPhase1, isDoingPhase1 } from "../../utils"; -import { getCohort } from "../../utils/cohorts"; +import useCohort from "@/services/useCohort"; import InscriptionClosedCLE from "./InscriptionClosedCLE"; import HomePhase2 from "./HomePhase2"; import Phase1NotDone from "./Phase1NotDone"; @@ -22,7 +22,7 @@ import useReinscription from "../changeSejour/lib/useReinscription"; export default function Home() { useDocumentTitle("Accueil"); const { young, isCLE } = useAuth(); - const cohort = getCohort(young.cohort); + const { cohort } = useCohort(); const { data: isReinscriptionOpen, isLoading: isReinscriptionOpenLoading } = useReinscription(); @@ -33,14 +33,14 @@ export default function Home() { if (young.status === YOUNG_STATUS.REFUSED) return ; // Phase 3 - if ([YOUNG_STATUS_PHASE3.WAITING_VALIDATION, YOUNG_STATUS_PHASE3.VALIDATED].includes(young.statusPhase3)) { + if ([YOUNG_STATUS_PHASE3.WAITING_VALIDATION, YOUNG_STATUS_PHASE3.VALIDATED].includes(young.statusPhase3 as any)) { return ; } // Je peux accéder à la Homepage de la Phase 2 si j'ai validé ma phase 1 et que ma cohorte me permet encore de faire la phase 2 : const hasMission = young.phase2ApplicationStatus.some((status) => ["VALIDATED", "IN_PROGRESS"].includes(status)); - const hasEquivalence = [EQUIVALENCE_STATUS.WAITING_CORRECTION, EQUIVALENCE_STATUS.WAITING_VERIFICATION].includes(young.status_equivalence); - const hasWithdrawn = [YOUNG_STATUS.WITHDRAWN, YOUNG_STATUS.ABANDONED].includes(young.status); + const hasEquivalence = [EQUIVALENCE_STATUS.WAITING_CORRECTION, EQUIVALENCE_STATUS.WAITING_VERIFICATION].includes(young.status_equivalence as any); + const hasWithdrawn = [YOUNG_STATUS.WITHDRAWN, YOUNG_STATUS.ABANDONED].includes(young.status as any); if (hasCompletedPhase1(young)) { // les volontaires des première cohortes n'ont plus le droit de faire la phase 2 SAUF si ils l'ont commencé @@ -65,7 +65,7 @@ export default function Home() { // Ma phase 1 est en cours, soit en cours d'inscription, soit en plein parcours const isCohortInstructionOpen = new Date() < new Date(cohort.instructionEndDate); - if (isCLE && [YOUNG_STATUS.WAITING_VALIDATION, YOUNG_STATUS.WAITING_CORRECTION].includes(young.status) && !isCohortInstructionOpen) { + if (isCLE && [YOUNG_STATUS.WAITING_VALIDATION, YOUNG_STATUS.WAITING_CORRECTION].includes(young.status as any) && !isCohortInstructionOpen) { return ; } diff --git a/app/src/scenes/inscription2023/InscriptionClosed.jsx b/app/src/scenes/inscription2023/InscriptionClosed.jsx index 6e075c8228..ef15a130c3 100644 --- a/app/src/scenes/inscription2023/InscriptionClosed.jsx +++ b/app/src/scenes/inscription2023/InscriptionClosed.jsx @@ -1,13 +1,14 @@ import DSFRContainer from "@/components/dsfr/layout/DSFRContainer"; import DSFRLayout from "@/components/dsfr/layout/DSFRLayout"; -import { getCohort } from "@/utils/cohorts"; +import useCohort from "@/services/useCohort"; import { SignupButtons } from "@snu/ds/dsfr"; import React from "react"; import { useHistory } from "react-router-dom"; -import { getCohortPeriod, YOUNG_STATUS } from "snu-lib"; +import { YOUNG_STATUS } from "snu-lib"; export default function InscriptionClosed({ young, isCLE }) { const history = useHistory(); + const { cohortDateString } = useCohort(); const statusWording = (young, isCLE) => { if (isCLE) { if ([YOUNG_STATUS.REINSCRIPTION, YOUNG_STATUS.IN_PROGRESS].includes(young.status)) { @@ -29,7 +30,7 @@ export default function InscriptionClosed({ young, isCLE }) { {!isCLE ? ( -

Les inscriptions pour le séjour {getCohortPeriod(getCohort(young?.cohort))} sont clôturées. Vous ne pourrez donc pas participer au séjour.

+

Les inscriptions pour le séjour {cohortDateString} sont clôturées. Vous ne pourrez donc pas participer au séjour.

) : (

Les inscriptions dans le cadre des classes engagées ont été clôturées.

)} diff --git a/app/src/scenes/inscription2023/index.jsx b/app/src/scenes/inscription2023/index.jsx index 256075cecd..3becac9063 100644 --- a/app/src/scenes/inscription2023/index.jsx +++ b/app/src/scenes/inscription2023/index.jsx @@ -1,5 +1,4 @@ import React from "react"; -import { useSelector } from "react-redux"; import { Redirect, useParams } from "react-router-dom"; import { SentryRoute } from "../../sentry"; @@ -20,7 +19,7 @@ import { YOUNG_STATUS, inscriptionCreationOpenForYoungs } from "snu-lib"; import FutureCohort from "./FutureCohort"; import InscriptionClosed from "./InscriptionClosed"; import { knowledgebaseURL } from "../../config"; -import { getCohort } from "@/utils/cohorts"; +import useCohort from "@/services/useCohort"; import useAuth from "@/services/useAuth"; import Help from "./components/Help"; import Stepper from "@/components/dsfr/ui/Stepper"; @@ -103,9 +102,8 @@ const StepCorrection = () => { }; export default function Index() { - const young = useSelector((state) => state.Auth.young); - const { isCLE } = useAuth(); - const cohort = getCohort(young.cohort); + const { young, isCLE } = useAuth(); + const { cohort } = useCohort(); if (!young) return ; if ([YOUNG_STATUS.IN_PROGRESS, YOUNG_STATUS.REINSCRIPTION].includes(young.status) && young.cohort === "à venir") { diff --git a/app/src/scenes/inscription2023/steps/stepConfirm.jsx b/app/src/scenes/inscription2023/steps/stepConfirm.jsx index 3b64954a22..bcfe5e3d9d 100644 --- a/app/src/scenes/inscription2023/steps/stepConfirm.jsx +++ b/app/src/scenes/inscription2023/steps/stepConfirm.jsx @@ -1,8 +1,9 @@ import React from "react"; -import { useDispatch, useSelector } from "react-redux"; +import { useDispatch } from "react-redux"; import { useHistory, Link } from "react-router-dom"; -import { translate, getCohortPeriod, concatPhoneNumberWithZone } from "snu-lib"; -import { getCohort } from "@/utils/cohorts"; +import { translate, concatPhoneNumberWithZone } from "snu-lib"; +import useAuth from "@/services/useAuth"; +import useCohort from "@/services/useCohort"; import EditPen from "../../../assets/icons/EditPen"; import ModalSejour from "../components/ModalSejour"; import { setYoung } from "../../../redux/auth/actions"; @@ -14,7 +15,8 @@ import DSFRContainer from "@/components/dsfr/layout/DSFRContainer"; import { SignupButtons } from "@snu/ds/dsfr"; export default function StepConfirm() { - const young = useSelector((state) => state.Auth.young); + const { young } = useAuth(); + const { cohortDateString } = useCohort(); const [modal, setModal] = React.useState({ isOpen: false }); const [loading, setLoading] = React.useState(false); const [error, setError] = React.useState({}); @@ -71,7 +73,7 @@ export default function StepConfirm() {

Séjour de cohésion :

-
{capitalizeFirstLetter(getCohortPeriod(getCohort(young?.cohort)))}
+
{capitalizeFirstLetter(cohortDateString)}
- {!pdrChoiceExpired(young.cohort) && ( + {!pdrChoiceExpired && (
)} - + ); } @@ -104,7 +104,7 @@ export default function StepPDR({ data: { center, session, meetingPoint, departu - {!pdrChoiceExpired(young.cohort) && ( + {!pdrChoiceExpired && (
)} - + ); } @@ -126,7 +126,7 @@ export default function StepPDR({ data: { center, session, meetingPoint, departu ); } - if (pdrChoiceExpired(young.cohort)) { + if (pdrChoiceExpired) { return (

Date de choix dépassée

@@ -141,7 +141,7 @@ export default function StepPDR({ data: { center, session, meetingPoint, departu

Confirmez votre point de rassemblement

- À faire avant le {pdrChoiceLimitDate(young.cohort)}. + À faire avant le {pdrChoiceLimitDate}.

@@ -150,7 +150,7 @@ export default function StepPDR({ data: { center, session, meetingPoint, departu
- +
); } diff --git a/app/src/scenes/phase1/scenes/affected/index.jsx b/app/src/scenes/phase1/scenes/affected/index.jsx index 9bec98de68..7e3e8c3b82 100644 --- a/app/src/scenes/phase1/scenes/affected/index.jsx +++ b/app/src/scenes/phase1/scenes/affected/index.jsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react"; import { toastr } from "react-redux-toastr"; import { capture } from "@/sentry"; import { isCle, transportDatesToString, youngCanChangeSession, getDepartureDate, getReturnDate } from "snu-lib"; -import { getCohort } from "../../../../utils/cohorts"; +import useCohort from "@/services/useCohort"; import api from "../../../../services/api"; import { AlertBoxInformation } from "../../../../components/Content"; import ChangeStayLink from "../../components/ChangeStayLink"; @@ -25,7 +25,7 @@ export default function Affected() { const [showInfoMessage, setShowInfoMessage] = useState(false); const [loading, setLoading] = useState(true); - const cohort = getCohort(young.cohort); + const { cohort } = useCohort(); const departureDate = getDepartureDate(young, session, cohort, meetingPoint); const returnDate = getReturnDate(young, session, cohort, meetingPoint); const data = { center, meetingPoint, session, departureDate, returnDate }; diff --git a/app/src/scenes/phase1/waitingAffectation.jsx b/app/src/scenes/phase1/waitingAffectation.jsx index eb4a80bd43..e2a8ef014b 100644 --- a/app/src/scenes/phase1/waitingAffectation.jsx +++ b/app/src/scenes/phase1/waitingAffectation.jsx @@ -1,5 +1,5 @@ import React from "react"; -import { getCohortPeriod, youngCanChangeSession } from "snu-lib"; +import { youngCanChangeSession } from "snu-lib"; import { Link } from "react-router-dom"; import hero2 from "../../assets/hero-2.png"; import heroBanner from "../../assets/hero-banner.png"; @@ -15,16 +15,14 @@ import Files from "./Files"; import ButtonExternalLinkPrimary from "../../components/ui/buttons/ButtonExternalLinkPrimary"; import useAuth from "@/services/useAuth"; import { RiInformationFill } from "react-icons/ri"; -import { getCohort } from "@/utils/cohorts"; +import useCohort from "@/services/useCohort"; import plausibleEvent from "@/services/plausible"; export default function WaitingAffectation() { const { young, isCLE } = useAuth(); + const { cohortDateString } = useCohort(); const shouldShowChangeStayLink = !isCLE && youngCanChangeSession(young); - const cohort = getCohort(young.cohort); - const cohortDate = getCohortPeriod(cohort); - function handleClick() { plausibleEvent("CLE attente affectation - desistement"); } @@ -39,7 +37,7 @@ export default function WaitingAffectation() {

Mon séjour de cohésion

-

{cohortDate}

+

{cohortDateString}

{shouldShowChangeStayLink && }
diff --git a/app/src/scenes/phase1/waitingList.jsx b/app/src/scenes/phase1/waitingList.jsx index 95d018142a..cc1c813a26 100644 --- a/app/src/scenes/phase1/waitingList.jsx +++ b/app/src/scenes/phase1/waitingList.jsx @@ -1,15 +1,16 @@ import React from "react"; import { Link } from "react-router-dom"; -import { getCohortPeriod, youngCanChangeSession } from "snu-lib"; +import { youngCanChangeSession } from "snu-lib"; import clock from "../../assets/clock.svg"; import edit from "../../assets/editIcon.svg"; import hero from "../../assets/hero.png"; import { knowledgebaseURL } from "../../config"; import Container from "./components/Container"; import Files from "./Files"; -import { getCohort } from "@/utils/cohorts"; +import useCohort from "@/services/useCohort"; export default function WaitingList({ young }) { + const { cohortDateString } = useCohort(); return ( <> @@ -19,7 +20,7 @@ export default function WaitingList({ young }) { Mon séjour de cohésion
- {getCohortPeriod(getCohort(young.cohort))}{" "} + {cohortDateString}{" "} {youngCanChangeSession(young) ? ( edit icon diff --git a/app/src/services/useAuth.ts b/app/src/services/useAuth.ts index 905773c3e2..3de74aab2f 100644 --- a/app/src/services/useAuth.ts +++ b/app/src/services/useAuth.ts @@ -4,10 +4,8 @@ import { setYoung } from "../redux/auth/actions"; import { toastr } from "react-redux-toastr"; import { logoutYoung } from "./young.service"; import { YOUNG_SOURCE, YoungType } from "snu-lib"; -import { fetchCohort } from "@/utils/cohorts"; import { displaySignupToast } from "@/utils"; import { AuthState } from "@/redux/auth/reducer"; -import { setCohort } from "@/redux/cohort/actions"; export const useAuth = () => { const dispatch = useDispatch(); @@ -26,11 +24,7 @@ export const useAuth = () => { const login = async (user?: YoungType) => { if (!user) return history.push("/auth"); - dispatch(setYoung(user)); - const cohort = await fetchCohort(user.cohortId); - if (cohort) { - dispatch(setCohort(cohort)); - } + await dispatch(setYoung(user)); displaySignupToast(user); }; diff --git a/app/src/services/useCohort.ts b/app/src/services/useCohort.ts index 4a7e0e0d1a..93c6f056fa 100644 --- a/app/src/services/useCohort.ts +++ b/app/src/services/useCohort.ts @@ -2,9 +2,10 @@ import { CohortState } from "@/redux/cohort/reducer"; import { pdrChoiceExpired, pdrChoiceLimitDate } from "@/scenes/phase1/scenes/affected/utils/steps.utils"; import { cohortAssignmentAnnouncementsIsOpenForYoung, getMeetingPointChoiceLimitDateForCohort, isCohortDone, isCohortNeedJdm } from "@/utils/cohorts"; import { useSelector } from "react-redux"; +import { getCohortPeriod } from "snu-lib"; export default function useCohort() { - const cohort = useSelector((state: CohortState) => state.Cohort.cohort); + const { cohort } = useSelector((state: CohortState) => state.Cohort); return { cohort, cohortAssignmentAnnouncementsIsOpenForYoung: cohortAssignmentAnnouncementsIsOpenForYoung(cohort), @@ -13,5 +14,6 @@ export default function useCohort() { isCohortNeedJdm: isCohortNeedJdm(cohort), pdrChoiceLimitDate: pdrChoiceLimitDate(cohort), pdrChoiceExpired: pdrChoiceExpired(cohort), + cohortDateString: getCohortPeriod(cohort) as string, }; } diff --git a/app/src/utils/cohorts.ts b/app/src/utils/cohorts.ts index 22cfc01deb..ee25d5257b 100644 --- a/app/src/utils/cohorts.ts +++ b/app/src/utils/cohorts.ts @@ -39,9 +39,13 @@ export const canYoungResumePhase1 = (y: YoungType): boolean => { }; export async function fetchCohort(cohortId: string): Promise { - const res = await fetch(`${apiURL}/cohort/${cohortId}/public`); - if (!res.ok) { - throw new Error("Unable to fetch cohort"); - } - return res.json(); + return fetch(`${apiURL}/cohort/${cohortId}/public`) + .then((res) => res.json()) + .catch((error) => { + throw new Error(error); + }) + .then((res) => { + if (!res.ok) throw new Error("Unable to fetch cohort"); + return res.data; + }); } diff --git a/app/src/utils/index.js b/app/src/utils/index.js index 0ce458fadf..389e7cdea2 100644 --- a/app/src/utils/index.js +++ b/app/src/utils/index.js @@ -2,9 +2,10 @@ import PasswordValidator from "password-validator"; import { YOUNG_STATUS, YOUNG_STATUS_PHASE1, YOUNG_STATUS_PHASE2, YOUNG_STATUS_PHASE3, REGLEMENT_INTERIEUR_VERSION, isCohortTooOld, EQUIVALENCE_STATUS } from "snu-lib"; export * from "snu-lib"; import slugify from "slugify"; -import { getCohort, isCohortDone } from "./cohorts"; +import { isCohortDone } from "./cohorts"; import { toastr } from "react-redux-toastr"; import { INSCRIPTION_STEPS, REINSCRIPTION_STEPS } from "./navigation"; +import store from "@/redux/store"; function addOneDay(date) { const newDate = new Date(date); @@ -104,7 +105,7 @@ export function hasAccessToPhase2(young) { const userIsDoingAMission = young.phase2ApplicationStatus.some((status) => ["VALIDATED", "IN_PROGRESS"].includes(status)); const hasEquivalence = [EQUIVALENCE_STATUS.WAITING_CORRECTION, EQUIVALENCE_STATUS.WAITING_VERIFICATION].includes(young.status_equivalence); - const cohort = getCohort(young.cohort); + const { cohort } = store.getState().Cohort; if (isCohortTooOld(cohort) && !userIsDoingAMission && !hasEquivalence) { return false; } diff --git a/app/src/utils/navigation.js b/app/src/utils/navigation.js index d68d43d040..e7780defb2 100644 --- a/app/src/utils/navigation.js +++ b/app/src/utils/navigation.js @@ -1,5 +1,4 @@ import { FEATURES_NAME, isFeatureEnabled, YOUNG_SOURCE, YOUNG_STATUS } from "snu-lib"; -import { getCohort } from "./cohorts"; import { environment } from "@/config"; export const INSCRIPTION_STEPS = { @@ -264,8 +263,7 @@ export const redirectToCorrection = (young, field) => { return correction ? correction.redirect : "/"; }; -export function shouldForceRedirectToEmailValidation(user) { - const cohort = getCohort(user.cohort); +export function shouldForceRedirectToEmailValidation(user, cohort) { const isEmailValidationEnabled = isFeatureEnabled(FEATURES_NAME.EMAIL_VALIDATION, undefined, environment); const shouldUserValidateEmail = user.status === YOUNG_STATUS.IN_PROGRESS && user.emailVerified === "false" && new Date() < new Date(cohort.inscriptionModificationEndDate); const pathname = window.location.pathname; diff --git a/package-lock.json b/package-lock.json index dc0b5a97a2..a97a748f1d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1738,6 +1738,7 @@ "react-tooltip": "^4.5.1", "reactstrap": "8.10.1", "redux": "4.2.1", + "redux-thunk": "^2.4.0", "regenerator-runtime": "0.13.9", "remark-gfm": "^4.0.0", "slugify": "^1.6.5", @@ -23107,6 +23108,15 @@ "@babel/runtime": "^7.9.2" } }, + "node_modules/redux-thunk": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.4.0.tgz", + "integrity": "sha512-/y6ZKQNU/0u8Bm7ROLq9Pt/7lU93cT0IucYMrubo89ENjxPa7i8pqLKu6V4X7/TvYovQ6x01unTeyeZ9lgXiTA==", + "license": "MIT", + "peerDependencies": { + "redux": "^4" + } + }, "node_modules/reflect-metadata": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz",