From 629c9ce15be5c719494c02f12853a339359289cc Mon Sep 17 00:00:00 2001 From: ledouxm Date: Tue, 22 Oct 2024 13:24:27 +0200 Subject: [PATCH] feat: add pic status badges --- packages/frontend/src/features/InfoForm.tsx | 69 +++++++++++++-------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/packages/frontend/src/features/InfoForm.tsx b/packages/frontend/src/features/InfoForm.tsx index f74ca1f..62de2c0 100644 --- a/packages/frontend/src/features/InfoForm.tsx +++ b/packages/frontend/src/features/InfoForm.tsx @@ -1,6 +1,6 @@ import { InputGroup, InputGroupWithTitle } from "#components/InputGroup"; import { SpaceTypeChips } from "#components/chips/SpaceTypeChips"; -import { css } from "#styled-system/css"; +import { css, cx } from "#styled-system/css"; import { Box, Center, Divider, Flex, Grid, Stack, styled } from "#styled-system/jsx"; import { useTabsContext } from "@ark-ui/react/tabs"; import Button from "@codegouvfr/react-dsfr/Button"; @@ -264,28 +264,38 @@ const UploadImage = ({ reportId }: { reportId: string }) => { ); }; -// const ReportStatus = ({ status }: { status: "uploading" | "success" | "error" }) => { -// return ( -// -// -// {status === "draft" ? "Brouillon" : "Envoyé"} -// -// ); -// }; +const ReportStatus = ({ status }: { status: "uploading" | "success" | "error" }) => { + const { color, bgColor, label, icon } = statusData[status]; + + return ( + + + {label} + + ); +}; + +const statusData = { + uploading: { label: "En cours", bgColor: "#FEE7FC", color: "#855080", icon: "fr-icon-refresh-line" }, + success: { label: "Ok", bgColor: "#B8FEC9", color: "#18753C", icon: "fr-icon-success-line" }, + error: { label: "Erreur", bgColor: "#FEC9C9", color: "#853C3C", icon: "fr-icon-warning-line" }, +}; const ReportPictures = ({ statusMap }: { statusMap: Record }) => { const form = useFormContext(); @@ -293,13 +303,13 @@ const ReportPictures = ({ statusMap }: { statusMap: Record }) => const reportId = form.getValues().id; const tmpPicturesQuery = useLiveQuery( - db.tmp_pictures.liveMany({ where: { reportId }, orderBy: { createdAt: "asc" } }), + db.tmp_pictures.liveMany({ where: { reportId }, orderBy: { createdAt: "desc" } }), ); const picturesQuery = useLiveQuery( db.pictures.liveMany({ where: { reportId }, - orderBy: { createdAt: "asc" }, + orderBy: { createdAt: "desc" }, }), ); @@ -323,11 +333,15 @@ const ReportPictures = ({ statusMap }: { statusMap: Record }) => const mergePictureArrays = (a: Tmp_pictures[], b: Pictures[]) => { const map = new Map(); - for (const item of a) { + const sortByDate = (a: Tmp_pictures, b: Tmp_pictures) => { + return new Date(a.createdAt!).getTime() - new Date(b.createdAt!).getTime(); + }; + + for (const item of a.sort(sortByDate)) { map.set(item.id, item); } - for (const item of b) { + for (const item of b.sort(sortByDate)) { map.set(item.id, item); } @@ -371,6 +385,7 @@ const PictureThumbnail = ({ picture, index, status }: { picture: Pictures; index return ( {/* */} +