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: Ajoute la date de mise à jour aux carte d'actu #3509

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/pages/actualites/index.page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mockUseRouter } from '~/client/components/useRouter.mock';
import { mockScrollIntoView, mockSmallScreen } from '~/client/components/window.mock';
import { DependenciesProvider } from '~/client/context/dependenciesContainer.context';
import { aManualAnalyticsService } from '~/client/services/analytics/analytics.service.fixture';
import ActualitesPage, { getStaticProps } from '~/pages/actualites/index.page';
import { ActualitesPage, getStaticProps } from '~/pages/actualites/index.page';
import { anActualite, anActualiteList } from '~/server/actualites/domain/actualite.fixture';
import { createFailure, createSuccess } from '~/server/errors/either';
import { ErreurMetier } from '~/server/errors/erreurMetier.types';
Expand Down
28 changes: 25 additions & 3 deletions src/pages/actualites/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,38 @@ import useAnalytics from '~/client/hooks/useAnalytics';
import { Actualite } from '~/server/actualites/domain/actualite';
import { isFailure } from '~/server/errors/either';
import { dependencies } from '~/server/start';
import { ISODateTime } from '~/shared/ISODateTime';

import analytics from './index.analytics';
import styles from './index.module.scss';

type SerializedActualite = Omit<Actualite, 'dateMiseAJour'> & {
dateMiseAJour?: ISODateTime
}
interface SerializedActualitesPageProps {
cartesActualites: Array<SerializedActualite>
}
Mintoo200 marked this conversation as resolved.
Show resolved Hide resolved
interface ActualitesPageProps {
cartesActualites: Array<Actualite>
}

