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

fix: mpc refresh #2322

Merged
merged 7 commits into from
Jul 22, 2024
Merged
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
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
Loading