Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

fix(BranchInfo): sort OpeningHours & hide deleted #424

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/components/info/BranchInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -45,6 +55,9 @@ const BranchInfo = ({
branch: Branch;
openingHours: OpeningHour[];
}) => {
const processedOpeningHours = openingHours
.filter(({ id }) => (branch.openingHours as string[])?.includes(id))
.sort(compareOpeningHours);
return (
<Box
sx={{ display: "flex", flexDirection: "column", alignItems: "center" }}
Expand All @@ -65,7 +78,7 @@ const BranchInfo = ({
{branch.location?.address}
</Box>
)}
{openingHours.length === 0 && (
{processedOpeningHours.length === 0 && (
<>
<Alert severity="info" data-testid="noHours" sx={{ my: 4 }}>
Sesongen er over – eller åpningstidene er ikke klare enda. Du kan
Expand All @@ -74,7 +87,7 @@ const BranchInfo = ({
<ContactInfo />
</>
)}
{openingHours.length > 0 && (
{processedOpeningHours.length > 0 && (
<TableContainer component={Paper}>
<Table aria-label="tabell over åpningstider">
<TableHead>
Expand All @@ -85,7 +98,7 @@ const BranchInfo = ({
</TableRow>
</TableHead>
<TableBody>
{openingHours.map((openingHour) => (
{processedOpeningHours.map((openingHour) => (
<OpeningHourRow
key={openingHour.id}
openingHour={openingHour}
Expand Down
Loading