Skip to content

Commit

Permalink
fix: add no certificat found explanation when no certificats are found
Browse files Browse the repository at this point in the history
  • Loading branch information
johangirod committed May 15, 2024
1 parent b74e19d commit 9715fd3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
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';
Expand All @@ -10,9 +15,14 @@ import { ISession } from '#models/user/session';
type IProps = {
uniteLegale: IUniteLegale;
session: ISession | null;
hasOtherCertificates: boolean;
};

export async function ProtectedCertificats({ uniteLegale, session }: IProps) {
export async function ProtectedCertificats({
uniteLegale,
session,
hasOtherCertificates,
}: IProps) {
const opqibi = getOpqibi(uniteLegale.siren, session?.user?.siret);
const qualifelec = getQualifelec(
uniteLegale.siege.siret,
Expand All @@ -22,9 +32,26 @@ export async function ProtectedCertificats({ uniteLegale, session }: IProps) {

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;
}
8 changes: 5 additions & 3 deletions app/(header-default)/labels-certificats/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ const LabelsAndCertificatsPage = async (props: AppRouterProps) => {
<CertificationsBioSection uniteLegale={uniteLegale} bio={bio} />
)}
{hasRights(session, EScope.protectedCertificats) && (
<>
<ProtectedCertificats uniteLegale={uniteLegale} session={session} />
</>
<ProtectedCertificats
uniteLegale={uniteLegale}
session={session}
hasOtherCertificates={checkHasLabelsAndCertificates(uniteLegale)}
/>
)}
</div>
</>
Expand Down

0 comments on commit 9715fd3

Please sign in to comment.