From 20309edb6ff699c62ce101c0b9bb7a8129d233c9 Mon Sep 17 00:00:00 2001 From: Antoine Lelong Date: Tue, 19 Nov 2024 12:14:07 +0100 Subject: [PATCH 1/2] fix: change get of id query params from getServerSideProps to client side --- webapp/CHANGELOG.md | 6 +-- .../pages/dashboard/offer/cje/[id]/index.tsx | 44 ++++++------------- .../pages/dashboard/offer/obiz/[id]/index.tsx | 41 +++++------------ 3 files changed, 25 insertions(+), 66 deletions(-) diff --git a/webapp/CHANGELOG.md b/webapp/CHANGELOG.md index 1c824aaa..b653b5bf 100644 --- a/webapp/CHANGELOG.md +++ b/webapp/CHANGELOG.md @@ -1,16 +1,14 @@ # [0.69.0](https://github.com/SocialGouv/carte-jeune-engage/compare/v0.68.2...v0.69.0) (2024-11-19) - ### Features -* CRISP help in dashboard page ([504e645](https://github.com/SocialGouv/carte-jeune-engage/commit/504e64560ac74d47d9c265cdfb1c29441dc58e0b)) +- CRISP help in dashboard page ([504e645](https://github.com/SocialGouv/carte-jeune-engage/commit/504e64560ac74d47d9c265cdfb1c29441dc58e0b)) ## [0.68.2](https://github.com/SocialGouv/carte-jeune-engage/compare/v0.68.1...v0.68.2) (2024-11-19) - ### Bug Fixes -* add defensive code in getserversideprops offer & log ([07d6e1b](https://github.com/SocialGouv/carte-jeune-engage/commit/07d6e1b1a9dd4738d6943558d17fbbd7aa321c85)) +- add defensive code in getserversideprops offer & log ([07d6e1b](https://github.com/SocialGouv/carte-jeune-engage/commit/07d6e1b1a9dd4738d6943558d17fbbd7aa321c85)) ## [0.68.1](https://github.com/SocialGouv/carte-jeune-engage/compare/v0.68.0...v0.68.1) (2024-11-19) diff --git a/webapp/src/pages/dashboard/offer/cje/[id]/index.tsx b/webapp/src/pages/dashboard/offer/cje/[id]/index.tsx index 6034840c..3236face 100644 --- a/webapp/src/pages/dashboard/offer/cje/[id]/index.tsx +++ b/webapp/src/pages/dashboard/offer/cje/[id]/index.tsx @@ -10,7 +10,6 @@ import { motion, AnimatePresence } from "framer-motion"; import OfferContent from "~/components/offer/page/OfferContent"; import CouponContent from "~/components/offer/page/CouponContent"; import { isIOS } from "~/utils/tools"; -import { GetServerSideProps } from "next"; const flipVariants = { hidden: { rotateY: 90 }, @@ -18,21 +17,25 @@ const flipVariants = { exit: { rotateY: -90 }, }; -type OfferCjePageProps = { - offer_id: string; -}; - -export default function OfferCjePage({ offer_id }: OfferCjePageProps) { +export default function OfferCjePage() { const router = useRouter(); + const { id: offer_id } = router.query as { id: string }; + const { data: resultOffer, isLoading: isLoadingOffer } = - api.offer.getById.useQuery({ id: parseInt(offer_id), source: "cje" }); + api.offer.getById.useQuery( + { id: parseInt(offer_id), source: "cje" }, + { enabled: !!offer_id } + ); const { data: resultCoupon, isLoading: isLoadingCoupon, refetch: refetchCoupon, - } = api.coupon.getOne.useQuery({ offer_id: parseInt(offer_id) }); + } = api.coupon.getOne.useQuery( + { offer_id: parseInt(offer_id) }, + { enabled: !!offer_id } + ); const { data: offer } = resultOffer || {}; const { data: coupon } = resultCoupon || {}; @@ -126,8 +129,8 @@ export default function OfferCjePage({ offer_id }: OfferCjePageProps) { await increaseNbSeen({ offer_id: parseInt(offer_id) }); }; - mutateData(); - }, []); + if (!!offer_id) mutateData(); + }, [offer_id]); useEffect(() => { if ( @@ -228,24 +231,3 @@ export default function OfferCjePage({ offer_id }: OfferCjePageProps) { ); } - -export const getServerSideProps: GetServerSideProps = async ({ - query, - params, -}) => { - const offer_id = query.id || params?.id || null; - - if (!offer_id || Array.isArray(offer_id)) { - console.error("Invalid offer_id in getServerSideProps:", { query, params }); - return { - redirect: { - destination: "/dashboard", - permanent: false, - }, - }; - } - - return { - props: { offer_id }, - }; -}; diff --git a/webapp/src/pages/dashboard/offer/obiz/[id]/index.tsx b/webapp/src/pages/dashboard/offer/obiz/[id]/index.tsx index ee27c436..00d371f4 100644 --- a/webapp/src/pages/dashboard/offer/obiz/[id]/index.tsx +++ b/webapp/src/pages/dashboard/offer/obiz/[id]/index.tsx @@ -11,10 +11,9 @@ import { Text, useDisclosure, } from "@chakra-ui/react"; -import { GetServerSideProps } from "next"; import Head from "next/head"; import { useRouter } from "next/router"; -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { BarcodeIcon } from "~/components/icons/barcode"; import LoadingLoader from "~/components/LoadingLoader"; import ObizOrderProcessModal from "~/components/modals/ObizOrderProcessModal"; @@ -27,13 +26,11 @@ import { getItemsTermsOfUse } from "~/payload/components/CustomSelectTermsOfUse" import { api } from "~/utils/api"; import { cleanHtml } from "~/utils/tools"; -type OfferObizPageProps = { - offer_id: string; -}; - -export default function OfferObizPage({ offer_id }: OfferObizPageProps) { +export default function OfferObizPage() { const router = useRouter(); + const { id: offer_id } = router.query as { id: string }; + const { isOpen: isOpenOrderProcessModal, onOpen: onOpenOrderProcessModal, @@ -46,7 +43,10 @@ export default function OfferObizPage({ offer_id }: OfferObizPageProps) { api.offer.increaseNbSeen.useMutation(); const { data: resultOffer, isLoading: isLoadingOffer } = - api.offer.getById.useQuery({ id: parseInt(offer_id), source: "obiz" }); + api.offer.getById.useQuery( + { id: parseInt(offer_id), source: "obiz" }, + { enabled: !!offer_id } + ); const { data: offer } = resultOffer || {}; @@ -80,8 +80,8 @@ export default function OfferObizPage({ offer_id }: OfferObizPageProps) { await increaseNbSeen({ offer_id: parseInt(offer_id) }); }; - mutateData(); - }, []); + if (!!offer_id) mutateData(); + }, [offer_id]); if (isLoadingOffer || !router.isReady) { return ( @@ -277,24 +277,3 @@ export default function OfferObizPage({ offer_id }: OfferObizPageProps) { ); } - -export const getServerSideProps: GetServerSideProps = async ({ - query, - params, -}) => { - const offer_id = query.id || params?.id || null; - - if (!offer_id || Array.isArray(offer_id)) { - console.error("Invalid offer_id in getServerSideProps:", { query, params }); - return { - redirect: { - destination: "/dashboard", - permanent: false, - }, - }; - } - - return { - props: { offer_id }, - }; -}; From 892cf6a6e652cb97c8faa2985b817289a3b258ba Mon Sep 17 00:00:00 2001 From: Social Groovy Bot <45039513+SocialGroovyBot@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:14:49 +0000 Subject: [PATCH 2/2] chore(release): 0.69.1 --- webapp/CHANGELOG.md | 7 +++++++ webapp/package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/webapp/CHANGELOG.md b/webapp/CHANGELOG.md index b653b5bf..4d37f088 100644 --- a/webapp/CHANGELOG.md +++ b/webapp/CHANGELOG.md @@ -1,3 +1,10 @@ +## [0.69.1](https://github.com/SocialGouv/carte-jeune-engage/compare/v0.69.0...v0.69.1) (2024-11-19) + + +### Bug Fixes + +* change get of id query params from getServerSideProps to client side ([20309ed](https://github.com/SocialGouv/carte-jeune-engage/commit/20309edb6ff699c62ce101c0b9bb7a8129d233c9)) + # [0.69.0](https://github.com/SocialGouv/carte-jeune-engage/compare/v0.68.2...v0.69.0) (2024-11-19) ### Features diff --git a/webapp/package.json b/webapp/package.json index eea5f317..7dc37d1f 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -1,6 +1,6 @@ { "name": "webapp", - "version": "0.69.0", + "version": "0.69.1", "private": true, "scripts": { "dev": "next dev",