Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: api route that compares inpi and ig #1331

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,71 @@
import FAQLink from '#components-ui/faq-link';
import { SeePersonPageLink } from '#components-ui/see-personn-page-link';
import { FullTable } from '#components/table/full';
import { IUniteLegale } from '#models/core/types';
import { IDirigeants, IEtatCivil, IPersonneMorale } from '#models/rne/types';
import {
IDirigeantsWithMetadata,
IEtatCivil,
IPersonneMorale,
} from '#models/rne/types';
import { formatDateLong, formatDatePartial, formatIntFr } from '#utils/helpers';
import { isPersonneMorale } from '../is-personne-morale';

type IDirigeantContentProps = {
dirigeants: IDirigeants;
dirigeants: IDirigeantsWithMetadata;
uniteLegale: IUniteLegale;
};

export function DirigeantContent({
const dataSourceTooltip = ({
dataType,
isInIg,
isInInpi,
}: {
dataType: string;
isInIg?: boolean;
isInInpi?: boolean;
}) => {
if (!isInIg && !isInInpi) {
return <></>;
}

return (
<>
{!isInIg && (
<>
{' '}
<FAQLink tooltipLabel={<></>}>
Ce {dataType} n‘apparait pas dans les données d‘Infogreffe.
</FAQLink>
</>
)}
{!isInInpi && (
<>
{' '}
<FAQLink tooltipLabel={<></>}>
Ce {dataType} n‘apparait pas dans les données de l‘INPI.
</FAQLink>
</>
)}
</>
);
};

export default function DirigeantsContent({
dirigeants,
uniteLegale,
}: IDirigeantContentProps) {
const formatDirigeant = (dirigeant: IEtatCivil | IPersonneMorale) => {
if (isPersonneMorale(dirigeant)) {
const infos = [
dirigeant.role,
dirigeant.roles?.map((role) => (
<>
<span>{role.label}</span>
{dataSourceTooltip({
...role,
dataType: 'rôle',
})}
</>
)) || <>{dirigeant.role}</>,
<>
<strong>{dirigeant.denomination}</strong>
{dirigeant.siren ? (
Expand All @@ -32,6 +80,10 @@ export function DirigeantContent({
)}
<br />
{dirigeant.natureJuridique}
{dataSourceTooltip({
...dirigeant,
dataType: 'dirigeant',
})}
</>,
];

Expand All @@ -50,7 +102,15 @@ export function DirigeantContent({
}${(dirigeant.nom || '').toUpperCase()}`;

return [
dirigeant.role,
dirigeant.roles?.map((role) => (
<>
<span>{role.label}</span>
{dataSourceTooltip({
...role,
dataType: 'rôle',
})}
</>
)) || <>{dirigeant.role}</>,
<>
{nomComplet}
{dirigeant.dateNaissance || dirigeant.dateNaissancePartial
Expand All @@ -62,6 +122,10 @@ export function DirigeantContent({
dirigeant.lieuNaissance ? `, à ${dirigeant.lieuNaissance}` : ''
}`
: ''}
{dataSourceTooltip({
...dirigeant,
dataType: 'dirigeant',
})}
</>,
...(dirigeant.dateNaissancePartial
? [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,30 @@ import { UniteLegalePageLink } from '#components/unite-legale-page-link';
import { EAdministration } from '#models/administrations/EAdministration';
import { IUniteLegale } from '#models/core/types';
import { IDirigeantsFetching } from '.';
import { DirigeantContent } from './dirigeant-content';
import DirigeantsContent from './dirigeants-content';

type IProps = {
dirigeants: IDirigeantsFetching;
uniteLegale: IUniteLegale;
isProtected: boolean;
warning: JSX.Element;
};

/**
* Dirigeants section
*/
function DirigeantsSection({
export default function DirigeantsSection({
uniteLegale,
dirigeants,
isProtected,
warning,
}: IProps) {
const sources = [EAdministration.INPI];

if (isProtected) {
sources.push(EAdministration.INFOGREFFE);
}

return (
<AsyncDataSectionClient
id="rne-dirigeants"
id="dirigeants-section"
title="Dirigeant(s)"
sources={sources}
sources={[
EAdministration.INPI,
...(isProtected ? [EAdministration.INFOGREFFE] : []),
]}
data={dirigeants}
isProtected={isProtected}
notFoundInfo={
Expand All @@ -50,10 +45,9 @@ function DirigeantsSection({
return (
<>
{dirigeants.metadata?.isFallback && <InpiPartiallyDownWarning />}
{warning ? warning : null}
{isProtected ? (
<Info>
Ces informations proviennent d’
Ces informations proviennent en partie d’
<a
rel="noopener"
target="_blank"
Expand Down Expand Up @@ -87,7 +81,7 @@ function DirigeantsSection({
&nbsp;:
</p>

<DirigeantContent
<DirigeantsContent
dirigeants={dirigeants}
uniteLegale={uniteLegale}
/>
Expand All @@ -99,5 +93,3 @@ function DirigeantsSection({
</AsyncDataSectionClient>
);
}

export default DirigeantsSection;
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,44 @@ import { HorizontalSeparator } from '#components-ui/horizontal-separator';
import BreakPageForPrint from '#components-ui/print-break-page';
import { IAPINotRespondingError } from '#models/api-not-responding';
import { IUniteLegale } from '#models/core/types';
import {
IDataFetchingState,
isDataLoading,
isDataSuccess,
isUnauthorized,
} from '#models/data-fetching';
import { IDirigeants } from '#models/rne/types';
import { IDataFetchingState } from '#models/data-fetching';
import { IDirigeantsWithMetadata } from '#models/rne/types';
import { ApplicationRights, hasRights } from '#models/user/rights';
import { ISession } from '#models/user/session';
import { APIRoutesPaths } from 'app/api/data-fetching/routes-paths';
import { useAPIRouteData } from 'hooks/fetch/use-API-route-data';
import BeneficiairesSection from './beneficiaires';
import RCSRNEComparison from './rcs-rne-comparison';
import DirigeantsSection from './rne-dirigeants';
import DirigeantsSection from './dirigeants-section';
import DirigeantSummary from './summary';

export type IDirigeantsFetching =
| IDirigeants
| IDirigeantsWithMetadata
| IAPINotRespondingError
| IDataFetchingState;

function mergeDirigeants(
dirigeantsRNE: IDirigeantsFetching,
dirigeantsRCS: IDirigeantsFetching
) {
if (isUnauthorized(dirigeantsRCS)) {
return { dirigeants: dirigeantsRNE, isProtected: false };
} else {
if (isDataLoading(dirigeantsRCS) || isDataLoading(dirigeantsRNE)) {
return { dirigeants: IDataFetchingState.LOADING, isProtected: false };
}
if (isDataSuccess(dirigeantsRCS)) {
return { dirigeants: dirigeantsRCS, isProtected: true };
}
}
return { dirigeants: dirigeantsRNE, isProtected: false };
}

export function DirigeantInformation({
uniteLegale,
session,
}: {
uniteLegale: IUniteLegale;
session: ISession | null;
}) {
const dirigeantsRNE = useAPIRouteData(
APIRoutesPaths.RneDirigeants,
uniteLegale.siren,
session
);

const mandatairesRCS = useAPIRouteData(
APIRoutesPaths.EspaceAgentRcsMandataires,
const isProtected = hasRights(session, ApplicationRights.mandatairesRCS);
const dirigeants = useAPIRouteData(
isProtected
? APIRoutesPaths.EspaceAgentDirigeantsProtected
: APIRoutesPaths.RneDirigeants,
uniteLegale.siren,
session
);

const { dirigeants, isProtected } = mergeDirigeants(
dirigeantsRNE,
mandatairesRCS
);

return (
<>
<DirigeantSummary uniteLegale={uniteLegale} dirigeants={dirigeants} />
<DirigeantsSection
uniteLegale={uniteLegale}
dirigeants={dirigeants}
isProtected={isProtected}
warning={
<RCSRNEComparison
dirigeantsRCS={mandatairesRCS}
dirigeantsRNE={dirigeantsRNE}
uniteLegale={uniteLegale}
/>
}
/>
<BreakPageForPrint />
<HorizontalSeparator />
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions app/api/data-fetching/routes-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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 { getConformiteEntreprise } from '#models/espace-agent/conformite';
import { getMandatairesRCS } from '#models/espace-agent/mandataires-rcs';
import { getDirigeantsProtected } from '#models/espace-agent/dirigeants-protected';
import { getDocumentsRNEProtected } from '#models/espace-agent/rne-protected/documents';
import { getDirigeantsRNE } from '#models/rne/dirigeants';
import { getRNEObservations } from '#models/rne/observations';
Expand All @@ -26,7 +26,7 @@ export const APIRoutesHandlers = {
[APIRoutesPaths.EspaceAgentCnetp]: getCnetp,
[APIRoutesPaths.EspaceAgentQualibat]: getQualibat,
[APIRoutesPaths.EspaceAgentQualifelec]: getQualifelec,
[APIRoutesPaths.EspaceAgentRcsMandataires]: getMandatairesRCS,
[APIRoutesPaths.EspaceAgentDirigeantsProtected]: getDirigeantsProtected,
[APIRoutesPaths.EspaceAgentBeneficiaires]: getBeneficiairesController,
[APIRoutesPaths.EspaceAgentRneDocuments]: getDocumentsRNEProtected,
[APIRoutesPaths.EspaceAgentAssociationProtected]: getAssociationProtected,
Expand Down
2 changes: 1 addition & 1 deletion app/api/data-fetching/routes-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export enum APIRoutesPaths {
EspaceAgentCnetp = 'espace-agent/cnetp',
EspaceAgentQualibat = 'espace-agent/qualibat',
EspaceAgentQualifelec = 'espace-agent/qualifelec',
EspaceAgentRcsMandataires = 'espace-agent/rcs-mandataires',
EspaceAgentDirigeantsProtected = 'espace-agent/dirigeants-protected',
EspaceAgentBeneficiaires = 'espace-agent/beneficiaires',
EspaceAgentRneDocuments = 'espace-agent/rne/documents',
EspaceAgentAssociationProtected = 'espace-agent/association-protected',
Expand Down
3 changes: 2 additions & 1 deletion app/api/data-fetching/routes-scopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export const APIRoutesScopes: Record<APIRoutesPaths, ApplicationRights> = {
[APIRoutesPaths.EspaceAgentQualibat]: ApplicationRights.protectedCertificats,
[APIRoutesPaths.EspaceAgentQualifelec]:
ApplicationRights.protectedCertificats,
[APIRoutesPaths.EspaceAgentRcsMandataires]: ApplicationRights.mandatairesRCS,
[APIRoutesPaths.EspaceAgentBeneficiaires]: ApplicationRights.beneficiaires,
[APIRoutesPaths.EspaceAgentRneDocuments]: ApplicationRights.documentsRne,
[APIRoutesPaths.EspaceAgentDirigeantsProtected]:
ApplicationRights.mandatairesRCS,
[APIRoutesPaths.EspaceAgentAssociationProtected]:
ApplicationRights.associationProtected,
[APIRoutesPaths.RneDirigeants]: ApplicationRights.opendata,
Expand Down
Loading
Loading