-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prefer the use of async client call # Conflicts: # app/(header-default)/documents/[slug]/_components/actes-section.tsx # app/(header-default)/documents/[slug]/page.tsx
- Loading branch information
1 parent
febbcaa
commit 44ea3e9
Showing
14 changed files
with
447 additions
and
86 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
app/(header-default)/documents/[slug]/_components/actes-section.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
'use client'; | ||
import routes from '#clients/routes'; | ||
import { Warning } from '#components-ui/alerts'; | ||
import ButtonLink from '#components-ui/button'; | ||
import ShowMore from '#components-ui/show-more'; | ||
import { AsyncDataSectionClient } from '#components/section/data-section/client'; | ||
import { FullTable } from '#components/table/full'; | ||
import { EAdministration } from '#models/administrations/EAdministration'; | ||
import { | ||
IUniteLegale, | ||
isAssociation, | ||
isServicePublic, | ||
} from '#models/core/types'; | ||
import { IActesRNE } from '#models/immatriculation'; | ||
import { formatDateLong } from '#utils/helpers'; | ||
import useFetchRNEDocuments from 'hooks/fetch/RNE-documents'; | ||
|
||
const NoDocument = () => ( | ||
<>Aucun document n’a été retrouvé dans le RNE pour cette entreprise.</> | ||
); | ||
|
||
export default function AgentActesSection({ | ||
uniteLegale, | ||
}: { | ||
uniteLegale: IUniteLegale; | ||
}) { | ||
const documents = useFetchRNEDocuments(uniteLegale); | ||
return ( | ||
<AsyncDataSectionClient | ||
title={'Actes et statuts'} | ||
id={'actes'} | ||
isProtected | ||
sources={[EAdministration.INPI]} | ||
data={documents} | ||
notFoundInfo={ | ||
<> | ||
{(isAssociation(uniteLegale) || isServicePublic(uniteLegale)) && ( | ||
<> | ||
<Warning full> | ||
Les associations et les services publics ne sont pas | ||
immatriculés au RNE. | ||
</Warning> | ||
<br /> | ||
</> | ||
)} | ||
<NoDocument /> | ||
</> | ||
} | ||
> | ||
{(documents) => ( | ||
<> | ||
<p> | ||
Cette entreprise possède {documents.actes.length} document(s) au | ||
RNE. Chaque document peut contenir un ou plusieurs actes : | ||
</p> | ||
{documents.actes.length >= 5 ? ( | ||
<ShowMore | ||
label={`Voir les ${ | ||
documents.actes.length - 5 | ||
} documents supplémentaires`} | ||
> | ||
<ActesTable actes={documents.actes} /> | ||
</ShowMore> | ||
) : ( | ||
<ActesTable actes={documents.actes} /> | ||
)} | ||
</> | ||
)} | ||
</AsyncDataSectionClient> | ||
); | ||
} | ||
|
||
type IActesTableProps = { | ||
actes: IActesRNE['actes']; | ||
}; | ||
function ActesTable({ actes }: IActesTableProps) { | ||
return ( | ||
<FullTable | ||
head={['Date de dépôt', 'Acte(s) contenu(s)', 'Lien']} | ||
body={actes.map((a) => [ | ||
formatDateLong(a.dateDepot), | ||
a.actes && ( | ||
<ul> | ||
{(a?.actes || []).map((acteName) => ( | ||
<li key={acteName}>{acteName}</li> | ||
))} | ||
</ul> | ||
), | ||
<ButtonLink | ||
target="_blank" | ||
alt | ||
small | ||
to={`${routes.api.rne.documents.download}${a.id}?type=acte`} | ||
> | ||
Télécharger | ||
</ButtonLink>, | ||
])} | ||
/> | ||
); | ||
} |
57 changes: 57 additions & 0 deletions
57
app/(header-default)/documents/[slug]/_components/carte-professionnelle-TP-section.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use client'; | ||
|
||
import ButtonLink from '#components-ui/button'; | ||
import { Icon } from '#components-ui/icon/wrapper'; | ||
import { AsyncDataSectionClient } from '#components/section/data-section/client'; | ||
import { EAdministration } from '#models/administrations/EAdministration'; | ||
import { IUniteLegale } from '#models/core/types'; | ||
import useFetchCarteProfessionnelleTP from 'hooks/fetch/carte-professionnelle-TP'; | ||
|
||
export default function CarteProfessionnelleTPSection({ | ||
uniteLegale, | ||
}: { | ||
uniteLegale: IUniteLegale; | ||
}) { | ||
const carteProfessionnelleTravauxPublics = | ||
useFetchCarteProfessionnelleTP(uniteLegale); | ||
|
||
return ( | ||
<AsyncDataSectionClient | ||
title="Carte professionnelle travaux publics" | ||
id="carte-professionnelle-travaux-publics" | ||
isProtected | ||
notFoundInfo={ | ||
'Aucune carte professionnelle trouvée pour cette entreprise' | ||
} | ||
sources={[EAdministration.FNTP]} | ||
data={carteProfessionnelleTravauxPublics} | ||
> | ||
{(data) => ( | ||
<> | ||
<p> | ||
Cette entreprise possède une{' '} | ||
<a | ||
href="https://www.fntp.fr/tout-savoir-sur-la-carte-professionnelle-tp" | ||
aria-label="En savoir plus sur la carte professionnelle d’entrepreneur de travaux publics, nouvelle fenêtre" | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
carte professionnelle d’entrepreneur de travaux publics | ||
</a> | ||
, délivrée par la FNTP. | ||
</p> | ||
|
||
<div className="layout-center"> | ||
<ButtonLink | ||
target="_blank" | ||
ariaLabel="Télécharger le justificatif de la carte professionnelle travaux publics, téléchargement dans une nouvelle fenêtre" | ||
to={`${data.documentUrl}`} | ||
> | ||
<Icon slug="download">Télécharger le justificatif</Icon> | ||
</ButtonLink> | ||
</div> | ||
</> | ||
)} | ||
</AsyncDataSectionClient> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
app/(header-default)/documents/[slug]/_components/conformite-section.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
import Conformite from '#components/espace-agent-components/conformite'; | ||
import { AsyncDataSectionClient } from '#components/section/data-section/client'; | ||
import { TwoColumnTable } from '#components/table/simple'; | ||
import { EAdministration } from '#models/administrations/EAdministration'; | ||
import { IUniteLegale } from '#models/core/types'; | ||
import useFetchConformite from 'hooks/fetch/conformite'; | ||
|
||
function ConformiteSection({ uniteLegale }: { uniteLegale: IUniteLegale }) { | ||
const conformite = useFetchConformite(uniteLegale); | ||
|
||
return ( | ||
<AsyncDataSectionClient | ||
title={'Conformité'} | ||
id={'conformite'} | ||
isProtected | ||
sources={[ | ||
EAdministration.DGFIP, | ||
EAdministration.URSSAF, | ||
EAdministration.MSA, | ||
]} | ||
data={conformite} | ||
> | ||
{(conformite) => ( | ||
<TwoColumnTable | ||
body={[ | ||
['Conformité fiscale', <Conformite data={conformite?.fiscale} />], | ||
[ | ||
'Conformité sociale', | ||
<> | ||
<Conformite | ||
data={conformite?.vigilance} | ||
administration="Urssaf" | ||
/> | ||
<br /> | ||
<Conformite data={conformite?.msa} administration="MSA" /> | ||
</>, | ||
], | ||
]} | ||
/> | ||
)} | ||
</AsyncDataSectionClient> | ||
); | ||
} | ||
|
||
export default ConformiteSection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/api/data-fetching/espace-agent/RNE-documents/[slug]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { EAdministration } from '#models/administrations/EAdministration'; | ||
import { getDocumentsRNEProtected } from '#models/immatriculation/rne'; | ||
import { EScope } from '#models/user/rights'; | ||
import { verifySiren } from '#utils/helpers'; | ||
import { ProtectedAPIRoute } from '../../_helper'; | ||
|
||
export async function GET( | ||
_request: Request, | ||
{ params }: { params: { slug: string } } | ||
) { | ||
const slug = params.slug; | ||
return ProtectedAPIRoute( | ||
'RNEDocuments', | ||
slug, | ||
EAdministration.INPI, | ||
EScope.documentsRne, | ||
async () => { | ||
const siren = verifySiren(slug as string); | ||
return getDocumentsRNEProtected(siren); | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { HttpForbiddenError } from '#clients/exceptions'; | ||
import { EAdministration } from '#models/administrations/EAdministration'; | ||
import { FetchRessourceException } from '#models/exceptions'; | ||
import { EScope, hasRights } from '#models/user/rights'; | ||
import { logFatalErrorInSentry } from '#utils/sentry'; | ||
import getSession from '#utils/server-side-helper/app/get-session'; | ||
|
||
export async function ProtectedAPIRoute<T>( | ||
routeLabel: string, | ||
slug: string, | ||
administration: EAdministration, | ||
scope: EScope, | ||
run: (agentSiret: string) => Promise<T> | ||
) { | ||
const session = await getSession(); | ||
try { | ||
if (!hasRights(session, scope)) { | ||
throw new HttpForbiddenError('Unauthorized account'); | ||
} | ||
|
||
const agentSiret = session?.user?.siret || 'Inconnu'; | ||
|
||
const data = await run(agentSiret); | ||
return Response.json(data, { status: 200 }); | ||
} catch (e: any) { | ||
const message = `Failed to get donnees ${routeLabel}`; | ||
logFatalErrorInSentry( | ||
new FetchRessourceException({ | ||
ressource: routeLabel, | ||
context: { slug }, | ||
cause: e, | ||
administration, | ||
}) | ||
); | ||
return Response.json({ message }, { status: e.status || 500 }); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/api/data-fetching/espace-agent/carte-professionnelle-TP/[slug]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { EAdministration } from '#models/administrations/EAdministration'; | ||
import { getCarteProfessionnelleTravauxPublic } from '#models/espace-agent/carte-professionnelle-travaux-publics'; | ||
import { EScope } from '#models/user/rights'; | ||
import { Siret, extractSirenFromSiret, verifySiret } from '#utils/helpers'; | ||
import { ProtectedAPIRoute } from '../../_helper'; | ||
|
||
export async function GET( | ||
_request: Request, | ||
{ params }: { params: { slug: string } } | ||
) { | ||
const slug = params.slug; | ||
return ProtectedAPIRoute( | ||
'CarteProfessionnelleTravauxPublics', | ||
slug, | ||
EAdministration.FNTP, | ||
EScope.conformite, | ||
async (agentSiret: string) => { | ||
const siret = verifySiret(slug as string); | ||
const siren = extractSirenFromSiret(siret); | ||
|
||
return await getCarteProfessionnelleTravauxPublic( | ||
siren, | ||
agentSiret as Siret | ||
); | ||
} | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
app/api/data-fetching/espace-agent/conformite/[slug]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { EAdministration } from '#models/administrations/EAdministration'; | ||
import { getConformiteEntreprise } from '#models/espace-agent/conformite'; | ||
import { EScope } from '#models/user/rights'; | ||
import { extractSirenFromSiret, verifySiret } from '#utils/helpers'; | ||
import { ProtectedAPIRoute } from '../../_helper'; | ||
|
||
export async function GET( | ||
_request: Request, | ||
{ params }: { params: { slug: string } } | ||
) { | ||
const slug = params.slug; | ||
return ProtectedAPIRoute( | ||
'DonneesConformite', | ||
slug, | ||
EAdministration.DINUM, | ||
EScope.conformite, | ||
async (agentSiret: string) => { | ||
const siret = verifySiret(slug as string); | ||
const siren = extractSirenFromSiret(siret); | ||
|
||
return await getConformiteEntreprise(siren, siret, agentSiret); | ||
} | ||
); | ||
} |
Oops, something went wrong.