Skip to content

Commit

Permalink
feat(dsfr): ajout de la page stats (#6090)
Browse files Browse the repository at this point in the history
* fix: pandacss

* fix: build

* fix: build

* fix(stats): add page

* fix: stats
  • Loading branch information
maxgfr authored Sep 2, 2024
1 parent 5e70276 commit 84fd66c
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 114 deletions.
36 changes: 36 additions & 0 deletions packages/code-du-travail-frontend/app/stats/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Metadata } from "next";
import { DsfrLayout } from "../../src/modules/layout";
import { Stats } from "../../src/modules/stats";
import { getStatsService } from "../../src/api";
import { cache } from "react";
import { REVALIDATE_TIME_DAY } from "../../src/config";

export const dynamic = "force-static";

export const revalidate = REVALIDATE_TIME_DAY;

export const metadata: Metadata = {
title: "Statistiques",
description: "Statistiques d’utilisation du Code du travail numérique",
};

const getStats = cache(async () => {
return getStatsService();
});

async function Index() {
const data = await getStats();

return (
<DsfrLayout>
<Stats
nbDocuments={data.nbDocuments}
nbVisits={data.nbVisits}
nbSearches={data.nbSearches}
nbPageViews={data.nbPageViews}
/>
</DsfrLayout>
);
}

export default Index;
112 changes: 0 additions & 112 deletions packages/code-du-travail-frontend/pages/stats.tsx

This file was deleted.

5 changes: 3 additions & 2 deletions packages/code-du-travail-frontend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export const COMMIT = process.env.NEXT_PUBLIC_COMMIT ?? "";
export const SITE_URL =
process.env.NEXT_PUBLIC_SITE_URL ?? `http://localhost:3000`;
export const PACKAGE_VERSION = version;
export const PIWIK_SITE_ID = process.env.NEXT_PUBLIC_PIWIK_SITE_ID ?? "";
export const PIWIK_URL = process.env.NEXT_PUBLIC_PIWIK_URL ?? "";
export const PIWIK_SITE_ID = process.env.NEXT_PUBLIC_PIWIK_SITE_ID ?? "3";
export const PIWIK_URL =
process.env.NEXT_PUBLIC_PIWIK_URL ?? "https://matomo.fabrique.social.gouv.fr";
export const IS_PREPROD =
process.env.NEXT_PUBLIC_IS_PREPRODUCTION_DEPLOYMENT ?? false;
export const IS_PROD =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { fr } from "@codegouvfr/react-dsfr";
import { CallOut } from "@codegouvfr/react-dsfr/CallOut";
import { css } from "../../../styled-system/css";

type StatsProps = {
title: string;
metric: number;
};

export const StatsDisplay = (props: StatsProps) => (
<div className={fr.cx("fr-col-12", "fr-col-md-3")}>
<CallOut className={`${callOut}`}>
<span className={`${metric} ${fr.cx("fr-mt-4v", "fr-display--xs")}`}>
{props.metric}
</span>
<span className={`${title} ${fr.cx("fr-text--bold", "fr-text--xl")}`}>
{props.title}
</span>
</CallOut>
</div>
);

const metric = css({
textAlign: "right",
display: "block",
});

const title = css({
textAlign: "left",
});

const callOut = css({
height: "100%",
});
26 changes: 26 additions & 0 deletions packages/code-du-travail-frontend/src/modules/stats/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { fr } from "@codegouvfr/react-dsfr";
import { StatsDisplay } from "./StatsDisplay";

type StatsProps = {
nbDocuments: number;
nbVisits: number;
nbSearches: number;
nbPageViews: number;
};

export const Stats = (props: StatsProps) => (
<div className={fr.cx("fr-grid-row")}>
<div className={fr.cx("fr-my-4w", "fr-col-12")}>
<h1 className={fr.cx("fr-mt-0")}>Statistiques d&apos;utilisation</h1>
<div className={fr.cx("fr-grid-row", "fr-grid-row--gutters")}>
<StatsDisplay title="Contenus référencés" metric={props.nbDocuments} />
<StatsDisplay title="Visites" metric={props.nbVisits} />
<StatsDisplay title="Recherches" metric={props.nbSearches} />
<StatsDisplay title="Consultations" metric={props.nbPageViews} />
</div>
<p className={fr.cx("fr-mt-4v")}>
Statistiques d’utilisation depuis le 01/01/2020
</p>
</div>
</div>
);

0 comments on commit 84fd66c

Please sign in to comment.