Skip to content

Commit

Permalink
feat: add declarations page
Browse files Browse the repository at this point in the history
  • Loading branch information
jonat75 committed Dec 8, 2023
1 parent 5daaff4 commit 6502359
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
19 changes: 19 additions & 0 deletions packages/app/src/app/(default)/mon-espace/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { declarationRepo } from "@api/core-domain/repo";
import { GetAllDeclarationsBySiren } from "@api/core-domain/useCases/GetAllDeclarationsBySiren";
import { assertServerSession } from "@api/utils/auth";

export async function getAllDeclarationsBySiren(siren: string) {
await assertServerSession({
owner: {
check: siren,
message: "Not authorized to fetch declarations for this siren.",
},
staff: true,
});

// handle default errors
const useCase = new GetAllDeclarationsBySiren(declarationRepo);
const declarations = await useCase.execute({ siren });

return declarations;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
export const IndexList = () => {
import Table from "@codegouvfr/react-dsfr/Table";
import { type DeclarationDTO } from "@common/core-domain/dtos/DeclarationDTO";

export const IndexList = ({ declarations }: { declarations: DeclarationDTO[] }) => {
const headers = [
"Siren",
"Année indicateur",
"Structure",
"Tranche d'effectif",
"Date de transmission",
"Index",
"Objectif et mesures",
];

const data = declarations.map(declaration => [
declaration.commencer?.siren,
declaration.commencer?.annéeIndicateurs,
declaration.entreprise?.type,
declaration.entreprise?.tranche,
declaration["declaration-existante"].date,
declaration["resultat-global"]?.index,
declaration["resultat-global"]?.mesures,
]);
return (
<div>
<h1>IndexList</h1>
<h1>Mes Déclarations</h1>
<Table headers={headers} data={data}></Table>;
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { authConfig } from "@api/core-domain/infra/auth/config";
import { MessageProvider } from "@design-system/client";
import { type Session } from "next-auth";
import { first } from "lodash";
import { getServerSession, type Session } from "next-auth";

import { getAllDeclarationsBySiren } from "../actions";
import { IndexList } from "./IndexList";

const canEditSiren = (user?: Session["user"]) => (siren?: string) => {
Expand All @@ -9,10 +12,22 @@ const canEditSiren = (user?: Session["user"]) => (siren?: string) => {
};

const MesDeclarationsPage = async () => {
const session = await getServerSession(authConfig);
const siren = first(session?.user.companies)?.siren;
let declarations;

if (!siren) return null;

try {
declarations = await getAllDeclarationsBySiren(siren);
} catch {
return null;
}

return (
<MessageProvider>
<IndexList />
{/* <RepeqList /> */}
<IndexList declarations={declarations} />
{/*<RepeqList /> */}
</MessageProvider>
);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/app/AuthHeaderItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const UserHeaderItem = () => {
quickAccessItem={{
iconId: isStaff ? "fr-icon-github-line" : "fr-icon-account-fill",
text: `${session.data.user.email}${isStaff ? " (staff)" : ""}`,
linkProps: { href: "/index-egapro/tableauDeBord/mon-profil" },
linkProps: { href: "/mon-espace/mon-profil" },
}}
/>
);
Expand Down

0 comments on commit 6502359

Please sign in to comment.