Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Dec 24, 2024
2 parents 0c470f5 + 1b60ada commit 2853ade
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
92 changes: 92 additions & 0 deletions src/components/blocs/sirene-updates/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<Bloc isLoading={isLoading} error={error} data={data} forceActionDisplay>
<BlocTitle as="h1" look="h4">
Mises à jour Sirene
</BlocTitle>
<BlocContent>
{updates?.map((structure) => (
<div key={structure.id}>
<a rel="noreferrer" target="_blank" href={structure?.paysageData?.href} className="fr-link fr-text--md fr-text--bold fr-mb-0">{structure?.paysageData?.displayName}</a>
<p className="fr-card__detail fr-mb-0">
{`Dernière modification repérée dans la base sirene le ${new Date(structure?.lastModificationDate)?.toLocaleDateString('fr', DATE_DISPLAY_OPTIONS)}`}
</p>
{structure.type === 'siren' && <p className="fr-card__detail fr-mb-2w">{`Suivi au niveau unité légale: ${structure?.siren}`}</p>}
{structure.type === 'siret' && <p className="fr-card__detail fr-mb-2w">{`Suivi au niveau établissement ${structure.siret}`}</p>}
{structure.updates.map((update) => (
<div>
<div style={{ display: 'flex', alignItems: 'center' }} key={update.id}>
<div style={{ flexGrow: 1 }} key={update.id}>
<p className="fr-text--sm fr-text--bold fr-mb-1v">{`${update.field}`}</p>
<p className="fr-text--sm fr-mb-1v">{`Valeur sirene: ${getSireneValue(update)}`}</p>
<p className="fr-text--sm fr-mb-0">{`Valeur paysage: ${getPaysageValue(update, structure.paysageData)}`}</p>
</div>
<div>
<Button
size="sm"
type="button"
tertiary
borderless
>
Marquer comme vérifié
</Button>
</div>
</div>
{!!(structure.updates.length > 0) && <hr style={{ width: '40%' }} />}
</div>
))}
{/* {structure.checks.map((update) => (
<div key={update.id}>
<p>{`Vérification de ${update.field}`}</p>
<p>{`Valeur sirene: ${update.value}`}</p>
<p>{`Date de la dernière vérification: ${update.lastChecked}`}</p>
</div>
))} */}
<hr />
</div>
))}
</BlocContent>
</Bloc>
);
}
2 changes: 2 additions & 0 deletions src/navigation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
AdminUsersPage,
AdminGeographicalExceptionsPage,
AdminGeographicalCategoriesPage,
AdminSirenePage,
} from '../pages/admin';

import { AccountPage, PreferencesPage, ProfilePage, SecurityPage } from '../pages/mon-compte';
Expand Down Expand Up @@ -115,6 +116,7 @@ export default function Routes() {
<Route path="categories-juridiques" element={<AdminLegalCategoriesPage />} />
<Route path="types-de-relation" element={<AdminRelationTypesPage />} />
<Route path="taches" element={<AdminJobsPage />} />
<Route path="sirene" element={<AdminSirenePage />} />
<Route path="nomenclatures" element={<Navigate to="nomenclatures/types-de-document" replace />} />
<Route path="nomenclatures/types-de-document" element={<AdminNomenclaturesPage route="/document-types" title="Types de documents" />} />
<Route path="nomenclatures/ministres-de-tutelle" element={<AdminNomenclaturesPage route="/supervising-ministers" title="Ministres de tutelle" />} />
Expand Down
6 changes: 5 additions & 1 deletion src/pages/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -90,6 +91,9 @@ function AdminPage() {
<SideMenuLink className={(page === 'taches') && 'sidemenu__item--active'} asLink={<RouterLink to="/admin/taches" replace />}>
Tâches du système
</SideMenuLink>
<SideMenuLink className={(page === 'sirene') && 'sidemenu__item--active'} asLink={<RouterLink to="/admin/sirene" replace />}>
Mises à jour Sirene
</SideMenuLink>
</SideMenu>
</Col>
<Col n="12 md-9">
Expand All @@ -103,5 +107,5 @@ function AdminPage() {
export {
AdminDashboardPage, AdminPage, AdminUsersPage, AdminNomenclaturesPage, AdminJournalPage,
AdminLegalCategoriesPage, AdminRelationTypesPage, AdminGroupsPage, AdminApiKeysPage, AdminJobsPage,
AdminGeographicalExceptionsPage, AdminGeographicalCategoriesPage,
AdminGeographicalExceptionsPage, AdminGeographicalCategoriesPage, AdminSirenePage,
};
20 changes: 20 additions & 0 deletions src/pages/admin/sirene.js
Original file line number Diff line number Diff line change
@@ -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 (
<Container>
<Row>
<Col>
<Breadcrumb>
<BreadcrumbItem asLink={<RouterLink to="/" />}>Accueil</BreadcrumbItem>
{/* <BreadcrumbItem asLink={<RouterLink to="/admin" />}>Administration</BreadcrumbItem> */}
<BreadcrumbItem>Mises à jour Sirene</BreadcrumbItem>
</Breadcrumb>
</Col>
</Row>
<SireneUpdates />
</Container>
);
}
8 changes: 7 additions & 1 deletion src/utils/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
Expand All @@ -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)}`;
}
Expand Down

0 comments on commit 2853ade

Please sign in to comment.