Skip to content

Commit

Permalink
feat: add title in idcc summary (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierJp authored Jan 6, 2025
1 parent e7f56f8 commit 3e8107b
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 21 deletions.
4 changes: 3 additions & 1 deletion clients/recherche-entreprise/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ const mapToUniteLegale = (result: IResult, pageEtablissements: number) => {
dateMiseAJourInsee: date_mise_a_jour_insee || '',
dateMiseAJourInpi: date_mise_a_jour_rne || '',
dateFermeture: date_fermeture ?? '',
listeIdcc: liste_idcc || [],
listeIdcc: (liste_idcc || []).map((idcc) => {
return { idcc, title: '' };
}),
};
};

Expand Down
5 changes: 4 additions & 1 deletion clients/recherche-entreprise/mapToDomain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,13 @@ export const mapToEtablissement = (
estEntrepreneurIndividuel,
idFiness: liste_finess || [],
idBio: liste_id_bio || [],
idcc: liste_idcc || [],
idOrganismeFormation: liste_id_organisme_formation || [],
idRge: liste_rge || [],
idUai: liste_uai || [],
},
listeIdcc: (liste_idcc || []).map((idcc) => {
// as etablissement will undergo a refacto, we prefer a simpler implem with no title
return { idcc, title: '' };
}),
};
};
37 changes: 23 additions & 14 deletions components/badges-section/convention-collectives/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
import React from 'react';
import InformationTooltip from '#components-ui/information-tooltip';
import { Tag } from '#components-ui/tag';
import { Siren } from '#utils/helpers';
import React from 'react';

const TagCC = ({ siren, idcc }: { siren: Siren; idcc: string }) => (
<Tag
link={{
href: `/divers/${siren}#idcc-${idcc}`,
'aria-label': `Consulter la liste de toutes les conventions collectives de la structure, dont l'IDCC ${idcc}`,
}}
>
IDCC {idcc}
</Tag>
);

export const ConventionCollectivesBadgesSection: React.FC<{
conventionCollectives: string[];
siren: Siren;
}> = ({ conventionCollectives, siren }) =>
conventionCollectives: { idcc: string; title: string }[];
}> = ({ siren, conventionCollectives }) =>
conventionCollectives.length > 0 ? (
conventionCollectives.map((idcc) => (
conventionCollectives.map(({ idcc, title }) => (
<React.Fragment key={idcc}>
{
<Tag
link={{
href: `/divers/${siren}#idcc-${idcc}`,
'aria-label': `Consulter la liste de toutes les conventions collectives de la structure, dont l'IDCC ${idcc}`,
}}
>
IDCC {idcc}
</Tag>
}
{title ? (
<InformationTooltip label={title} tabIndex={0}>
<TagCC siren={siren} idcc={idcc} />
</InformationTooltip>
) : (
<TagCC siren={siren} idcc={idcc} />
)}
</React.Fragment>
))
) : (
Expand Down
4 changes: 2 additions & 2 deletions components/etablissement-section/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ const EtablissementSection: React.FC<IProps> = ({
? [['Date de fermeture', formatDate(etablissement.dateFermeture || '')]]
: []),
['', <br />],
...(etablissement.complements.idcc
...(etablissement.listeIdcc
? [
[
'Convention collective de l’établissement',
[
<ConventionCollectivesBadgesSection
conventionCollectives={etablissement.complements.idcc}
conventionCollectives={etablissement.listeIdcc}
siren={uniteLegale.siren}
/>,
],
Expand Down
30 changes: 30 additions & 0 deletions models/conventions-collectives/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ export type ICCWithMetadata = {
unknown: boolean;
};

/**
* Get title from metadata for a single idcc
* @param siren
* @param idcc
* @returns
*/
export const getIdccTitle = async (siren: Siren, idcc: string) => {
try {
const metadata = await clientIdccMetadata(idcc);
return { idcc, title: metadata.title || '' };
} catch (e: any) {
logErrorInSentry(
new FetchRessourceException({
cause: e,
ressource: 'Convention Collective',
context: {
siren,
},
})
);
// when metadata fails we intentionnally ignore failure
return { idcc, title: '' };
}
};

/**
* Get all idcc and their metadata for a given siren
* @param siren
* @returns
*/
export const getAllIdccWithMetadata = async (
siren: Siren
): Promise<ICCWithMetadata[] | IAPINotRespondingError> => {
Expand Down
6 changes: 3 additions & 3 deletions models/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface IEtablissement {
latitude: string;
longitude: string;
complements: IEtablissementComplements;
listeIdcc: { idcc: string; title: string }[];
}

export interface IEtablissementWithUniteLegale {
Expand Down Expand Up @@ -78,6 +79,7 @@ export const createDefaultEtablissement = (): IEtablissement => {
latitude: '',
longitude: '',
complements: createDefaultEtablissementComplements(),
listeIdcc: [],
};
};

Expand Down Expand Up @@ -118,7 +120,7 @@ export interface IUniteLegale extends IEtablissementsList {
colter: {
codeColter: string | null;
};
listeIdcc: string[];
listeIdcc: { idcc: string; title: string }[];
}

export const createDefaultUniteLegale = (siren: Siren): IUniteLegale => {
Expand Down Expand Up @@ -220,7 +222,6 @@ export interface IEtablissementComplements {
estEntrepreneurIndividuel: boolean;
idFiness: string[];
idBio: string[];
idcc: string[];
idOrganismeFormation: string[];
idRge: string[];
idUai: string[];
Expand All @@ -232,7 +233,6 @@ export const createDefaultEtablissementComplements =
estEntrepreneurIndividuel: false,
idFiness: [],
idBio: [],
idcc: [],
idOrganismeFormation: [],
idRge: [],
idUai: [],
Expand Down
8 changes: 8 additions & 0 deletions models/core/unite-legale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '#clients/exceptions';
import { clientUniteLegaleRechercheEntreprise } from '#clients/recherche-entreprise/siren';
import { clientUniteLegaleInsee } from '#clients/sirene-insee/siren';
import { getIdccTitle } from '#models/conventions-collectives';
import { createEtablissementsList } from '#models/core/etablissements-list';
import { IETATADMINSTRATIF, estActif } from '#models/core/etat-administratif';
import { Siren, isLuhnValid, verifySiren } from '#utils/helpers';
Expand Down Expand Up @@ -101,6 +102,13 @@ class UniteLegaleBuilder {
IETATADMINSTRATIF.ACTIF_ZERO_ETABLISSEMENT;
}

// idcc
uniteLegale.listeIdcc = await Promise.all(
uniteLegale.listeIdcc.map(async ({ idcc }) => {
return await getIdccTitle(uniteLegale.siren, idcc);
})
);

return uniteLegale;
};

Expand Down

0 comments on commit 3e8107b

Please sign in to comment.