diff --git a/webapp/CHANGELOG.md b/webapp/CHANGELOG.md index f9b52ecc..464169e6 100644 --- a/webapp/CHANGELOG.md +++ b/webapp/CHANGELOG.md @@ -1,9 +1,8 @@ # [0.55.0](https://github.com/SocialGouv/carte-jeune-engage/compare/v0.54.3...v0.55.0) (2024-11-07) - ### Features -* handle merging multiple PDFs from order data ([e1d22c4](https://github.com/SocialGouv/carte-jeune-engage/commit/e1d22c4d5ab916c92dc28f87638d2c3a15f9879f)) +- handle merging multiple PDFs from order data ([e1d22c4](https://github.com/SocialGouv/carte-jeune-engage/commit/e1d22c4d5ab916c92dc28f87638d2c3a15f9879f)) ## [0.54.3](https://github.com/SocialGouv/carte-jeune-engage/compare/v0.54.2...v0.54.3) (2024-11-06) diff --git a/webapp/src/pages/dashboard/order/[id].tsx b/webapp/src/pages/dashboard/order/[id].tsx index 25223ebf..775b5a4c 100644 --- a/webapp/src/pages/dashboard/order/[id].tsx +++ b/webapp/src/pages/dashboard/order/[id].tsx @@ -10,21 +10,28 @@ import { } from "@chakra-ui/react"; import { useRouter } from "next/router"; import { useEffect, useMemo, useState } from "react"; +import { HiExclamation } from "react-icons/hi"; import { HiCheckCircle, HiClock, + HiExclamationCircle, HiEye, HiMinus, HiPlus, } from "react-icons/hi2"; import { MdOutlineFileDownload } from "react-icons/md"; +import { PiWarningFill } from "react-icons/pi"; import { BarcodeIcon } from "~/components/icons/barcode"; import LoadingLoader from "~/components/LoadingLoader"; import BackButton from "~/components/ui/BackButton"; import Image from "~/components/ui/Image"; import { Typewriter } from "~/components/ui/Typewriter"; import { api } from "~/utils/api"; -import { formatDateToDDMMYYYY, formatter2Digits } from "~/utils/tools"; +import { + formatDateToDDMMYYYY, + formatter2Digits, + isOlderThan24Hours, +} from "~/utils/tools"; export default function OrderObizPage() { const router = useRouter(); @@ -35,6 +42,7 @@ export default function OrderObizPage() { }; const [showDetails, setShowDetails] = useState(false); + const [isSynchronizing, setIsSynchronizing] = useState(true); const { data: resultOrder, @@ -47,6 +55,7 @@ export default function OrderObizPage() { const { mutateAsync: mutateOrderSync, isLoading: isLoadingSyncOrder } = api.order.synchronizeOrder.useMutation({ onSuccess: () => { + setIsSynchronizing(false); utils.order.getById.invalidate(); }, }); @@ -80,6 +89,11 @@ export default function OrderObizPage() { return; } + const orderHasIssue = + !isSynchronizing && + order.status !== "delivered" && + isOlderThan24Hours(order.createdAt); + const showPDF = () => { if (order.ticket && typeof order.ticket === "object" && order.ticket.url) { window.open(order.ticket.url, "_blank", "noopener,noreferrer"); @@ -97,9 +111,61 @@ export default function OrderObizPage() { } }; + const signalIssueWithOrder = () => {}; + const getOrderContent = () => { if (!order.articles) return; + if (orderHasIssue) { + return ( + + + + + + + Nous rencontrons un problème avec ce bon d’achat + + + Signalez votre problème maintenant pour obtenir de l’aide. + + + + + + + + + Votre paiement a bien été enregistré + + + + + + Votre bon d’achat n’est toujours pas arrivé + + + ); + } + if (order.status !== "delivered") { return ( @@ -249,10 +315,14 @@ export default function OrderObizPage() { shadow={"xl"} p={6} > - Valeur totale - - {amount}€ - + {!orderHasIssue && ( + <> + Valeur totale + + {amount}€ + + + )} {getOrderContent()} diff --git a/webapp/src/utils/tools.ts b/webapp/src/utils/tools.ts index 82a7c9b3..1f937415 100644 --- a/webapp/src/utils/tools.ts +++ b/webapp/src/utils/tools.ts @@ -35,6 +35,18 @@ export const formatDateToDDMMYYYY = (isoDate: string | Date): string => { return `${day}/${month}/${year}`; }; +export const isOlderThan24Hours = (dateString: string): boolean => { + const inputDate = new Date(dateString); + + const currentDate = new Date(); + + const diffInMs = currentDate.getTime() - inputDate.getTime(); + + const twentyFourHoursInMs = 86400000; + + return diffInMs > twentyFourHoursInMs; +}; + export const getTodayFrenchDate = () => { const date = new Date(); const frenchDate = date.toLocaleDateString("fr-FR", {