Skip to content

Commit

Permalink
Revert "Move association and protected certificat to server component" (
Browse files Browse the repository at this point in the history
#1053)

This reverts commit 0ddc22b.
  • Loading branch information
XavierJp committed May 15, 2024
1 parent 0ddc22b commit 7ad8552
Show file tree
Hide file tree
Showing 22 changed files with 292 additions and 206 deletions.
27 changes: 18 additions & 9 deletions app/(header-default)/entreprise/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import UsefulShortcuts from '#components/useful-shortcuts';
import { isAPINotResponding } from '#models/api-not-responding';
import { estNonDiffusible } from '#models/core/statut-diffusion';
import { isAssociation, isCollectiviteTerritoriale } from '#models/core/types';
import { getProtectedCertificats } from '#models/espace-agent/certificats';
import { getImmatriculationEORI } from '#models/espace-agent/immatriculation-eori';
import { getServicePublicByUniteLegale } from '#models/service-public';
import { EScope, hasRights } from '#models/user/rights';
Expand Down Expand Up @@ -55,14 +56,18 @@ export default async function UniteLegalePage(props: AppRouterProps) {
const session = await getSession();
const uniteLegale = await cachedGetUniteLegale(slug, isBot, page);

const [servicePublic, immatriculationEORI] = await Promise.all([
getServicePublicByUniteLegale(uniteLegale, {
isBot,
}),
hasRights(session, EScope.eori)
? getImmatriculationEORI(uniteLegale.siege.siret, session?.user)
: null,
]);
const [servicePublic, immatriculationEORI, privateCertificats] =
await Promise.all([
getServicePublicByUniteLegale(uniteLegale, {
isBot,
}),
hasRights(session, EScope.eori)
? getImmatriculationEORI(uniteLegale.siege.siret, session?.user)
: null,
hasRights(session, EScope.protectedCertificats)
? getProtectedCertificats(uniteLegale, session?.user)
: null,
]);

return (
<>
Expand All @@ -79,7 +84,11 @@ export default async function UniteLegalePage(props: AppRouterProps) {
<NonDiffusibleSection />
) : (
<>
<UniteLegaleSection uniteLegale={uniteLegale} session={session} />
<UniteLegaleSection
uniteLegale={uniteLegale}
session={session}
protectedCertificats={privateCertificats}
/>
{hasRights(session, EScope.isAgent) && (
<EspaceAgentSummarySection
immatriculationEORI={immatriculationEORI}
Expand Down

This file was deleted.

49 changes: 34 additions & 15 deletions app/(header-default)/labels-certificats/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
checkHasLabelsAndCertificates,
checkHasQuality,
} from '#components/badges-section/labels-and-certificates';
import { OpqibiSection } from '#components/espace-agent-components/certifications/opqibi-section';
import { QualibatSection } from '#components/espace-agent-components/certifications/qualibat-section';
import { QualifelecSection } from '#components/espace-agent-components/certifications/qualifelec-section';
import { CertificationsBioSection } from '#components/labels-and-certificates/bio';
import { EgaproSection } from '#components/labels-and-certificates/egapro';
import { CertificationsEntrepreneurSpectaclesSection } from '#components/labels-and-certificates/entrepreneur-spectacles';
Expand All @@ -15,6 +18,10 @@ import { CertificationSocieteMission } from '#components/labels-and-certificates
import Title from '#components/title-section';
import { FICHE } from '#components/title-section/tabs';
import { getCertificationsFromSlug } from '#models/certifications';
import {
getProtectedCertificats,
hasProtectedCertificatsEntreprise,
} from '#models/espace-agent/certificats';
import { EScope, hasRights } from '#models/user/rights';
import {
uniteLegalePageDescription,
Expand All @@ -25,7 +32,6 @@ import extractParamsAppRouter, {
AppRouterProps,
} from '#utils/server-side-helper/app/extract-params';
import getSession from '#utils/server-side-helper/app/get-session';
import { ProtectedCertificats } from './_components/protected-certificats';

export const generateMetadata = async (
props: AppRouterProps
Expand Down Expand Up @@ -64,15 +70,23 @@ const LabelsAndCertificatsPage = async (props: AppRouterProps) => {
estEntrepriseInclusive,
} = uniteLegale.complements;

const {
rge,
entrepreneurSpectacles,
egapro,
bio,
organismesDeFormation,
ess,
entrepriseInclusive,
} = await getCertificationsFromSlug(uniteLegale);
const [
{
rge,
entrepreneurSpectacles,
egapro,
bio,
organismesDeFormation,
ess,
entrepriseInclusive,
},
protectedCertificats,
] = await Promise.all([
getCertificationsFromSlug(uniteLegale),
hasRights(session, EScope.protectedCertificats)
? getProtectedCertificats(uniteLegale, session?.user)
: null,
]);

return (
<>
Expand All @@ -83,7 +97,8 @@ const LabelsAndCertificatsPage = async (props: AppRouterProps) => {
session={session}
/>
{!checkHasLabelsAndCertificates(uniteLegale) &&
!hasRights(session, EScope.protectedCertificats) && (
(!protectedCertificats ||
!hasProtectedCertificatsEntreprise(protectedCertificats)) && (
<p>Cette structure ne possède aucun label ou certificat.</p>
)}
{estEss && <CertificationESSSection ess={ess} />}
Expand Down Expand Up @@ -116,10 +131,14 @@ const LabelsAndCertificatsPage = async (props: AppRouterProps) => {
{estBio && (
<CertificationsBioSection uniteLegale={uniteLegale} bio={bio} />
)}
{hasRights(session, EScope.protectedCertificats) && (
<>
<ProtectedCertificats uniteLegale={uniteLegale} session={session} />
</>
{protectedCertificats && (
<QualifelecSection qualifelec={protectedCertificats.qualifelec} />
)}
{protectedCertificats && (
<QualibatSection qualibat={protectedCertificats.qualibat} />
)}
{protectedCertificats && (
<OpqibiSection opqibi={protectedCertificats.opqibi} />
)}
</div>
</>
Expand Down
31 changes: 31 additions & 0 deletions app/api/data-fetching/association/[slug]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { EAdministration } from '#models/administrations/EAdministration';
import { getAssociationFromSlug } from '#models/association';
import { FetchRessourceException } from '#models/exceptions';
import logErrorInSentry from '#utils/sentry';
import { withIgnoreBot } from '#utils/server-side-helper/app/with-anti-bot';

export const GET = withIgnoreBot(async function (
_request: Request,
{ params }: { params: { slug: string } }
) {
const slug = params.slug;
try {
const immatriculation = await getAssociationFromSlug(slug as string);
return Response.json(immatriculation, { status: 200 });
} catch (e: any) {
const message = 'Failed to fetch Association';

logErrorInSentry(
new FetchRessourceException({
cause: e,
ressource: 'Association',
administration: EAdministration.MI,
message,
context: {
slug: slug as string,
},
})
);
return Response.json({ message }, { status: e.status || 500 });
}
});
1 change: 1 addition & 0 deletions clients/routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const routes = {
api: {
association: '/api/data-fetching/association',
rne: {
documents: {
list: '/api/data-fetching/espace-agent/documents/',
Expand Down
7 changes: 4 additions & 3 deletions components-ui/alerts-with-explanations/association-adress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import {
getPersonnalDataAssociation,
} from '#models/core/statut-diffusion';
import { IAssociation } from '#models/core/types';
import { ISession } from '#models/user/session';
import useSession from 'hooks/use-session';
import { Warning } from '../alerts';

const AssociationAdressAlert: React.FC<{
uniteLegale: IAssociation;
association: IDataAssociation | IAPINotRespondingError | null;
session: ISession | null;
}> = ({ uniteLegale, association, session }) => {
}> = ({ uniteLegale, association }) => {
const session = useSession();

if (!association || isAPINotResponding(association)) {
return null;
}
Expand Down
101 changes: 56 additions & 45 deletions components/association-section/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
'use client';

import AssociationAdressAlert from '#components-ui/alerts-with-explanations/association-adress';
import { HorizontalSeparator } from '#components-ui/horizontal-separator';
import BreakPageForPrint from '#components-ui/print-break-page';
import { Tag } from '#components-ui/tag';
import { AsyncDataSectionServer } from '#components/section/data-section/server';
import { Section } from '#components/section';
import { AsyncDataSectionClient } from '#components/section/data-section/client';
import { TwoColumnTable } from '#components/table/simple';
import { EAdministration } from '#models/administrations/EAdministration';
import { getAssociationFromSlug } from '#models/association';
import { IDataAssociation } from '#models/association/types';
import { getPersonnalDataAssociation } from '#models/core/statut-diffusion';
import { IAssociation, IUniteLegale } from '#models/core/types';
import { ISession } from '#models/user/session';
import { IdRna, formatDate, formatIntFr } from '#utils/helpers';
import { useFetchAssociation } from 'hooks/fetch/association';
import { AssociationNotFound } from './association-not-found';

const getTableData = (
Expand Down Expand Up @@ -130,58 +133,66 @@ const AssociationSection = ({
}) => {
const { idAssociation = '' } = uniteLegale.association;

const association = getAssociationFromSlug(uniteLegale.siren);
const association = useFetchAssociation(uniteLegale.siren);

if (!association) {
// Data can be null if the natureJuridique is an association,
// but no idAssociation is provided by Insee API call.
return (
<Section
title={`Répertoire National des Associations`}
sources={[EAdministration.MI]}
>
<AssociationNotFound uniteLegale={uniteLegale} />;
</Section>
);
}

return (
<>
<AsyncDataSectionServer
<AsyncDataSectionClient
title="Répertoire National des Associations"
sources={[EAdministration.MI]}
data={association}
notFoundInfo={<AssociationNotFound uniteLegale={uniteLegale} />}
>
{(association) =>
!association ? (
<AssociationNotFound uniteLegale={uniteLegale} />
) : (
<>
<AssociationAdressAlert
uniteLegale={uniteLegale}
session={session}
association={association}
/>
<p>
Cette structure est inscrite au{' '}
<strong>Répertoire National des Associations (RNA)</strong>,
avec les informations suivantes&nbsp;:
</p>
<TwoColumnTable
body={getTableData(
idAssociation,
association,
uniteLegale,
session
)}
/>
{idAssociation && (
<>
<br />
Retrouvez plus d&apos;informations (comptes, effectifs et
documents administratifs) sur la{' '}
<a
target="_blank"
href={`https://www.data-asso.fr/annuaire/association/${idAssociation}?docFields=documentsDac,documentsRna`}
rel="noopener noreferrer"
>
fiche data-asso de cette association
</a>
.
</>
{(association) => (
<>
<AssociationAdressAlert
uniteLegale={uniteLegale}
association={association}
/>
<p>
Cette structure est inscrite au{' '}
<strong>Répertoire National des Associations (RNA)</strong>, avec
les informations suivantes&nbsp;:
</p>
<TwoColumnTable
body={getTableData(
idAssociation,
association,
uniteLegale,
session
)}
</>
)
}
</AsyncDataSectionServer>
/>
{idAssociation && (
<>
<br />
Retrouvez plus d&apos;informations (comptes, effectifs et
documents administratifs) sur la{' '}
<a
target="_blank"
href={`https://www.data-asso.fr/annuaire/association/${idAssociation}?docFields=documentsDac,documentsRna`}
rel="noopener noreferrer"
>
fiche data-asso de cette association
</a>
.
</>
)}
</>
)}
</AsyncDataSectionClient>
<HorizontalSeparator />
<BreakPageForPrint />
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import { Icon } from '#components-ui/icon/wrapper';
import { isAPINotResponding } from '#models/api-not-responding';
import constants from '#models/constants';
import { getOpqibi } from '#models/espace-agent/certificats/opqibi';
import { getQualibat } from '#models/espace-agent/certificats/qualibat';
import { getQualifelec } from '#models/espace-agent/certificats/qualifelec';
import { ISession } from '#models/user/session';
import { IProtectedCertificatsEntreprise } from '#models/espace-agent/certificats';
import { IUniteLegale } from '../../../models/core/types';
import { LabelWithLinkToSection } from './label-with-link-to-section';

export const ProtectedCertificatesBadgesSection: React.FC<{
uniteLegale: IUniteLegale;
session: ISession | null;
}> = async ({ uniteLegale, session }) => {
const [opqibi, qualifelec, qualibat] = await Promise.all([
getOpqibi(uniteLegale.siren, session?.user?.siret),
getQualifelec(uniteLegale.siege.siret, session?.user?.siret),
getQualibat(uniteLegale.siege.siret, session?.user?.siret),
]);
protectedCertificats: IProtectedCertificatsEntreprise | null;
}> = ({ uniteLegale, protectedCertificats }) => {
if (!protectedCertificats) {
return null;
}
const { opqibi, qualibat, qualifelec } = protectedCertificats;

if (
isAPINotResponding(opqibi) &&
Expand Down
Loading

0 comments on commit 7ad8552

Please sign in to comment.