From 052d69d0031a05925ed0edc6e0a087db3b4285b4 Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Wed, 21 Jun 2023 15:06:29 +0200 Subject: [PATCH] Corrige les liens vers la doc depuis le comparateur --- .../components/EngineDocumentationRoutes.tsx | 8 +- .../choix-du-statut/_components/useSteps.ts | 2 +- .../choix-du-statut/comparateur.tsx | 90 +++++++++++++++++++ .../assistants/choix-du-statut/config.ts | 1 + .../assistants/choix-du-statut/index.tsx | 23 +++-- .../assistants/choix-du-statut/statuts.tsx | 5 -- .../components/Comparateur.tsx | 12 ++- .../components/DetailsRowCards.tsx | 5 +- site/source/sitePaths.ts | 4 +- 9 files changed, 126 insertions(+), 24 deletions(-) create mode 100644 site/source/pages/assistants/choix-du-statut/comparateur.tsx delete mode 100644 site/source/pages/assistants/choix-du-statut/statuts.tsx diff --git a/site/source/components/EngineDocumentationRoutes.tsx b/site/source/components/EngineDocumentationRoutes.tsx index 1aecd6346..356389b59 100644 --- a/site/source/components/EngineDocumentationRoutes.tsx +++ b/site/source/components/EngineDocumentationRoutes.tsx @@ -3,15 +3,15 @@ import { Route, Routes, useNavigate } from 'react-router-dom' import Popover from '@/design-system/popover/Popover' import Documentation from '@/pages/Documentation' import { EngineComparison } from '@/pages/simulateurs/comparaison-statuts/components/Comparateur' -import { useSitePaths } from '@/sitePaths' export function EngineDocumentationRoutes({ namedEngines, + basePath, }: { namedEngines: EngineComparison + basePath: string }) { const navigate = useNavigate() - const { absoluteSitePaths } = useSitePaths() return ( @@ -25,14 +25,14 @@ export function EngineDocumentationRoutes({ isOpen isDismissable onClose={() => { - navigate(absoluteSitePaths.simulateurs.comparaison, { + navigate(basePath, { replace: true, }) }} > diff --git a/site/source/pages/assistants/choix-du-statut/_components/useSteps.ts b/site/source/pages/assistants/choix-du-statut/_components/useSteps.ts index 1544ac93c..f05ee1650 100644 --- a/site/source/pages/assistants/choix-du-statut/_components/useSteps.ts +++ b/site/source/pages/assistants/choix-du-statut/_components/useSteps.ts @@ -13,7 +13,7 @@ const stepOrder: readonly Step[] = [ 'association', 'associé', 'rémunération', - 'statuts', + 'comparateur', ] as const export function useCurrentStep() { diff --git a/site/source/pages/assistants/choix-du-statut/comparateur.tsx b/site/source/pages/assistants/choix-du-statut/comparateur.tsx new file mode 100644 index 000000000..e61bef64c --- /dev/null +++ b/site/source/pages/assistants/choix-du-statut/comparateur.tsx @@ -0,0 +1,90 @@ +import { useMemo } from 'react' + +import { EngineDocumentationRoutes } from '@/components/EngineDocumentationRoutes' +import { Statut } from '@/components/StatutTag' +import { useEngine, useRawSituation } from '@/components/utils/EngineContext' +import { EngineComparison } from '@/pages/simulateurs/comparaison-statuts/components/Comparateur' +import Détails from '@/pages/simulateurs/comparaison-statuts/components/Détails' +import Résultats from '@/pages/simulateurs/comparaison-statuts/components/Résultats' +import { useCasParticuliers } from '@/pages/simulateurs/comparaison-statuts/contexts/CasParticuliers' +import { useSitePaths } from '@/sitePaths' +import { Situation } from '@/store/reducers/rootReducer' + +export default function Comparateur() { + const namedEngines = useStatutComparaison() + const { absoluteSitePaths } = useSitePaths() + + return ( + <> + + + + + ) +} + +/** + * Returns the situation for computing the results with the given statut + * @param statut + */ +function useStatutComparaison(): EngineComparison { + const { isAutoEntrepreneurACREEnabled } = useCasParticuliers() + const possibleStatuts = usePossibleStatuts() + console.log(possibleStatuts) + const situation = useRawSituation() + const engine = useEngine() + + return useMemo( + () => + possibleStatuts.map((statut) => ({ + name: statut, + engine: engine.shallowCopy().setSituation({ + ...situation, + ...getSituationFromStatut(statut, isAutoEntrepreneurACREEnabled), + }), + })) as EngineComparison, + [possibleStatuts, isAutoEntrepreneurACREEnabled] + ) +} + +function usePossibleStatuts(): Array { + const engine = useEngine() + // We could do this logic by filtering the applicable status in publicodes, + // but for now, there is only two options, so we hardcode it + if ( + engine.evaluate('entreprise . catégorie juridique . EI = non').nodeValue === + true + ) { + return ['SASU', 'SARL'] + } else { + return ['SASU', 'EI', 'AE'] + } +} + +function getSituationFromStatut(statut: Statut, AEAcre: boolean): Situation { + return { + 'entreprise . catégorie juridique . remplacements': 'oui', + 'entreprise . catégorie juridique': + statut === 'SASU' + ? "'SAS'" + : statut === 'EURL' + ? "'EURL'" + : statut === 'AE' + ? "'EI'" + : statut === 'SELARLU' + ? "'SELARL'" + : statut === 'SELASU' + ? "'SELAS'" + : `'${statut}'`, + 'entreprise . catégorie juridique . EI . auto-entrepreneur': + statut === 'AE' ? 'oui' : 'non', + 'entreprise . imposition': "'IS'", + 'entreprise . associés': ['SARL', 'SAS', 'SELAS', 'SELARL'].includes(statut) + ? "'multiple'" + : "'unique'", + ...(AEAcre ? { 'dirigeant . exonérations . ACRE': 'oui' } : {}), + } +} diff --git a/site/source/pages/assistants/choix-du-statut/config.ts b/site/source/pages/assistants/choix-du-statut/config.ts index d5c8f3395..5b485636c 100644 --- a/site/source/pages/assistants/choix-du-statut/config.ts +++ b/site/source/pages/assistants/choix-du-statut/config.ts @@ -32,6 +32,7 @@ export function choixStatutJuridiqueConfig({ simulation: { situation: { 'entreprise . catégorie juridique . remplacements': 'non', + salarié: 'non', }, }, autoloadLastSimulation: true, diff --git a/site/source/pages/assistants/choix-du-statut/index.tsx b/site/source/pages/assistants/choix-du-statut/index.tsx index 412c9b380..97c2f4694 100644 --- a/site/source/pages/assistants/choix-du-statut/index.tsx +++ b/site/source/pages/assistants/choix-du-statut/index.tsx @@ -7,12 +7,12 @@ import { useCurrentStep } from './_components/useSteps' import Association from './association' import Associé from './associé' import Commune from './commune' +import Comparateur from './comparateur' import DétailsActivité from './détails-activité' import AccueilChoixStatut from './home' import RechercheActivité from './recherche-activité' import Rémunération from './rémunération' import Résultat from './résultat' -import Statuts from './statuts' export default function ChoixDuStatut() { const { relativeSitePaths } = useSitePaths() @@ -32,12 +32,21 @@ export default function ChoixDuStatut() { path={childrenPaths['détails-activité']} element={} /> - } /> - } /> - } /> - } /> - } /> - } /> + } /> + } /> + } + /> + } + /> + } /> + } + /> ) diff --git a/site/source/pages/assistants/choix-du-statut/statuts.tsx b/site/source/pages/assistants/choix-du-statut/statuts.tsx deleted file mode 100644 index 3dd9002c1..000000000 --- a/site/source/pages/assistants/choix-du-statut/statuts.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import ComparateurStatuts from '@/pages/simulateurs/comparaison-statuts' - -export default function Statuts() { - return -} diff --git a/site/source/pages/simulateurs/comparaison-statuts/components/Comparateur.tsx b/site/source/pages/simulateurs/comparaison-statuts/components/Comparateur.tsx index 422bf8a1a..db88332ee 100644 --- a/site/source/pages/simulateurs/comparaison-statuts/components/Comparateur.tsx +++ b/site/source/pages/simulateurs/comparaison-statuts/components/Comparateur.tsx @@ -10,6 +10,7 @@ import Simulation, { } from '@/components/Simulation' import { Statut } from '@/components/StatutTag' import { Spacing } from '@/design-system/layout' +import { useSitePaths } from '@/sitePaths' import Détails from './Détails' import Résultats from './Résultats' @@ -19,7 +20,9 @@ type NamedEngine = { name: Statut } -export type EngineComparison = [NamedEngine, NamedEngine, NamedEngine] +export type EngineComparison = + | [NamedEngine, NamedEngine, NamedEngine] + | [NamedEngine, NamedEngine] function Comparateur({ namedEngines }: { namedEngines: EngineComparison }) { const { t } = useTranslation() @@ -30,6 +33,8 @@ function Comparateur({ namedEngines }: { namedEngines: EngineComparison }) { Engine ] + const { absoluteSitePaths } = useSitePaths() + return ( <> - + ) } diff --git a/site/source/pages/simulateurs/comparaison-statuts/components/DetailsRowCards.tsx b/site/source/pages/simulateurs/comparaison-statuts/components/DetailsRowCards.tsx index 8a5e10661..814df942c 100644 --- a/site/source/pages/simulateurs/comparaison-statuts/components/DetailsRowCards.tsx +++ b/site/source/pages/simulateurs/comparaison-statuts/components/DetailsRowCards.tsx @@ -41,7 +41,6 @@ const DetailsRowCards = ({ warning?: (engine: Engine) => ReactNode footer?: (engine: Engine) => ReactNode }) => { - console.log(namedEngines) const options = namedEngines.map(({ engine, name }) => ({ engine, name, @@ -104,7 +103,7 @@ const DetailsRowCards = ({ > Ne s'applique pas @@ -128,7 +127,7 @@ const DetailsRowCards = ({ {label && label} diff --git a/site/source/sitePaths.ts b/site/source/sitePaths.ts index bcb143d01..9f22f30fb 100644 --- a/site/source/sitePaths.ts +++ b/site/source/sitePaths.ts @@ -34,7 +34,7 @@ const rawSitePathsFr = { association: 'association', associé: 'associe', rémunération: 'remuneration', - statuts: 'statuts', + comparateur: 'comparateur', résultat: 'resultat', }, }, @@ -120,7 +120,7 @@ const rawSitePathsEn = { association: 'association', associé: 'partnership', rémunération: 'remuneration', - statuts: 'statuts', + comparateur: 'comparator', résultat: 'result', }, },