const MAX_VISIBLE_ACTUALITES = 3;
export default function ActualitesPage({ cartesActualites }: ActualitesPageProps) {

function deserialize(actualites: Array<SerializedActualite>): Array<Actualite> {
return actualites.map((actualite) => ({
...actualite,
dateMiseAJour: actualite.dateMiseAJour ? new Date(actualite.dateMiseAJour) : undefined,
}));
}
function serialize(cartesActualitesResponse: Array<Actualite>): Array<SerializedActualite> {
return JSON.parse(JSON.stringify(cartesActualitesResponse));
}
sokl-octo marked this conversation as resolved.
Show resolved Hide resolved

export default function Deserialize(props: SerializedActualitesPageProps) {
const deserializedActus = deserialize(props.cartesActualites);
return <ActualitesPage cartesActualites={deserializedActus} />;
}
export function ActualitesPage({ cartesActualites }: ActualitesPageProps) {
useAnalytics(analytics);

const articleCardList = useMemo(() => {
Expand Down Expand Up @@ -54,7 +76,7 @@ export default function ActualitesPage({ cartesActualites }: ActualitesPageProps
);
}

export async function getStaticProps(): Promise<GetStaticPropsResult<ActualitesPageProps>> {
export async function getStaticProps(): Promise<GetStaticPropsResult<SerializedActualitesPageProps>> {
const isEspaceJeuneVisible = process.env.NEXT_PUBLIC_OLD_ESPACE_JEUNE_FEATURE === '0';
if (!isEspaceJeuneVisible) {
return { notFound: true };
Expand All @@ -68,7 +90,7 @@ export async function getStaticProps(): Promise<GetStaticPropsResult<ActualitesP

return {
props: {
cartesActualites: JSON.parse(JSON.stringify(cartesActualitesResponse.result)),
cartesActualites: serialize(cartesActualitesResponse.result),
},
revalidate: dependencies.cmsDependencies.duréeDeValiditéEnSecondes(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/espace-jeune/index.page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { mockUseRouter } from '~/client/components/useRouter.mock';
import { mockScrollIntoView, mockSmallScreen } from '~/client/components/window.mock';
import { DependenciesProvider } from '~/client/context/dependenciesContainer.context';
import { aManualAnalyticsService } from '~/client/services/analytics/analytics.service.fixture';
import EspaceJeunePage, { getStaticProps } from '~/pages/espace-jeune/index.page';
import { EspaceJeunePage, getStaticProps } from '~/pages/espace-jeune/index.page';
import { anActualite, anActualiteList } from '~/server/actualites/domain/actualite.fixture';
import { aServiceJeune, aServiceJeuneList } from '~/server/services-jeunes/domain/servicesJeunes.fixture';

Expand Down
34 changes: 29 additions & 5 deletions src/pages/espace-jeune/index.page.tsx
sokl-octo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,45 @@ import { LightHero, LightHeroPrimaryText, LightHeroSecondaryText } from '~/clien
import SeeMoreItemList from '~/client/components/ui/SeeMore/SeeMoreItemList';
import useAnalytics from '~/client/hooks/useAnalytics';
import analytics from '~/pages/espace-jeune/index.analytics';
import { Accueil } from '~/pages/index.page';
import { Actualite } from '~/server/actualites/domain/actualite';
import { isFailure } from '~/server/errors/either';
import { ServiceJeune } from '~/server/services-jeunes/domain/servicesJeunes';
import { dependencies } from '~/server/start';
import { ISODateTime } from '~/shared/ISODateTime';

import styles from './index.module.scss';

interface EspaceJeunePageProps {
cartesActualites: Actualite[]
type EspaceJeunePageProps = {
cartesActualites: Array<Actualite>
serviceJeuneList: Array<ServiceJeune>
}
type SerializedActualite = Omit<Actualite, 'dateMiseAJour'> & {
dateMiseAJour?: ISODateTime
}
type SerializedEspaceJeunePageProps = {
cartesActualites: Array<SerializedActualite>
serviceJeuneList: Array<ServiceJeune>
}


const MAX_VISIBLE_ACTUALITES_LENGTH = 3;
function deserialize(actualites: Array<SerializedActualite>): Array<Actualite> {
return actualites.map((actualite) => ({
...actualite,
dateMiseAJour: actualite.dateMiseAJour ? new Date(actualite.dateMiseAJour) : undefined,
}));
}
function serialize(cartesActualitesResponse: unknown): Record<string, unknown> {
return JSON.parse(JSON.stringify(cartesActualitesResponse));
}

export default function Deserialize(props: SerializedEspaceJeunePageProps) {
const deserializedActus = deserialize(props.cartesActualites);
return <Accueil actualites={deserializedActus} />;
}

export default function EspaceJeunePage({ cartesActualites, serviceJeuneList }: EspaceJeunePageProps) {
export function EspaceJeunePage({ cartesActualites, serviceJeuneList }: EspaceJeunePageProps) {
useAnalytics(analytics);

const articleCardList: React.ReactNode[] = useMemo(() => {
Expand Down Expand Up @@ -87,8 +111,8 @@ export async function getStaticProps(): Promise<GetStaticPropsResult<EspaceJeune

return {
props: {
cartesActualites: JSON.parse(JSON.stringify(cartesActualitesResponse.result)),
serviceJeuneList: JSON.parse(JSON.stringify(serviceJeuneList.result)),
cartesActualites: serialize(cartesActualitesResponse.result),
serviceJeuneList: serialize(serviceJeuneList.result),
},
revalidate: dependencies.cmsDependencies.duréeDeValiditéEnSecondes(),
};
Expand Down
4 changes: 2 additions & 2 deletions src/pages/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface CardContent {
}

type SerializedActualite = Omit<Actualite, 'dateMiseAJour'> & {
dateMiseAJour: ISODateTime
dateMiseAJour?: ISODateTime
}
interface SerializedAccueilPageProps {
actualites: Array<SerializedActualite>
Expand All @@ -38,7 +38,7 @@ interface AccueilPageProps {
function deserialize(actualites: Array<SerializedActualite>): Array<Actualite> {
return actualites.map((actualite) => ({
...actualite,
dateMiseAJour: new Date(actualite.dateMiseAJour),
dateMiseAJour: actualite.dateMiseAJour ? new Date(actualite.dateMiseAJour) : undefined,
}));
}
function serialize(cartesActualitesResponse: Array<Actualite>): Array<SerializedActualite> {
Expand Down