From fedeccda20797304300731ea1add62e4b3898f61 Mon Sep 17 00:00:00 2001 From: Lars Mitsem Selbekk Date: Tue, 16 Jan 2024 01:40:12 +0100 Subject: [PATCH] fix(BranchInfo): sort OpeningHours & hide deleted There is a bug where bladmin only deletes the references to OpeningHours in the branch, and not the OpeningHours themselves, which is what is queried. Until the bladmin bug is fixed, this hides OpeningHours which are not referenced from the branch. --- src/components/info/BranchInfo.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/components/info/BranchInfo.tsx b/src/components/info/BranchInfo.tsx index 41c5f0c..1575de9 100644 --- a/src/components/info/BranchInfo.tsx +++ b/src/components/info/BranchInfo.tsx @@ -14,6 +14,16 @@ import "moment/locale/nb"; import BranchSelect from "components/BranchSelect"; import ContactInfo from "components/info/ContactInfo"; +const compareOpeningHours = (a: OpeningHour, b: OpeningHour): number => { + if (a.from < b.from) { + return -1; + } + if (a.from > b.from) { + return 1; + } + return 0; +}; + const OpeningHourRow = ({ openingHour }: { openingHour: OpeningHour }) => { const fromDate = moment(openingHour.from).locale("nb"); const toDate = moment(openingHour.to).locale("nb"); @@ -45,6 +55,9 @@ const BranchInfo = ({ branch: Branch; openingHours: OpeningHour[]; }) => { + const processedOpeningHours = openingHours + .filter(({ id }) => (branch.openingHours as string[])?.includes(id)) + .sort(compareOpeningHours); return ( )} - {openingHours.length === 0 && ( + {processedOpeningHours.length === 0 && ( <> Sesongen er over – eller åpningstidene er ikke klare enda. Du kan @@ -74,7 +87,7 @@ const BranchInfo = ({ )} - {openingHours.length > 0 && ( + {processedOpeningHours.length > 0 && ( @@ -85,7 +98,7 @@ const BranchInfo = ({ - {openingHours.map((openingHour) => ( + {processedOpeningHours.map((openingHour) => (