Skip to content

Commit

Permalink
Revert "Revert "Move association and protected certificat to server c…
Browse files Browse the repository at this point in the history
…omponent"" (#1054)

* Revert "Revert "Move association and protected certificat to server component…"

This reverts commit 7ad8552.

* fix: notFoundInfo null should not display section

Loader appears sooner.

fix #1057

* fix: hide association & RNE for bots

fix #1056

* fix: add no certificat found explanation when no certificats are found

---------

Co-authored-by: Johan Girod <[email protected]>
  • Loading branch information
XavierJp and johangirod committed May 15, 2024
1 parent 3f8460b commit 7b925d1
Show file tree
Hide file tree
Showing 26 changed files with 262 additions and 313 deletions.
11 changes: 8 additions & 3 deletions app/(header-default)/dirigeants/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ const DirigeantsPage = async (props: AppRouterProps) => {
{servicePublic ? (
<ResponsableSection servicePublic={servicePublic} />
) : (
<Suspense fallback={<PageLoader />}>
<DirigeantInformation uniteLegale={uniteLegale} session={session} />
</Suspense>
!isBot && (
<Suspense fallback={<PageLoader />}>
<DirigeantInformation
uniteLegale={uniteLegale}
session={session}
/>
</Suspense>
)
)}
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async function MandatairesRCSSection({
id="rne-dirigeants"
title="Dirigeant(s)"
isProtected
notFoundInfo={null}
sources={[EAdministration.INFOGREFFE]}
data={mandatairesRCS}
>
Expand Down
29 changes: 10 additions & 19 deletions app/(header-default)/entreprise/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ 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 @@ -56,18 +55,14 @@ export default async function UniteLegalePage(props: AppRouterProps) {
const session = await getSession();
const uniteLegale = await cachedGetUniteLegale(slug, isBot, page);

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,
]);
const [servicePublic, immatriculationEORI] = await Promise.all([
getServicePublicByUniteLegale(uniteLegale, {
isBot,
}),
hasRights(session, EScope.eori)
? getImmatriculationEORI(uniteLegale.siege.siret, session?.user)
: null,
]);

return (
<>
Expand All @@ -84,11 +79,7 @@ export default async function UniteLegalePage(props: AppRouterProps) {
<NonDiffusibleSection />
) : (
<>
<UniteLegaleSection
uniteLegale={uniteLegale}
session={session}
protectedCertificats={privateCertificats}
/>
<UniteLegaleSection uniteLegale={uniteLegale} session={session} />
{hasRights(session, EScope.isAgent) && (
<EspaceAgentSummarySection
immatriculationEORI={immatriculationEORI}
Expand All @@ -112,7 +103,7 @@ export default async function UniteLegalePage(props: AppRouterProps) {
<BreakPageForPrint />
</>
)}
{isAssociation(uniteLegale) && (
{!isBot && isAssociation(uniteLegale) && (
<AssociationSection uniteLegale={uniteLegale} session={session} />
)}
<UsefulShortcuts uniteLegale={uniteLegale} />
Expand Down
16 changes: 9 additions & 7 deletions app/(header-default)/justificatif/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ const JustificatifPage = async (props: AppRouterProps) => {
ficheType={FICHE.JUSTIFICATIFS}
session={session}
/>
<Suspense fallback={<PageLoader />}>
<Immatriculations
uniteLegale={uniteLegale}
immatriculationJOAFE={immatriculationJOAFE}
session={session}
/>
</Suspense>
{!isBot && (
<Suspense fallback={<PageLoader />}>
<Immatriculations
uniteLegale={uniteLegale}
immatriculationJOAFE={immatriculationJOAFE}
session={session}
/>
</Suspense>
)}
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Suspense } from 'react';
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 {
IAPINotRespondingError,
isAPINotResponding,
} from '#models/api-not-responding';
import { IUniteLegale } from '#models/core/types';
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';

type IProps = {
uniteLegale: IUniteLegale;
session: ISession | null;
hasOtherCertificates: boolean;
};

export async function ProtectedCertificats({
uniteLegale,
session,
hasOtherCertificates,
}: IProps) {
const opqibi = getOpqibi(uniteLegale.siren, session?.user?.siret);
const qualifelec = getQualifelec(
uniteLegale.siege.siret,
session?.user?.siret
);
const qualibat = getQualibat(uniteLegale.siege.siret, session?.user?.siret);

return (
<>
{!hasOtherCertificates && (
<Suspense>
<NoCertificatsWarning certificats={[opqibi, qualifelec, qualibat]} />
</Suspense>
)}
<QualibatSection qualibat={qualibat} />
<QualifelecSection qualifelec={qualifelec} />
<OpqibiSection opqibi={opqibi} />
</>
);
}

async function NoCertificatsWarning({
certificats: certificatsPromise,
}: {
certificats: Promise<IAPINotRespondingError | unknown>[];
}) {
const certificats = await Promise.all(certificatsPromise);
if (certificats.every((certificat) => isAPINotResponding(certificat))) {
return <p>Aucun certificat n’a été trouvé pour cette entreprise.</p>;
}
return null;
}
51 changes: 17 additions & 34 deletions app/(header-default)/labels-certificats/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ 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 @@ -18,10 +15,6 @@ 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 @@ -32,6 +25,7 @@ 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 @@ -70,23 +64,15 @@ const LabelsAndCertificatsPage = async (props: AppRouterProps) => {
estEntrepriseInclusive,
} = uniteLegale.complements;

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

return (
<>
Expand All @@ -97,8 +83,7 @@ const LabelsAndCertificatsPage = async (props: AppRouterProps) => {
session={session}
/>
{!checkHasLabelsAndCertificates(uniteLegale) &&
(!protectedCertificats ||
!hasProtectedCertificatsEntreprise(protectedCertificats)) && (
!hasRights(session, EScope.protectedCertificats) && (
<p>Cette structure ne possède aucun label ou certificat.</p>
)}
{estEss && <CertificationESSSection ess={ess} />}
Expand Down Expand Up @@ -131,14 +116,12 @@ const LabelsAndCertificatsPage = async (props: AppRouterProps) => {
{estBio && (
<CertificationsBioSection uniteLegale={uniteLegale} bio={bio} />
)}
{protectedCertificats && (
<QualifelecSection qualifelec={protectedCertificats.qualifelec} />
)}
{protectedCertificats && (
<QualibatSection qualibat={protectedCertificats.qualibat} />
)}
{protectedCertificats && (
<OpqibiSection opqibi={protectedCertificats.opqibi} />
{hasRights(session, EScope.protectedCertificats) && (
<ProtectedCertificats
uniteLegale={uniteLegale}
session={session}
hasOtherCertificates={checkHasLabelsAndCertificates(uniteLegale)}
/>
)}
</div>
</>
Expand Down
31 changes: 0 additions & 31 deletions app/api/data-fetching/association/[slug]/route.ts

This file was deleted.

1 change: 0 additions & 1 deletion clients/routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const routes = {
api: {
association: '/api/data-fetching/association',
rne: {
documents: {
list: '/api/data-fetching/espace-agent/documents/',
Expand Down
7 changes: 3 additions & 4 deletions components-ui/alerts-with-explanations/association-adress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import {
getPersonnalDataAssociation,
} from '#models/core/statut-diffusion';
import { IAssociation } from '#models/core/types';
import useSession from 'hooks/use-session';
import { ISession } from '#models/user/session';
import { Warning } from '../alerts';

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

session: ISession | null;
}> = ({ uniteLegale, association, session }) => {
if (!association || isAPINotResponding(association)) {
return null;
}
Expand Down
Loading

0 comments on commit 7b925d1

Please sign in to comment.