From a06ccf85f7f8495e499fec1932fc27613c6e7644 Mon Sep 17 00:00:00 2001 From: Robin Monnier Date: Fri, 11 Oct 2024 16:00:23 +0200 Subject: [PATCH] feat: remove status col, add isProtected, create component, add agent wall --- .../agent-wall/subventions-association.tsx | 13 +++ .../subventions-association-section/index.tsx | 99 +++++++++++++------ models/subventions/association/index.ts | 2 +- 3 files changed, 81 insertions(+), 33 deletions(-) create mode 100644 components/espace-agent-components/agent-wall/subventions-association.tsx diff --git a/components/espace-agent-components/agent-wall/subventions-association.tsx b/components/espace-agent-components/agent-wall/subventions-association.tsx new file mode 100644 index 000000000..ee3625632 --- /dev/null +++ b/components/espace-agent-components/agent-wall/subventions-association.tsx @@ -0,0 +1,13 @@ +import { IUniteLegale } from '#models/core/types'; +import { PropsWithChildren } from 'react'; +import AgentWall from '.'; + +const AgentWallSubventionsAssociation: React.FC< + PropsWithChildren<{ + title: string; + id: string; + uniteLegale: IUniteLegale; + }> +> = ({ uniteLegale, id, title }) => ; + +export default AgentWallSubventionsAssociation; diff --git a/components/subventions-association-section/index.tsx b/components/subventions-association-section/index.tsx index 1ec7757f0..97ecafba7 100644 --- a/components/subventions-association-section/index.tsx +++ b/components/subventions-association-section/index.tsx @@ -2,13 +2,51 @@ import { Tag } from '#components-ui/tag'; import { DataSubvention } from '#components/administrations'; +import AgentWallSubventionsAssociation from '#components/espace-agent-components/agent-wall/subventions-association'; import { DataSectionClient } from '#components/section/data-section'; import { FullTable } from '#components/table/full'; import { EAdministration } from '#models/administrations/EAdministration'; import { IAssociation } from '#models/core/types'; +import { ISubventions } from '#models/subventions/association'; +import { AppScope, hasRights } from '#models/user/rights'; import { ISession } from '#models/user/session'; import { formatCurrency } from '#utils/helpers'; import { useAPIRouteData } from 'hooks/fetch/use-API-route-data'; +import { useMemo } from 'react'; + +const SubventionDetails: React.FC<{ subventions: ISubventions }> = ({ + subventions, +}) => { + const subventionStats = useMemo(() => { + const totalSubventions = subventions.length; + const mostRecentYear = subventions[totalSubventions - 1]?.year; + const approvedSubventions = subventions.filter( + (subvention) => subvention.label === 'Accordé' + ); + const totalApproved = approvedSubventions.length; + const totalAmount = approvedSubventions.reduce( + (acc, subvention) => acc + subvention.amount, + 0 + ); + + return { + totalSubventions, + mostRecentYear, + totalApproved, + totalAmount, + }; + }, [subventions]); + + return ( +

+ Cette association a demandé {subventionStats.totalSubventions}{' '} + subvention(s) depuis {subventionStats.mostRecentYear} dont{' '} + {subventionStats.totalApproved} accordée(s) pour un total de{' '} + {formatCurrency(subventionStats.totalAmount)}. Ces données sont + collectées par . +

+ ); +}; export const SubventionsAssociationSection: React.FC<{ uniteLegale: IAssociation; @@ -19,56 +57,53 @@ export const SubventionsAssociationSection: React.FC<{ uniteLegale.siren, session ); - if (!subventions) return null; + + if (!hasRights(session, AppScope.none)) { + return ( + + ); + } return ( {(subventions) => - subventions.length === 0 ? ( + !subventions || subventions?.length === 0 ? ( <> Aucune demande de subvention n’a été trouvée pour cette association. ) : ( <> -

- Voici le détail des subventions demandées par l’association. Ces - données sont collectées par . -

+ [ {subvention.year}, {subvention.description}, formatCurrency(subvention.amount), - // TODO Component - - {subvention.status} - , - // TODO Component - - {subvention.label} - , + subvention.label && ( + + {subvention.label} + + ), ])} /> diff --git a/models/subventions/association/index.ts b/models/subventions/association/index.ts index 0134b7abe..779f003e4 100644 --- a/models/subventions/association/index.ts +++ b/models/subventions/association/index.ts @@ -21,7 +21,7 @@ export interface ISubvention { export const getSubventionsAssociationFromSlug = async ( slug: string -): Promise => { +): Promise => { const uniteLegale = await getUniteLegaleFromSlug(slug, { isBot: false, });