Skip to content

Commit

Permalink
fix: mentions legales ssr (#3406)
Browse files Browse the repository at this point in the history
  • Loading branch information
rap2hpoutre authored Dec 4, 2023
1 parent 57e6236 commit 7c2b2ce
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ fileignoreconfig:
checksum: 437a1f461d7764c51f288128de18506f4c22078c109238a41e8883a813b7ac55
- filename: server/src/common/actions/effectifs.actions.ts
checksum: 32225fd2335732e86cceb6b3bb90e5e4a93c976090cf9445c7243f555638fd86
- filename: ui/pages/mentions-legales.tsx
checksum: a2f835244846eceb8330f07846c128d318de81c5e46741be536b554726b4372c
scopeconfig:
- scope: node
custom_patterns:
Expand Down
1 change: 0 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"node-ovh-objectstorage": "2.0.5",
"nodemailer": "6.8.0",
"nodemailer-html-to-text": "3.2.0",
"notion-client": "^6.16.0",
"oleoduc": "0.7.0",
"omit-deep": "0.3.0",
"openapi3-ts": "4.0.2",
Expand Down
10 changes: 0 additions & 10 deletions server/src/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import cors from "cors";
import express, { Application } from "express";
import Joi from "joi";
import { ObjectId, WithId } from "mongodb";
import { NotionAPI } from "notion-client";
import passport from "passport";
import { typesEffectifNominatif } from "shared/constants/indicateurs";
import swaggerUi from "swagger-ui-express";
Expand Down Expand Up @@ -140,8 +139,6 @@ import organismesRouter from "./routes/specific.routes/organismes.routes";

const openapiSpecs = JSON.parse(fs.readFileSync(openApiFilePath, "utf8"));

const notion = new NotionAPI();

/**
* Create the express app
*/
Expand Down Expand Up @@ -211,13 +208,6 @@ function setupRoutes(app: Application) {
};
})
)
.get(
"/api/mentions-legales",
returnResult(async () => {
const recordMap = await notion.getPage("Mentions-l-gales-002a2868ea2f46cdb2d73207d12b6075");
return recordMap;
})
)
.post(
"/api/v1/organismes/search-by-siret",
returnResult(async (req) => {
Expand Down
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"luxon": "3.3.0",
"next": "13.2.3",
"next-plausible": "3.7.2",
"notion-client": "^6.16.0",
"notion-types": "^6.16.0",
"react": "18.2.0",
"react-accessible-treeview": "2.8.0",
Expand Down
51 changes: 13 additions & 38 deletions ui/pages/mentions-legales.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,26 @@
import { Center, Spinner } from "@chakra-ui/react";
import { GetServerSidePropsContext } from "next";
import { GetStaticProps, InferGetStaticPropsType } from "next";
import { NotionAPI } from "notion-client";
import { ExtendedRecordMap } from "notion-types";
import { useEffect, useState } from "react";
import { NotionRenderer } from "react-notion-x";

import { _get } from "@/common/httpClient";
import { NotionDoc } from "@/components/NotionDoc";
import SimplePage from "@/components/Page/SimplePage";

import "react-notion-x/src/styles.css";

const isInitialServerSideProps = (context: GetServerSidePropsContext) =>
context.req?.url?.indexOf("/_next/data/") === -1;

export const getServerSideProps = async (context) => {
try {
const isInitial = isInitialServerSideProps(context);
if (!isInitial) return { props: {} };
const dataSSR = await _get("/api/mentions-legales");
return { props: { dataSSR } };
} catch (e) {
console.error(e);
return { props: {} };
}
};

export default function Home({ dataSSR }: { dataSSR: ExtendedRecordMap }) {
const [data, setData] = useState(dataSSR);
const [isLoading, setIsLoading] = useState(!dataSSR);

useEffect(() => {
if (dataSSR) return;
(async () => {
setIsLoading(true);
setData(await _get("/api/mentions-legales"));
setIsLoading(false);
})();
}, []);
export const getStaticProps = (async () => {
const notion = new NotionAPI();
const recordMap = await notion.getPage("Mentions-l-gales-002a2868ea2f46cdb2d73207d12b6075");
// const data = await _get("/api/mentions-legales");
return { props: { data: recordMap }, revalidate: 60 * 30 };
}) satisfies GetStaticProps<{
data: ExtendedRecordMap;
}>;

export default function MentionsLegales({ data }: InferGetStaticPropsType<typeof getStaticProps>) {
return (
<SimplePage title="Mentions légales">
{isLoading ? (
<Center>
<Spinner />
</Center>
) : (
<NotionDoc recordMap={data} />
)}
<NotionRenderer pageTitle={false} disableHeader={true} recordMap={data} fullPage={true} darkMode={false} />
</SimplePage>
);
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18137,7 +18137,6 @@ request-debug@latest:
node-ovh-objectstorage: 2.0.5
nodemailer: 6.8.0
nodemailer-html-to-text: 3.2.0
notion-client: ^6.16.0
oleoduc: 0.7.0
omit-deep: 0.3.0
openapi3-ts: 4.0.2
Expand Down Expand Up @@ -19785,6 +19784,7 @@ request-debug@latest:
luxon: 3.3.0
next: 13.2.3
next-plausible: 3.7.2
notion-client: ^6.16.0
notion-types: ^6.16.0
react: 18.2.0
react-accessible-treeview: 2.8.0
Expand Down

0 comments on commit 7c2b2ce

Please sign in to comment.