Skip to content

Commit

Permalink
fix: mcp redirect (#2338)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonat75 authored Jul 29, 2024
1 parent 25beaae commit 6ddb586
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 49 deletions.
5 changes: 0 additions & 5 deletions packages/app/src/api/core-domain/infra/auth/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,6 @@ export const authConfig: AuthOptions = {

return token;
},

async redirect({ url, baseUrl }) {
logger.info(`Redirect called with URL: ${url} and Base URL: ${baseUrl}`);
return url.startsWith(baseUrl) ? url : baseUrl;
},
// expose data from jwt to front
session({ session, token }) {
session.user = token.user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const DeclarationReceipt = (input: DeclarationOpmc) => {
value: `${declaration.declarant.lastname} ${declaration.declarant.firstname}`,
},
{
key: "Adresse mail",
key: "Adresse email",
value: declaration.declarant.email.getValue(),
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const RepresentationEquilibreeReceipt = ({ repEq }: RepresentationEquilib
value: `${repEq.declarant.lastname} ${repEq.declarant.firstname}`,
},
{
key: "Adresse mail",
key: "Adresse email",
value: repEq.declarant.email.getValue(),
},
],
Expand Down
18 changes: 18 additions & 0 deletions packages/app/src/app/(default)/RedirectUrl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use client";

import { useRouter } from "next/navigation";
import { useEffect } from "react";

export const RedirectedUrl = () => {
const routeur = useRouter();

useEffect(() => {
const redirectedUrl = window.sessionStorage.getItem("redirectUrl");
if (redirectedUrl) {
window.sessionStorage.removeItem("redirectUrl");
routeur.push(redirectedUrl);
}
}, []);

return null;
};
4 changes: 2 additions & 2 deletions packages/app/src/app/(default)/cgu/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Cgu = () => {
<p>
Egapro utilise le service d’identification MonComptePro pour garantir l’appartenance de l’Utilisateur à
l’entreprise déclarante. L’Utilisateur doit créer un compte MonComptePro, en renseignant notamment son
adresse mail, et s’identifier avec ce compte pour déclarer sur Egapro.
adresse email, et s’identifier avec ce compte pour déclarer sur Egapro.
</p>
<h3 className="fr-text--xl">
3.2 Egapro sur la représentation équilibrée entre les femmes et les hommes dans les postes de direction des
Expand All @@ -80,7 +80,7 @@ const Cgu = () => {
<p>
Egapro utilise le service d’identification MonComptePro pour garantir l’appartenance de l’Utilisateur à
l’entreprise déclarante. L’Utilisateur doit créer un compte MonComptePro, en renseignant notamment son
adresse mail, et s’identifier avec ce compte pour déclarer sur Egapro.
adresse email, et s’identifier avec ce compte pour déclarer sur Egapro.
</p>
<h2>Article 4 - Responsabilités</h2>
<h3 className="fr-text--xl">4.1 L’Éditeur de la Plateforme</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { fr } from "@codegouvfr/react-dsfr";
import Alert from "@codegouvfr/react-dsfr/Alert";
import { Button } from "@codegouvfr/react-dsfr/Button";
import Input from "@codegouvfr/react-dsfr/Input";
import { Select } from "@codegouvfr/react-dsfr/Select";
import { config } from "@common/config";
Expand All @@ -11,7 +12,7 @@ import { isCompanyClosed } from "@common/core-domain/helpers/entreprise";
import { type COUNTIES, COUNTRIES_COG_TO_ISO, COUNTY_TO_REGION, inseeCodeToCounty, PUBLIC_YEARS } from "@common/dict";
import { zodFr } from "@common/utils/zod";
import { SkeletonForm } from "@components/utils/skeleton/SkeletonForm";
import { BackNextButtonsGroup, Link } from "@design-system";
import { BackNextButtonsGroup, Icon, Link } from "@design-system";
import { ClientAnimate } from "@design-system/utils/client/ClientAnimate";
import { getCompany } from "@globalActions/company";
import { CLOSED_COMPANY_ERROR } from "@globalActions/companyErrorCodes";
Expand All @@ -20,7 +21,7 @@ import { useDeclarationFormManager } from "@services/apiClient/useDeclarationFor
import { sortBy } from "lodash";
import { useRouter } from "next/navigation";
import { type Session } from "next-auth";
import { useSession } from "next-auth/react";
import { signIn, useSession } from "next-auth/react";
import { FormProvider, useForm } from "react-hook-form";
import { z } from "zod";

Expand Down Expand Up @@ -282,6 +283,20 @@ export const CommencerForm = ({ monCompteProHost }: { monCompteProHost: string }
cliquez ici
</Link>
</p>
<div className={fr.cx("fr-pt-3v")}>
Vous ne trouvez pas dans la liste déroulante l'entreprise rattachée à votre compte MonComptePro, cliquez sur
ce bouton : <br />
<Button
onClick={e => {
e.preventDefault();
window.sessionStorage.setItem("redirectUrl", window.location.href);
signIn("moncomptepro", { redirect: false });
}}
>
<Icon icon="fr-icon-refresh-line" />
Rafraichir MCP
</Button>
</div>

<ClientAnimate>
{isValid && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CenteredContainer } from "@design-system";
import { NAVIGATION } from "../../navigation";
import { Indic2or3Form } from "../Form";

const { title } = NAVIGATION.indicateur3;
const { title } = NAVIGATION.indicateur2;

export const metadata = {
title,
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/app/(default)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { Header } from "../Header";
// for resolution of "[css url] was preloaded using link preload but not used within a few seconds from the window's load event." warning in dev mode
import styles from "./default.module.css";
import { Navigation } from "./Navigation";
import { RedirectedUrl } from "./RedirectUrl";

const DefaultLayout = async ({ children }: PropsWithChildren) => {
return (
<div className={styles.app}>
<RedirectedUrl />
<Header auth navigation={<Navigation />} />
<main role="main" id="content" className={styles.content}>
{children}
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/app/(default)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ const LoginPage = async ({ searchParams }: NextServerPageProps<never, "callbackU
</p>
<br />
<p>
Pour s'identifier avec MonComptePro, il convient d'utiliser une <b>adresse mail professionnelle</b>,
celle-ci doit correspondre à la personne à contacter par les services de l'inspection du travail en
cas de besoin.
Pour s'identifier avec MonComptePro, il convient d'utiliser une <b>adresse email professionnelle</b>
, celle-ci doit correspondre à la personne à contacter par les services de l'inspection du travail
en cas de besoin.
</p>
<br />
<p>
Expand Down
18 changes: 11 additions & 7 deletions packages/app/src/app/(default)/mon-espace/les-entreprises/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const MesEntreprisesInfoAlert = () => (
</p>
<p>
{" "}
Si vous souhaitez supprimer une adresse mail rattachée à un siren, veuillez{" "}
Si vous souhaitez supprimer une adresse email rattachée à un siren, veuillez{" "}
<Link target="_blank" href={"mailto:[email protected]"}>
contacter MonComptePro
</Link>{" "}
Expand All @@ -38,7 +38,7 @@ const MesEntreprisesInfoAlert = () => (
>
créer un nouveau compte MonComptePro
</Link>{" "}
pour rattacher une autre adresse mail à un numéro Siren.
pour rattacher une autre adresse email à un numéro Siren.
</p>
</>
}
Expand All @@ -62,8 +62,10 @@ const MesEntreprisesPage = async ({ searchParams }: NextServerPageProps<never, "
</Box>
<p>
<br />
Vous souhaitez rattacher votre adresse mail à un autre Siren,{" "}
<Link href="https://app.moncomptepro.beta.gouv.fr/manage-organizations">cliquez ici</Link>
Vous souhaitez rattacher votre adresse email à un autre Siren,{" "}
<Link target="_blank" href="https://app.moncomptepro.beta.gouv.fr/manage-organizations">
cliquez ici
</Link>
</p>
</Box>
</MessageProvider>
Expand All @@ -84,8 +86,10 @@ const MesEntreprisesPage = async ({ searchParams }: NextServerPageProps<never, "
</Box>
<p>
<br />
Vous souhaitez rattacher votre adresse mail à un autre Siren,{" "}
<Link href="https://app.moncomptepro.beta.gouv.fr/manage-organizations">cliquez ici</Link>
Vous souhaitez rattacher votre adresse email à un autre Siren,{" "}
<Link target="_blank" href="https://app.moncomptepro.beta.gouv.fr/manage-organizations">
cliquez ici
</Link>
</p>
<Box mt="4w">
<Heading as="h1" variant="h6" text="Responsables" />
Expand All @@ -107,7 +111,7 @@ const MesEntreprisesPage = async ({ searchParams }: NextServerPageProps<never, "
</Box>
<p>
<br />
Vous souhaitez rattacher votre adresse mail à un autre Siren,{" "}
Vous souhaitez rattacher votre adresse email à un autre Siren,{" "}
<Link href="https://app.moncomptepro.beta.gouv.fr/manage-organizations">cliquez ici</Link>
</p>
<Box mt="4w">Pas d'utilisateur pour ce Siren ou Url invalide</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const MesDeclarationsPage = async ({ searchParams }: NextServerPageProps<never,
<SelectSirenStaff currentSiren={selectedSiren} />
<p>
<br />
Vous souhaitez rattacher votre adresse mail à un autre Siren,{" "}
Vous souhaitez rattacher votre adresse email à un autre Siren,{" "}
<Link
target="_blank"
href={`https://app${
Expand Down Expand Up @@ -121,7 +121,7 @@ const MesDeclarationsPage = async ({ searchParams }: NextServerPageProps<never,
))}
<p>
<br />
Vous souhaitez rattacher votre adresse mail à un autre Siren,{" "}
Vous souhaitez rattacher votre adresse email à un autre Siren,{" "}
<Link
target="_blank"
href={`https://app${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ export const SelectSiren = ({ sirenList, loadedSiren }: { loadedSiren?: string;
</div>
</GridCol>
</Grid>
<div className={fr.cx("fr-pt-2v")}>
<Button onClick={() => signIn("moncomptepro", { redirect: true })}>
<div className={fr.cx("fr-pt-3v")}>
Vous ne trouvez pas dans la liste déroulante l'entreprise rattachée à votre compte MonComptePro, cliquez sur ce
bouton : <br />
<Button
onClick={e => {
e.preventDefault();
window.sessionStorage.setItem("redirectUrl", window.location.href);
signIn("moncomptepro", { redirect: false });
}}
>
<Icon icon="fr-icon-refresh-line" />
Rafraichir MCP
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const MesEntreprisesInfoAlert = () => (
entreprises.
</p>
<p>
{" "}
Si vous souhaitez supprimer une adresse mail rattachée à un siren, veuillez{" "}
Si vous souhaitez supprimer une adresse email rattachée à un siren, veuillez{" "}
<Link target="_blank" href={"mailto:[email protected]"}>
contacter MonComptePro
</Link>{" "}
Expand All @@ -38,7 +37,7 @@ const MesEntreprisesInfoAlert = () => (
>
créer un nouveau compte MonComptePro
</Link>{" "}
pour rattacher une autre adresse mail à un numéro Siren.
pour rattacher une autre adresse email à un numéro Siren.
</p>
</>
}
Expand Down Expand Up @@ -96,7 +95,7 @@ const MesEntreprisesPage = async ({ searchParams }: NextServerPageProps<never, "
<SelectSiren sirenList={sirenList} loadedSiren={selectedSiren} />
<p>
<br />
Vous souhaitez rattacher votre adresse mail à un autre Siren,{" "}
Vous souhaitez rattacher votre adresse email à un autre Siren,{" "}
<Link
target="_blank"
href={`https://app${
Expand Down Expand Up @@ -128,7 +127,7 @@ const MesEntreprisesPage = async ({ searchParams }: NextServerPageProps<never, "
<SelectSiren sirenList={sirenList} />
<p>
<br />
Vous souhaitez rattacher votre adresse mail à un autre Siren,{" "}
Vous souhaitez rattacher votre adresse email à un autre Siren,{" "}
<Link
target="_blank"
href={`https://app${
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"use client";

import { fr } from "@codegouvfr/react-dsfr";
import { Button } from "@codegouvfr/react-dsfr/Button";
import Input from "@codegouvfr/react-dsfr/Input";
import Select from "@codegouvfr/react-dsfr/Select";
import { createSteps } from "@common/core-domain/dtos/CreateRepresentationEquilibreeDTO";
import { YEARS_REPEQ } from "@common/dict";
import { BackNextButtonsGroup, FormLayout, Link } from "@design-system";
import { BackNextButtonsGroup, FormLayout, Icon, Link } from "@design-system";
import { getCompany } from "@globalActions/company";
import { zodResolver } from "@hookform/resolvers/zod";
import { sortBy } from "lodash";
import { useRouter } from "next/navigation";
import { type Session } from "next-auth";
import { signIn } from "next-auth/react";
import { useTransition } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
Expand Down Expand Up @@ -175,6 +178,20 @@ export const CommencerForm = ({ session, monCompteProHost }: { monCompteProHost:
cliquez ici
</Link>
</p>
<div className={fr.cx("fr-pt-3v")}>
Vous ne trouvez pas dans la liste déroulante l'entreprise rattachée à votre compte MonComptePro, cliquez sur
ce bouton : <br />
<Button
onClick={e => {
e.preventDefault();
window.sessionStorage.setItem("redirectUrl", window.location.href);
signIn("moncomptepro", { redirect: false });
}}
>
<Icon icon="fr-icon-refresh-line" />
Rafraichir MCP
</Button>
</div>
<BackNextButtonsGroup
backProps={{
onClick: confirmReset,
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/app/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const labourMinistryRepeq = {

export const Footer = () => (
<DsfrFooter
accessibility="non compliant"
accessibility="partially compliant"
accessibilityLinkProps={{
href: "/declaration-accessibilite",
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export class DeclarationSpecification extends AbstractSpecification<Declaration>

try {
// TODO: confirm year with product owner
assert(
declaration.year.getValue() >= 2020 && declaration.year.getValue() <= new Date().getFullYear(),
"Règle 1 - Assertion année indicateurs",
);
// assert(
// declaration.year.getValue() >= 2020 && declaration.year.getValue() <= new Date().getFullYear(),
// "Règle 1 - Assertion année indicateurs",
// );

// Règle 2 - Assertion champs obligatoiresx
// siren, year are present by definition but we check them anyway.
Expand Down
4 changes: 2 additions & 2 deletions packages/simulateur/src/components/UtilisateursEntreprise.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ export default function UtilisateursEntreprise({ siren }: { siren: string }) {

const FormInput = z.object({
email: z
.string({ required_error: "L'adresse mail est requise" })
.regex(EMAIL_REGEX, { message: "L'adresse mail est invalide" }),
.string({ required_error: "L'adresse email est requise" })
.regex(EMAIL_REGEX, { message: "L'adresse email est invalide" }),
})

return (
Expand Down
6 changes: 3 additions & 3 deletions packages/simulateur/src/components/ds/FieldEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { fieldValidator, InputControl, InputControlProps } from "./form-lib"
type FieldEmailProps = Partial<InputControlProps>

const FieldInput = z
.string({ required_error: "L'adresse mail est requise" })
.min(1, { message: "L'adresse mail est requise" })
.regex(EMAIL_REGEX, { message: "L'adresse mail est invalide" })
.string({ required_error: "L'adresse email est requise" })
.min(1, { message: "L'adresse email est requise" })
.regex(EMAIL_REGEX, { message: "L'adresse email est invalide" })

export function FieldEmail({ ...rest }: FieldEmailProps) {
return (
Expand Down
4 changes: 2 additions & 2 deletions packages/simulateur/src/views/AskEmail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test("AskEmail should not accept empty email", () => {
render(<AskEmail />)
expect(screen.getByLabelText(/Email/i)).toHaveValue("")
fireEvent.submit(screen.getByRole("button", { name: "Envoyer" }))
expect(screen.getByText("L'adresse mail est requise")).toBeInTheDocument()
expect(screen.getByText("L'adresse email est requise")).toBeInTheDocument()
})

test("AskEmail should not accept invalid email", async () => {
Expand All @@ -25,7 +25,7 @@ test("AskEmail should not accept invalid email", async () => {
})
expect(input).toHaveValue("invalid")
fireEvent.submit(screen.getByRole("button", { name: "Envoyer" }))
expect(screen.getByText("L'adresse mail est invalide")).toBeInTheDocument()
expect(screen.getByText("L'adresse email est invalide")).toBeInTheDocument()
})

test("AskEmail should accept valid email", async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/simulateur/src/views/AskEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import { EMAIL_REGEX } from "../utils/regex"

const FormInput = z.object({
email: z
.string({ required_error: "L'adresse mail est requise" })
.min(1, { message: "L'adresse mail est requise" })
.regex(EMAIL_REGEX, { message: "L'adresse mail est invalide" }),
.string({ required_error: "L'adresse email est requise" })
.min(1, { message: "L'adresse email est requise" })
.regex(EMAIL_REGEX, { message: "L'adresse email est invalide" }),
})

interface AskEmailProps {
Expand Down
Loading

0 comments on commit 6ddb586

Please sign in to comment.