Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit c9d2f53

Browse files
committed
fix: can't make reservation if there is no city
1 parent 909c39a commit c9d2f53

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

apps/ui/components/reservation/Step0.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,19 @@ const Step0 = ({
8787
return fields.indexOf(a) - fields.indexOf(b);
8888
}) || [];
8989

90-
const includesReserveeType =
91-
reservationUnit?.metadataSet?.supportedFields?.includes("reservee_type");
90+
const { supportedFields } = reservationUnit.metadataSet ?? {};
91+
const includesReserveeType = supportedFields?.includes("reservee_type");
9292
const reserveeType = watch("reserveeType");
9393
const homeCity = watch("homeCity");
94+
const includesHomeCity = supportedFields?.includes("home_city");
9495

9596
if (includesReserveeType && isSubmitted && !reserveeType)
9697
errorKeys.push("reserveeType");
9798

99+
const isHomeCityValid = !includesHomeCity || Boolean(homeCity);
100+
const isReserveeTypeValid = !includesReserveeType || Boolean(reserveeType);
101+
const submitDisabled = !isValid || !isReserveeTypeValid || !isHomeCityValid;
102+
98103
return (
99104
<Form
100105
onSubmit={(e) => {
@@ -191,10 +196,7 @@ const Step0 = ({
191196
<MediumButton
192197
variant="primary"
193198
type="submit"
194-
disabled={
195-
!isValid ||
196-
(includesReserveeType && (!reserveeType || homeCity === 0))
197-
}
199+
disabled={submitDisabled}
198200
iconRight={<IconArrowRight aria-hidden />}
199201
data-test="reservation__button--update"
200202
isLoading={isSubmitting}

apps/ui/pages/reservation-unit/[...params].tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,13 @@ const ReservationUnitReservationWithReservationProp = ({
236236
reserveeAddressCity: reservation?.reserveeAddressCity ?? "",
237237
reserveeAddressZip: reservation?.reserveeAddressZip ?? "",
238238
// TODO is this correct? it used to just pick the homeCity (but that makes no sense since it's typed as a number)
239-
homeCity: reservation?.homeCity?.pk ?? 0,
239+
// no it's not correct, the types and MetaFields are based on a number but the front sets it as { label: string, value: number }
240+
// requires typing the useFormContext properly and refactoring all setters.
241+
homeCity: reservation?.homeCity?.pk ?? undefined,
240242
};
241-
// TODO don't use defaultValues, use values (and reset on fetch) from the form
243+
// TODO is defaultValues correct? it's prefilled from the profile data and we are not refetching at any point.
244+
// If we would refetch values would be more correct with reset hook.
245+
// Also if this is ever initialised without the data it will not prefill the form.
242246
const form = useForm<Inputs>({ defaultValues, mode: "onBlur" });
243247
const { handleSubmit, watch } = form;
244248

0 commit comments

Comments
 (0)