Fix reschedule uid not prepopulating fields (#1416)
This commit is contained in:
		
							parent
							
								
									09c4040ce5
								
							
						
					
					
						commit
						1c0c3c7690
					
				
					 1 changed files with 32 additions and 14 deletions
				
			
		| 
						 | 
					@ -96,7 +96,7 @@ const BookingPage = (props: BookingPageProps) => {
 | 
				
			||||||
  const date = asStringOrNull(router.query.date);
 | 
					  const date = asStringOrNull(router.query.date);
 | 
				
			||||||
  const timeFormat = asStringOrNull(router.query.clock) === "24h" ? "H:mm" : "h:mma";
 | 
					  const timeFormat = asStringOrNull(router.query.clock) === "24h" ? "H:mm" : "h:mma";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const [guestToggle, setGuestToggle] = useState(false);
 | 
					  const [guestToggle, setGuestToggle] = useState(props.booking && props.booking.attendees.length > 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  type Location = { type: LocationType; address?: string };
 | 
					  type Location = { type: LocationType; address?: string };
 | 
				
			||||||
  // it would be nice if Prisma at some point in the future allowed for Json<Location>; as of now this is not the case.
 | 
					  // it would be nice if Prisma at some point in the future allowed for Json<Location>; as of now this is not the case.
 | 
				
			||||||
| 
						 | 
					@ -139,20 +139,38 @@ const BookingPage = (props: BookingPageProps) => {
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const defaultValues = () => {
 | 
				
			||||||
 | 
					    if (!rescheduleUid) {
 | 
				
			||||||
 | 
					      return {
 | 
				
			||||||
 | 
					        name: (router.query.name as string) || "",
 | 
				
			||||||
 | 
					        email: (router.query.email as string) || "",
 | 
				
			||||||
 | 
					        notes: (router.query.notes as string) || "",
 | 
				
			||||||
 | 
					        guests: ensureArray(router.query.guest) as string[],
 | 
				
			||||||
 | 
					        customInputs: props.eventType.customInputs.reduce(
 | 
				
			||||||
 | 
					          (customInputs, input) => ({
 | 
				
			||||||
 | 
					            ...customInputs,
 | 
				
			||||||
 | 
					            [input.id]: router.query[slugify(input.label)],
 | 
				
			||||||
 | 
					          }),
 | 
				
			||||||
 | 
					          {}
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (!props.booking || !props.booking.attendees.length) {
 | 
				
			||||||
 | 
					      return {};
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const primaryAttendee = props.booking.attendees[0];
 | 
				
			||||||
 | 
					    if (!primaryAttendee) {
 | 
				
			||||||
 | 
					      return {};
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      name: primaryAttendee.name || "",
 | 
				
			||||||
 | 
					      email: primaryAttendee.email || "",
 | 
				
			||||||
 | 
					      guests: props.booking.attendees.slice(1).map((attendee) => attendee.email),
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const bookingForm = useForm<BookingFormValues>({
 | 
					  const bookingForm = useForm<BookingFormValues>({
 | 
				
			||||||
    defaultValues: {
 | 
					    defaultValues: defaultValues(),
 | 
				
			||||||
      name: (router.query.name as string) || "",
 | 
					 | 
				
			||||||
      email: (router.query.email as string) || "",
 | 
					 | 
				
			||||||
      notes: (router.query.notes as string) || "",
 | 
					 | 
				
			||||||
      guests: ensureArray(router.query.guest),
 | 
					 | 
				
			||||||
      customInputs: props.eventType.customInputs.reduce(
 | 
					 | 
				
			||||||
        (customInputs, input) => ({
 | 
					 | 
				
			||||||
          ...customInputs,
 | 
					 | 
				
			||||||
          [input.id]: router.query[slugify(input.label)],
 | 
					 | 
				
			||||||
        }),
 | 
					 | 
				
			||||||
        {}
 | 
					 | 
				
			||||||
      ),
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const selectedLocation = useWatch({
 | 
					  const selectedLocation = useWatch({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue