Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(app): Unifier les écrans "Phase 1 hors parcours" #4557

Draft
wants to merge 4 commits into
base: 2633-RefactoAppHomePage
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions app/src/scenes/home/Phase1NotDone.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { youngCanWithdraw, isCle } from "snu-lib";
import Img3 from "../../assets/homePhase2Desktop.png";
import Img2 from "../../assets/homePhase2Mobile.png";
import Withdrawal from "../account/scenes/withdrawn/components/Withdrawal";
import { Link } from "react-router-dom";

export default function Phase1NotDone() {
const young = useSelector((state) => state.Auth.young);
Expand All @@ -23,20 +24,12 @@ export default function Phase1NotDone() {
{!isCle(young) && (
<>
<div className="flex w-full lg:w-fit flex-col items-stretch">
<button
<Link
className="mt-4 rounded-[10px] border-[1px] border-blue-600 bg-blue-600 py-2.5 px-3 text-sm font-medium leading-5 text-white hover:bg-white hover:!text-blue-600"
onClick={() => (window.location.href = "/changer-de-sejour")}>
to="/changer-de-sejour">
Choisir un nouveau séjour
</button>
</Link>
</div>

{youngCanWithdraw(young) ? (
<div className="flex w-full lg:w-fit flex-col items-stretch">
<span className="pt-4 [&>button]:text-blue-600">
<Withdrawal young={young} />
</span>
</div>
) : null}
</>
)}
</div>
Expand Down
42 changes: 14 additions & 28 deletions app/src/scenes/home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from "react";
import useDocumentTitle from "../../hooks/useDocumentTitle";
import { YOUNG_STATUS, YOUNG_STATUS_PHASE1, hasAccessToReinscription, hasCompletedPhase1 } from "../../utils";
import { YOUNG_STATUS, YOUNG_STATUS_PHASE1, hasCompletedPhase1 } from "../../utils";
import { cohortAssignmentAnnouncementsIsOpenForYoung, getCohort } from "../../utils/cohorts";
import Affected from "./Affected";
import InscriptionClosedCLE from "./InscriptionClosedCLE";
import HomePhase2 from "./HomePhase2";
import Phase1NotDone from "./Phase1NotDone";
import WaitingReinscription from "./WaitingReinscription";
import Default from "./default";
import RefusedV2 from "./refusedV2";
import WaitingAffectation from "./waitingAffectation";
Expand All @@ -21,20 +20,13 @@ import AvenirCohort from "./AvenirCohort";
import { EQUIVALENCE_STATUS, isCohortTooOld, YOUNG_STATUS_PHASE3 } from "snu-lib";
import Loader from "@/components/Loader";
import { wasYoungExcluded, hasCompletedPhase2 } from "../../utils";
import { fetchReInscriptionOpen } from "../../services/reinscription.service";
import { useQuery } from "@tanstack/react-query";

export default function Home() {
useDocumentTitle("Accueil");
const { young, isCLE } = useAuth();
const { young } = useAuth();
const cohort = getCohort(young.cohort);

const { data: isReinscriptionOpen, isLoading: isReinscriptionOpenLoading } = useQuery({
queryKey: ["isReInscriptionOpen"],
queryFn: fetchReInscriptionOpen,
});

if (!young || !cohort || isReinscriptionOpenLoading) return <Loader />;
if (!young || !cohort) return <Loader />;

// Je ne peux plus participer au SNU (exclu, refusé) :
if (wasYoungExcluded(young)) return <Excluded />;
Expand All @@ -61,25 +53,19 @@ export default function Home() {
return <HomePhase2 />;
}

// Je peux me réinscrire :
if (isReinscriptionOpen && hasAccessToReinscription(young, cohort)) {
return <WaitingReinscription reinscriptionOpen={isReinscriptionOpen} />;
}
// Je n'ai pas validé ma phase 1 et la réinscription n'est pas ouverte (je peux changer de séjour):
// Cet écran permet de changer de séjour ou se désister
if ([YOUNG_STATUS.VALIDATED].includes(young.status) && young.statusPhase1 === YOUNG_STATUS_PHASE1.NOT_DONE) {
return <Phase1NotDone />;
}
if (hasWithdrawn) return <Withdrawn />;

// je suis sur une cohorte à venir et la réinscription n'est pas ouverte
if (young.cohort === "à venir") {
return <AvenirCohort />; //moyen de faire encore mieux niveau merge
}
if (young.cohort === "à venir") return <AvenirCohort />;
// TODO: if (cohortGroup.type === COHORT_GROUP_TYPE.RESERVE) return <AvenirCohort />;

// Je me suis désisté et la reinscription est fermée
if (hasWithdrawn) {
return <Withdrawn />;
}
if (new Date() > new Date(cohort.dateEnd)) return <Phase1NotDone />;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas d'accord ici !
car les référent peuvent mettre jusqu'a 8 jours pour valider des jeunes après la fin du séjour..


return <HomePhase1 />;
}

function HomePhase1() {
const { young, isCLE } = useAuth();
const cohort = getCohort(young.cohort);

// Ma phase 1 est en cours, soit en cours d'inscription, soit en plein parcours
const isCohortInstructionOpen = new Date() < new Date(cohort.instructionEndDate);
Expand Down
Loading