Skip to content

Commit

Permalink
fix: reservation series edit
Browse files Browse the repository at this point in the history
- Don't validate start time nor allow user to change it.
- Don't allow user to change the type of series.
  • Loading branch information
joonatank committed Oct 16, 2024
1 parent 4d49347 commit 5ddd7a1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion apps/admin-ui/src/component/ReservationTypeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ function ReservationTypeForm({
reservationUnit,
children,
disableBufferToggle,
disableTypeSelect,
}: {
reservationUnit: TypeFormReservationUnit;
children?: React.ReactNode;
disableBufferToggle?: boolean;
disableTypeSelect?: boolean;
}) {
const { t } = useTranslation();

Expand All @@ -121,7 +123,7 @@ function ReservationTypeForm({
return (
<>
<Element $wide>
<TypeSelect />
<TypeSelect isDisabled={disableTypeSelect} />
</Element>
{type === ReservationTypeChoice.Blocked && (
<CommentsTextArea
Expand Down
1 change: 1 addition & 0 deletions apps/admin-ui/src/i18n/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ const translations: ITranslations = {
RESERVATION_END_DATE_TOO_FAR: [
"Ei pystytty luomaan varauksia yli 2 vuoden päähän",
],
RESERVATION_SERIES_ALREADY_STARTED: ["Toistuva varaus on jo alkanut"],
},
descriptive: {
"Reservation overlaps with reservation before due to buffer time.": [
Expand Down
4 changes: 1 addition & 3 deletions apps/admin-ui/src/schemas/recurringReservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ const RescheduleReservationSeriesFormSchemaRefined = (
// TODO do we need it here? reschedule might not have metadata
.passthrough()
// this refine works without partial since it's the last required value
.superRefine((val, ctx) =>
checkDateNotInPast(convertToDate(val.startingDate), ctx, "startingDate")
)
/* Don't validate start time since it's not editable */
.superRefine((val, ctx) =>
checkDateNotInPast(convertToDate(val.endingDate), ctx, "endingDate")
)
Expand Down
2 changes: 2 additions & 0 deletions apps/admin-ui/src/spa/reservations/[id]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ function EditReservation({
<ReservationTypeForm
reservationUnit={reservationUnit}
disableBufferToggle
// backend doesn't allow changing type for series but does allow it for single reservations
disableTypeSelect={reservation.recurringReservation?.pk != null}
>
{reservation.recurringReservation?.pk && (
<InnerTextInput
Expand Down
2 changes: 2 additions & 0 deletions apps/admin-ui/src/spa/reservations/[id]/series/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ function SeriesPageInner({ pk }: { pk: number }) {
control={control}
error={translateError(errors.startingDate?.message)}
required
// NOTE we can't change the start date of the series
disabled
/>

<ControlledDateInput
Expand Down

0 comments on commit 5ddd7a1

Please sign in to comment.