Skip to content

Commit

Permalink
fix(client): 🐛 images dynamic stats
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-fesselier committed Feb 12, 2025
1 parent 98b674d commit 87f3612
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 11 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Props {
image?: any;
imageWidth?: number;
imageHeight?: number;
imageComponent?: ReactElement;
header?: ReactElement;
footer?: ReactElement;
footerBottom?: boolean;
Expand Down Expand Up @@ -42,6 +43,7 @@ const Card = (props: Props) => {
style={{ objectFit: "contain" }}
/>
)}
{props.imageComponent}
</div>
<h3 className="text-h6 md:text-h5 my-3 text-blue-france">{props.title}</h3>
<div className={cls("[&_p]:text-large", props.footerBottom && "flex-grow")}>{props.children}</div>
Expand All @@ -57,6 +59,7 @@ const Card = (props: Props) => {
props.footerBottom,
props.imageWidth,
props.imageHeight,
props.imageComponent,
],
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface Props {
children: number;
}

export const ImageCustomFigure = (props: Props) => {
return (
<span className="absolute w-[48px] h-[48px] right-0 top-[16px] flex items-center justify-center text-white text-small font-bold leading-none">
+{props.children}
</span>
);
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { Figure } from "./Figure";
export { ImageCustomFigure } from "./ImageCustomFigure";
export { ImpactCol } from "./ImpactCol";
export { TeamCard } from "./TeamCard";
86 changes: 75 additions & 11 deletions apps/client/src/pages/mission-et-impact.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Badge from "@codegouvfr/react-dsfr/Badge";
import Button from "@codegouvfr/react-dsfr/Button";
import Card from "@codegouvfr/react-dsfr/Card";
import { NextPage } from "next";
import { GetStructureStatisticsResponse, TranslationStatisticsResponse } from "@refugies-info/api-types";
import { useTranslation } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import Image from "next/image";
import { useEffect, useState } from "react";
import { useInView } from "react-intersection-observer";
import { END } from "redux-saga";
import CommunityIlluAmbassadeurs from "~/assets/staticPages/mission-et-impact/community-ambassadeurs.png";
import CommunityIlluCda from "~/assets/staticPages/mission-et-impact/community-cda.png";
import CommunityIlluDinum from "~/assets/staticPages/mission-et-impact/community-dinum.png";
Expand Down Expand Up @@ -46,14 +48,23 @@ import {
StepContent,
Title2,
} from "~/components/Pages/staticPages/common";
import { Figure, ImpactCol, TeamCard } from "~/components/Pages/staticPages/mission-et-impact";
import { Figure, ImageCustomFigure, ImpactCol, TeamCard } from "~/components/Pages/staticPages/mission-et-impact";
import SEO from "~/components/Seo";
import { useTeamData } from "~/data/useTeamData";
import { defaultStaticProps } from "~/lib/getDefaultStaticProps";
import { getLanguageFromLocale } from "~/lib/getLanguageFromLocale";
import { logger } from "~/logger";
import { wrapper } from "~/services/configureStore";
import { fetchThemesActionCreator } from "~/services/Themes/themes.actions";
import API from "~/utils/API";

export type View = "mission" | "impact" | "users" | "figures" | "team" | "contributors" | "steps";

const MissionImpact: NextPage = () => {
interface Props {
structuresStatistics: GetStructureStatisticsResponse;
translationStatistics: TranslationStatisticsResponse;
}

const MissionImpact = (props: Props) => {
const { t } = useTranslation();
const teamData = useTeamData();

Expand Down Expand Up @@ -308,8 +319,21 @@ const MissionImpact: NextPage = () => {
<Title2 className="!text-center">{t("MissionImpact.community_title")}</Title2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-10">
<RICard
image={CommunityIlluDispositifs}
imageWidth={240}
imageComponent={
<div className="relative inline-block">
<Image
src={CommunityIlluDispositifs}
alt=""
width={240}
height={80}
style={{ objectFit: "contain" }}
/>
<ImageCustomFigure>
{(props.translationStatistics.nbRedactors || 0) +
(props.structuresStatistics.nbStructureAdmins || 0)}
</ImageCustomFigure>
</div>
}
title={t("MissionImpact.community_dispositifs_title")}
footer={
<Badge severity="new" noIcon>
Expand All @@ -321,8 +345,12 @@ const MissionImpact: NextPage = () => {
<p>{t("MissionImpact.community_dispositifs_subtitle")}</p>
</RICard>
<RICard
image={CommunityIlluCda}
imageWidth={240}
imageComponent={
<div className="relative inline-block">
<Image src={CommunityIlluCda} alt="" width={240} height={80} style={{ objectFit: "contain" }} />
<ImageCustomFigure>{props.structuresStatistics.nbCDA || 0}</ImageCustomFigure>
</div>
}
title={t("MissionImpact.community_cda_title")}
footer={
<Badge severity="new" noIcon>
Expand All @@ -334,8 +362,18 @@ const MissionImpact: NextPage = () => {
<p>{t("MissionImpact.community_cda_subtitle")}</p>
</RICard>
<RICard
image={CommunityIlluTraducteurs}
imageWidth={232}
imageComponent={
<div className="relative inline-block">
<Image
src={CommunityIlluTraducteurs}
alt=""
width={232}
height={80}
style={{ objectFit: "contain" }}
/>
<ImageCustomFigure>{props.translationStatistics.nbTranslators || 0}</ImageCustomFigure>
</div>
}
title={t("MissionImpact.community_traducteurs_title")}
footer={
<Badge severity="info" noIcon>
Expand Down Expand Up @@ -644,6 +682,32 @@ const MissionImpact: NextPage = () => {
);
};

export const getStaticProps = defaultStaticProps;
export const getStaticProps = wrapper.getStaticProps((store) => async ({ locale }) => {
const action = fetchThemesActionCreator();
store.dispatch(action);
store.dispatch(END);
await store.sagaTask?.toPromise();

let translationStatistics: TranslationStatisticsResponse = {};
let structuresStatistics: GetStructureStatisticsResponse = {};

try {
structuresStatistics = await API.getStructuresStatistics({
facets: ["nbCDA", "nbStructureAdmins"],
});
translationStatistics = await API.getTranslationStatistics({ facets: ["nbTranslators", "nbRedactors"] });
} catch (e) {
logger.error("[index] build page", e);
}

return {
props: {
...(await serverSideTranslations(getLanguageFromLocale(locale), ["common"])),
structuresStatistics,
translationStatistics,
},
revalidate: 60 * 10,
};
});

export default MissionImpact;

0 comments on commit 87f3612

Please sign in to comment.