Skip to content

Commit

Permalink
fix: select default reservation unit in calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed May 22, 2024
1 parent 0f40d5a commit 1c548eb
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { addDays, formatISO, startOfDay, subDays } from "date-fns";
import { AutoGrid, HorisontalFlex } from "@/styles/layout";
import { ReservationUnitCalendar } from "./ReservationUnitCalendar";
Expand All @@ -19,9 +19,14 @@ export function ReservationUnitCalendarView({
const [reservationUnitPk, setReservationUnitPk] = useState(-1);

const valueOption =
reservationUnitOptions.find((o) => o.value === reservationUnitPk) ??
reservationUnitOptions[0] ??
null;
reservationUnitOptions.find((o) => o.value === reservationUnitPk) ?? null;

// Set the first reservation unit as the default
useEffect(() => {
if (reservationUnitOptions.length > 0) {
setReservationUnitPk(reservationUnitOptions[0].value);
}
}, [reservationUnitOptions]);

const onChange = (reservationUnits: { label: string; value: number }) => {
setReservationUnitPk(reservationUnits.value);
Expand Down

0 comments on commit 1c548eb

Please sign in to comment.