This repository was archived by the owner on Feb 10, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments