Skip to content

Commit

Permalink
feat(contributions): nouvelle version pages personnalisables
Browse files Browse the repository at this point in the history
  • Loading branch information
carolineBda committed Jul 19, 2023
1 parent 2636575 commit 08bdf20
Show file tree
Hide file tree
Showing 12 changed files with 346 additions and 99 deletions.
1 change: 0 additions & 1 deletion packages/code-du-travail-frontend/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Sentry from "@sentry/nextjs";
import { Button, Container, icons as Icons, theme } from "@socialgouv/cdtn-ui";
import Head from "next/head";
import Link from "next/link";
import React, { useEffect } from "react";
import styled from "styled-components";
Expand Down
88 changes: 56 additions & 32 deletions packages/code-du-travail-frontend/pages/contribution/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Layout } from "../../src/layout/Layout";
import { Breadcrumb } from "@socialgouv/cdtn-utils";
import { handleError } from "../../src/lib/fetch-error";
import { SITE_URL } from "../../src/config";
import ContributionGeneric from "../../src/contributions/Contribution-generic";

const fetchQuestion = ({ slug }) =>
fetch(`${SITE_URL}/api/items/contributions/${slug}`);
Expand All @@ -16,36 +17,53 @@ interface Props {
breadcrumbs: Breadcrumb[];
description: string;
title: string;
slug: string;
content;
answers;
relatedItems: Array<any>;
}

function PageContribution(props: Props): JSX.Element {
const buildTitleAndDescription = (
breadcrumbs,
conventionAnswer,
title,
description
) => {
if (breadcrumbs && breadcrumbs.length > 0 && conventionAnswer) {
const titleWithThemeAndCC =
breadcrumbs[breadcrumbs.length - 1].label +
" - " +
conventionAnswer.shortName;
return {
description: title + " " + description,
title: titleWithThemeAndCC,
};
}
const buildTitleAndDescription = (
breadcrumbs,
conventionAnswer,
title,
description
) => {
if (breadcrumbs && breadcrumbs.length > 0 && conventionAnswer) {
const titleWithThemeAndCC =
breadcrumbs[breadcrumbs.length - 1].label +
" - " +
conventionAnswer.shortName;
return {
description,
title,
description: title + " " + description,
title: titleWithThemeAndCC,
};
}
return {
description,
title,
};
};

const { breadcrumbs, title, answers, description, relatedItems, content } =
props;
const SLUG_FOR_POC = [
"les-conges-pour-evenements-familiaux",
"quelle-est-la-duree-maximale-de-la-periode-dessai-sans-et-avec-renouvellement",
"quelle-est-la-duree-de-preavis-en-cas-de-licenciement",
];
const showNewContribPage = (slug): boolean => {
return SLUG_FOR_POC.indexOf(slug) >= 0;
};

function PageContribution(props: Props): JSX.Element {
const {
breadcrumbs,
title,
answers,
description,
relatedItems,
content,
slug,
} = props;

const metas = buildTitleAndDescription(
breadcrumbs,
Expand All @@ -54,21 +72,27 @@ function PageContribution(props: Props): JSX.Element {
description
);
return (
<div>
<Layout>
<Metas title={metas.title} description={metas.description} />
<Answer
title={title}
relatedItems={relatedItems}
breadcrumbs={breadcrumbs}
>
<Layout>
<Metas title={metas.title} description={metas.description} />
<Answer
title={title}
relatedItems={relatedItems}
breadcrumbs={breadcrumbs}
>
{showNewContribPage(slug) ? (
<ContributionGeneric
answers={answers}
slug={slug}
content={(content && content._source) || {}}
/>
) : (
<Contribution
answers={answers}
content={(content && content._source) || {}}
/>
</Answer>
</Layout>
</div>
)}
</Answer>
</Layout>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import References from "../../src/common/References";
import { Layout } from "../../src/layout/Layout";
import { EditorialContentDataWrapper } from "@socialgouv/cdtn-utils";
import { getInformationBySlug } from "../../src/information";
import { Contents } from "../../src/information/Components";
import { Contents } from "../../src/information";
import { QuestionnaireWrapper } from "../../src/questionnaire";
import { useRouter } from "next/router";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
import { Agreement, getLabelBySource } from "@socialgouv/cdtn-utils";
import React, { useState } from "react";
import styled from "styled-components";

import Mdx from "../../src/common/Mdx";
import { A11yLink } from "../common/A11yLink";
import { useLocalStorageOnPageLoad } from "../lib/useLocalStorage";
import rehypeToReact from "./rehypeToReact";
import ReferencesJuridiques, { filteredRefs } from "./References";
import {
ArrowLink,
Badge,
Button,
icons,
Paragraph,
Section,
theme,
Title,
Wrapper,
} from "@socialgouv/cdtn-ui";
import { RadioQuestion } from "../outils/Components";
import { AgreementRoute } from "../outils/common/type/WizardType";
import { SearchAgreementInput } from "../outils/common/Agreement/AgreementSearch/AgreementInput/SearchAgreementInput";
import router from "next/router";
import { Toast } from "@socialgouv/cdtn-ui/lib";
import { EnterpriseSearch } from "../outils/CommonSteps/Agreement/components";
import { AgreementSearchValue } from "../outils/CommonSteps/Agreement/store";
import { AgreementSupportInfo } from "../outils/common/Agreement/types";
import NotSupportedAgreementDisclaimer from "../outils/DureePreavisDemission/steps/component/NotSupportedAgreementDisclaimer";

const { DirectionRight } = icons;

const onUserAction = (agreement) => {
console.log("Track ?????", agreement);
};

const ContributionGeneric = ({ answers, content, slug }) => {
console.log(answers);
const hasConventionAnswers =
answers.conventions && answers.conventions.length > 0;
const [showAnswer, setShowAnswer] = useState(false);

const [convention, setConvention] =
useLocalStorageOnPageLoad<Agreement>("convention");

const [selectedRoute, setSelectedRoute] = useState<
AgreementRoute | undefined
>();

const onSelectAgreement = (agreement) => {
console.log("track event onSelectAgreement", agreement);
setConvention(agreement);
};
const supportedAgreements: AgreementSupportInfo[] = answers.conventions.map(
(c) => {
return {
idcc: parseInt(c.idcc, 10),
fullySupported: true,
};
}
);
return (
<>
{hasConventionAnswers && (
<>
<Badge />
<section>
<Wrapper variant="light">
<Title shift={spacings.xmedium} variant="primary">
Votre Situtation
</Title>

<RadioQuestion
questions={[
{
label:
"Je sais quelle est ma convention collective (je la saisis)",
value: "agreement" as AgreementRoute,
id: "route-agreement",
},
{
label:
"Je ne sais pas quelle est ma convention collective (je la recherche)",
value: "enterprise" as AgreementRoute,
id: "route-enterprise",
},
]}
name="route"
label=" Quel est le nom de la convention collective applicable&nbsp;?"
selectedOption={selectedRoute}
onChangeSelectedOption={(value: AgreementRoute) => {
setConvention();
setSelectedRoute(value);
}}
tooltip={{
content: (
<p>
Vous pouvez trouver le nom de votre convention collective
sur votre <strong>bulletin de paie</strong>.
</p>
),
}}
/>
{selectedRoute === "agreement" && (
<>
{convention ? (
<>
<Toast
variant="secondary"
onRemove={() => setConvention()}
>
{convention.shortTitle}
{convention.highlight &&
convention.highlight.searchInfo && (
<Paragraph variant="altText" noMargin>
{convention.highlight.searchInfo}
</Paragraph>
)}
</Toast>
</>
) : (
<SearchAgreementInput
onUserAction={onUserAction}
onSelectAgreement={onSelectAgreement}
/>
)}
</>
)}
{selectedRoute === "enterprise" && (
<EnterpriseSearch
supportedAgreements={supportedAgreements}
selectedAgreement={convention}
onSelectAgreement={setConvention}
onUserAction={(action, value: AgreementSearchValue) =>
onUserAction(value)
}
alertAgreementNotSupported={(url: string) => (
<NotSupportedAgreementDisclaimer agreementUrl={url} />
)}
simulator="QUESTIONNAIRE"
/>
)}
{convention && (
<Div>
<Button
variant="primary"
onClick={() => {
router.push(`/contribution/${convention.num}-${slug}`);
}}
>
Afficher les informations
<StyledDirectionRightIcon />
</Button>
</Div>
)}
</Wrapper>

{!showAnswer && (
<p>
<Button variant="navLink" onClick={() => setShowAnswer(true)}>
<ArrowLink arrowPosition="left">
Accéder aux informations générales sans renseigner ma
convention collective
</ArrowLink>
</Button>
</p>
)}
</section>
</>
)}
{showAnswer && answers.generic && (
<Section>
<Title stripe="left">Que dit le code du travail&nbsp;?</Title>
{content && (
<Meta>
{content.url && (
<span>
Source&nbsp;:{" "}
<A11yLink
href={content.url}
target="_blank"
rel="noopener noreferrer"
>
{`Fiche: ${getLabelBySource(content.source)}`}
</A11yLink>
</span>
)}
{content.url && content.date && (
<HideOnMobile aria-hidden="true">&nbsp;-&nbsp;</HideOnMobile>
)}
{content.date && <span>Mis à jour le&nbsp;: {content.date}</span>}
</Meta>
)}

<Mdx
markdown={answers.generic.markdown}
components={rehypeToReact(content)}
/>
<ReferencesJuridiques
references={filteredRefs(answers?.generic?.references, content.url)}
/>
</Section>
)}
</>
);
};

const { breakpoints, fonts, spacings } = theme;

const Meta = styled.div`
display: flex;
margin-bottom: ${spacings.medium};
font-size: ${fonts.sizes.small};
@media (max-width: ${breakpoints.mobile}) {
flex-direction: column;
}
`;
const HideOnMobile = styled.span`
@media (max-width: ${breakpoints.mobile}) {
display: none;
}
`;
const Div = styled.div`
text-align: center;
margin-top: ${spacings.large};
`;

const StyledDirectionRightIcon = styled(DirectionRight)`
width: 1.5em;
margin-left: ${spacings.base};
`;

export default ContributionGeneric;
Loading

0 comments on commit 08bdf20

Please sign in to comment.