From 015a049c141d2132d5fc8328cf891223da58cb1b Mon Sep 17 00:00:00 2001 From: folland87 Date: Fri, 20 Dec 2024 10:22:31 +0100 Subject: [PATCH 1/2] add siren update page --- src/components/blocs/sirene-updates/index.js | 92 ++++++++++++++++++++ src/navigation/index.js | 2 + src/pages/admin/index.js | 6 +- src/pages/admin/sirene.js | 20 +++++ 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/components/blocs/sirene-updates/index.js create mode 100644 src/pages/admin/sirene.js diff --git a/src/components/blocs/sirene-updates/index.js b/src/components/blocs/sirene-updates/index.js new file mode 100644 index 00000000..fda9a712 --- /dev/null +++ b/src/components/blocs/sirene-updates/index.js @@ -0,0 +1,92 @@ +import { Bloc, BlocContent, BlocTitle } from '../../bloc'; +import useFetch from '../../../hooks/useFetch'; +import Button from '../../button'; + +const getPaysageValue = (update, paysageData) => { + const { field } = update; + if (field === 'changementNicSiegeUniteLegale') return update.siret; + if (field === 'changementCategorieJuridiqueUniteLegale') { + return paysageData?.legalcategory?.inseeCode; + } + if (field === 'changementEtatAdministratifUniteLegale') { + return paysageData?.structureStatus; + } + if (field === 'changementDenominationUniteLegale') { + return paysageData?.displayName; + } + if (field === 'changementDenominationUsuelleUniteLegale') { + return paysageData?.currentName?.usualName; + } + return null; +}; +const getSireneValue = (update) => { + const { field } = update; + if (field === 'changementNicSiegeUniteLegale') return update.siren + update.value; + return update.value; +}; + +const DATE_DISPLAY_OPTIONS = { + year: 'numeric', + month: 'long', + day: 'numeric', +}; + +export default function SireneUpdates() { + const { data, isLoading, error } = useFetch('/sirene/updates'); + + if (isLoading) { + return null; + } + + const updates = data?.data?.filter((structure) => structure.updates.length > 0); + + return ( + + + Mises à jour Sirene + + + {updates?.map((structure) => ( +
+ {structure?.paysageData?.displayName} +

+ {`Dernière modification repérée dans la base sirene le ${new Date(structure?.lastModificationDate)?.toLocaleDateString('fr', DATE_DISPLAY_OPTIONS)}`} +

+ {structure.type === 'siren' &&

{`Suivi au niveau unité légale: ${structure?.siren}`}

} + {structure.type === 'siret' &&

{`Suivi au niveau établissement ${structure.siret}`}

} + {structure.updates.map((update) => ( +
+
+
+

{`${update.field}`}

+

{`Valeur sirene: ${getSireneValue(update)}`}

+

{`Valeur paysage: ${getPaysageValue(update, structure.paysageData)}`}

+
+
+ +
+
+ {!!(structure.updates.length > 0) &&
} +
+ ))} + {/* {structure.checks.map((update) => ( +
+

{`Vérification de ${update.field}`}

+

{`Valeur sirene: ${update.value}`}

+

{`Date de la dernière vérification: ${update.lastChecked}`}

+
+ ))} */} +
+
+ ))} +
+
+ ); +} diff --git a/src/navigation/index.js b/src/navigation/index.js index 2dfaff3c..a097d15c 100644 --- a/src/navigation/index.js +++ b/src/navigation/index.js @@ -63,6 +63,7 @@ import { AdminUsersPage, AdminGeographicalExceptionsPage, AdminGeographicalCategoriesPage, + AdminSirenePage, } from '../pages/admin'; import { AccountPage, PreferencesPage, ProfilePage, SecurityPage } from '../pages/mon-compte'; @@ -115,6 +116,7 @@ export default function Routes() { } /> } /> } /> + } /> } /> } /> } /> diff --git a/src/pages/admin/index.js b/src/pages/admin/index.js index dddfce14..96e3b056 100644 --- a/src/pages/admin/index.js +++ b/src/pages/admin/index.js @@ -10,6 +10,7 @@ import AdminJobsPage from './jobs'; import AdminJournalPage from './journal'; import AdminNomenclaturesPage from './nomenclatures'; import AdminGeographicalCategoriesPage from './categories-geographiques'; +import AdminSirenePage from './sirene'; import AdminRelationTypesPage from './relation-types'; import AdminUsersPage from './users'; @@ -90,6 +91,9 @@ function AdminPage() { }> Tâches du système + }> + Mises à jour Sirene + @@ -103,5 +107,5 @@ function AdminPage() { export { AdminDashboardPage, AdminPage, AdminUsersPage, AdminNomenclaturesPage, AdminJournalPage, AdminLegalCategoriesPage, AdminRelationTypesPage, AdminGroupsPage, AdminApiKeysPage, AdminJobsPage, - AdminGeographicalExceptionsPage, AdminGeographicalCategoriesPage, + AdminGeographicalExceptionsPage, AdminGeographicalCategoriesPage, AdminSirenePage, }; diff --git a/src/pages/admin/sirene.js b/src/pages/admin/sirene.js new file mode 100644 index 00000000..97c6af11 --- /dev/null +++ b/src/pages/admin/sirene.js @@ -0,0 +1,20 @@ +import { Breadcrumb, BreadcrumbItem, Col, Container, Row } from '@dataesr/react-dsfr'; +import { Link as RouterLink } from 'react-router-dom'; +import SireneUpdates from '../../components/blocs/sirene-updates'; + +export default function AdminJournalPage() { + return ( + + + + + }>Accueil + {/* }>Administration */} + Mises à jour Sirene + + + + + + ); +} From 1b60adaae322d13463fcbfc50fd9d50cfccb6650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Tue, 24 Dec 2024 12:03:37 +0100 Subject: [PATCH 2/2] feat(dates): Correct label for futures dates --- src/utils/dates.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/dates.js b/src/utils/dates.js index ff6bc59e..77d0c8a2 100644 --- a/src/utils/dates.js +++ b/src/utils/dates.js @@ -116,7 +116,7 @@ export function formatDescriptionDatesForMandateAndPrizes({ startDate = null, en } export function formatDescriptionDates(startDate = null, endDate = null) { - if (!startDate && !endDate) { return null; } + if (!startDate && !endDate) return null; if (!startDate && endDate) { if (endDate.split('-').length === 1) { return ` jusqu'à ${toString(endDate)}`; @@ -127,6 +127,12 @@ export function formatDescriptionDates(startDate = null, endDate = null) { return ` jusqu'au ${toString(endDate)}`; } if (startDate && !endDate) { + if (new Date(startDate) > new Date()) { + if (startDate.split('-').length !== 3) { + return ` à partir de ${toString(startDate)}`; + } + return ` à partir du ${toString(startDate)}`; + } if (startDate.split('-').length !== 3) { return ` depuis ${toString(startDate)}`; }