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) => (