Skip to content

Commit

Permalink
fix: mpc refresh (#2322)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonat75 authored Jul 22, 2024
1 parent 9a48ff2 commit 25beaae
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 32 deletions.
5 changes: 5 additions & 0 deletions packages/app/src/api/core-domain/infra/auth/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ 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 @@ -71,7 +71,7 @@ const Recherche = withSearchParamsValidation(getDeclarationStatsInputSchema)(asy
</GridCol>
</Grid>
</Container>
<Box className={cx(fr.cx("fr-pb-6w", "fr-pt-4w"), "bg-dsfr-alt-grey")}>
<Box className={cx(fr.cx("fr-pb-6w", "fr-pt-4w"))}>
{!searchParamsError && (
<Suspense>
{isLandingPage ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default withSearchParamsValidation(searchRepresentationEquilibreeDTOSchem
</GridCol>
</Grid>
</Container>
<Box className={cx(fr.cx("fr-pb-6w", "fr-pt-4w"), "bg-dsfr-alt-grey")}>
<Box className={cx(fr.cx("fr-pb-6w", "fr-pt-4w"))}>
<Container as="section">
<Grid haveGutters align="center">
<GridCol sm={12} md={10} xl={8}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ export function buildHelpersObjectifsMesures(declaration?: DeclarationOpmcDTO) {

export const isEditable = (declaration?: DeclarationOpmcDTO) =>
declaration?.["declaration-existante"].date
? isBefore(new Date(), add(new Date(declaration?.["declaration-existante"].date), { years: 1 }))
? !declaration?.opmc?.datePublicationObjectifs ||
isBefore(new Date(), add(new Date(declaration?.["declaration-existante"].date), { years: 1 }))
: false;

type Props = {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/app/(default)/login/MonCompteProLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const MonCompteProLogin = ({ callbackUrl }: MonCompteProLoginProps) => (
<MonCompteProButton
onClick={e => {
e.preventDefault();
signIn("moncomptepro", { callbackUrl });
signIn("moncomptepro", { callbackUrl, redirect: true });
}}
/>
<Link href="/aide-moncomptepro" target="_blank">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const getDeclarationOpmcStatus = (declaration?: DeclarationOpmcDTO) => {

try {
objectifsMesuresSchema.parse(initialValuesObjectifsMesures);
if (isFrozenDeclarationForOPMC(declaration)) return declarationOpmcStatus.NOT_MODIFIABLE_CORRECT;
// if (isFrozenDeclarationForOPMC(declaration)) return declarationOpmcStatus.NOT_MODIFIABLE_CORRECT;
} catch (e) {
if (isFrozenDeclarationForOPMC(declaration)) return declarationOpmcStatus.NOT_MODIFIABLE_INCORRECT;
//if (isFrozenDeclarationForOPMC(declaration)) return declarationOpmcStatus.NOT_MODIFIABLE_INCORRECT;
return declarationOpmcStatus.TO_COMPLETE;
}
return declarationOpmcStatus.COMPLETED;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { authConfig } from "@api/core-domain/infra/auth/config";
import Alert from "@codegouvfr/react-dsfr/Alert";
import { config } from "@common/config";
import { type DeclarationDTO } from "@common/core-domain/dtos/DeclarationDTO";
import { type DeclarationOpmcDTO } from "@common/core-domain/dtos/DeclarationOpmcDTO";
import { type RepresentationEquilibreeDTO } from "@common/core-domain/dtos/RepresentationEquilibreeDTO";
Expand Down Expand Up @@ -71,7 +72,14 @@ const MesDeclarationsPage = async ({ searchParams }: NextServerPageProps<never,
<p>
<br />
Vous souhaitez rattacher votre adresse mail à un autre Siren,{" "}
<Link href="https://app.moncomptepro.beta.gouv.fr/manage-organizations">cliquez ici</Link>
<Link
target="_blank"
href={`https://app${
config.api.security.moncomptepro.appTest ? "-sandbox" : ""
}.moncomptepro.beta.gouv.fr/manage-organizations`}
>
cliquez ici
</Link>
</p>
</Box>
</MessageProvider>
Expand Down Expand Up @@ -114,7 +122,14 @@ const MesDeclarationsPage = async ({ searchParams }: NextServerPageProps<never,
<p>
<br />
Vous souhaitez rattacher votre adresse mail à un autre Siren,{" "}
<Link href="https://app.moncomptepro.beta.gouv.fr/manage-organizations">cliquez ici</Link>
<Link
target="_blank"
href={`https://app${
config.api.security.moncomptepro.appTest ? "-sandbox" : ""
}.moncomptepro.beta.gouv.fr/manage-organizations`}
>
cliquez ici
</Link>
</p>
</Box>
<Box mt="10w">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use client";

import { fr } from "@codegouvfr/react-dsfr";
import { Button } from "@codegouvfr/react-dsfr/Button";
import { Select } from "@codegouvfr/react-dsfr/Select";
import { Grid, GridCol } from "@design-system";
import { Grid, GridCol, Icon } from "@design-system";
import { getCompany } from "@globalActions/company";
import { useRouter } from "next/navigation";
import { signIn } from "next-auth/react";
import { useEffect, useState } from "react";

export const SelectSiren = ({ sirenList, loadedSiren }: { loadedSiren?: string; sirenList: string[] }) => {
Expand All @@ -22,26 +24,34 @@ export const SelectSiren = ({ sirenList, loadedSiren }: { loadedSiren?: string;
}, [currentSiren, router, loadedSiren]);

return (
<Grid>
<GridCol sm={3}>
<Select
label="SIREN"
nativeSelectProps={{ onChange: event => setCurrentSiren(event.target.value), value: currentSiren }}
>
<option value="">Sélectionner un siren</option>
{sirenList.map((value, key) => (
<option key={`siren-${key}`} value={value}>
{value}
</option>
))}
</Select>
</GridCol>
<GridCol sm={9}>
<div className={fr.cx("fr-pt-10v", "fr-pl-2v")}>
<span className={fr.cx("fr-icon-building-line", "fr-pr-2v")} aria-hidden="true"></span>
<span>{selectedCompanyName}</span>
</div>
</GridCol>
</Grid>
<>
<Grid>
<GridCol sm={3}>
<Select
label="SIREN"
nativeSelectProps={{ onChange: event => setCurrentSiren(event.target.value), value: currentSiren }}
>
<option value="">Sélectionner un siren</option>
{sirenList.map((value, key) => (
<option key={`siren-${key}`} value={value}>
{value}
</option>
))}
</Select>
</GridCol>
<GridCol sm={6}>
<div className={fr.cx("fr-pt-10v", "fr-pl-2v")}>
<span className={fr.cx("fr-icon-building-line", "fr-pr-2v")} aria-hidden="true"></span>
<span>{selectedCompanyName}</span>
</div>
</GridCol>
</Grid>
<div className={fr.cx("fr-pt-2v")}>
<Button onClick={() => signIn("moncomptepro", { redirect: true })}>
<Icon icon="fr-icon-refresh-line" />
Rafraichir MCP
</Button>
</div>
</>
);
};
18 changes: 16 additions & 2 deletions packages/app/src/app/(default)/mon-espace/mes-entreprises/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@ const MesEntreprisesPage = async ({ searchParams }: NextServerPageProps<never, "
<p>
<br />
Vous souhaitez rattacher votre adresse mail à un autre Siren,{" "}
<Link href="https://app.moncomptepro.beta.gouv.fr/manage-organizations">cliquez ici</Link>
<Link
target="_blank"
href={`https://app${
config.api.security.moncomptepro.appTest ? "-sandbox" : ""
}.moncomptepro.beta.gouv.fr/manage-organizations`}
>
cliquez ici
</Link>
</p>
</Box>
{typeof selectedSiren === "string" && (
Expand All @@ -122,7 +129,14 @@ const MesEntreprisesPage = async ({ searchParams }: NextServerPageProps<never, "
<p>
<br />
Vous souhaitez rattacher votre adresse mail à un autre Siren,{" "}
<Link href="https://app.moncomptepro.beta.gouv.fr/manage-organizations">cliquez ici</Link>
<Link
target="_blank"
href={`https://app${
config.api.security.moncomptepro.appTest ? "-sandbox" : ""
}.moncomptepro.beta.gouv.fr/manage-organizations`}
>
cliquez ici
</Link>
</p>
</Box>
<Box mt="4w">Le siren fournit est invalide.</Box>
Expand Down

0 comments on commit 25beaae

Please sign in to comment.