Skip to content

Commit

Permalink
fix(BranchInfo): sort OpeningHours & hide deleted (#424)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LarsSelbekk authored Jan 16, 2024
1 parent ad28ed9 commit 8fc0c7a
Showing 1 changed file with 16 additions and 3 deletions.
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

1 comment on commit 8fc0c7a

@vercel
Copy link

@vercel vercel bot commented on 8fc0c7a Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bl-next – ./

bl-next-git-production-boklisten.vercel.app
next.boklisten.no
bl-next-boklisten.vercel.app

Please sign in to comment.