fix: sync book event form values with bookingData (#14945)
* fix: sync book event form values with bookingData * fixup! fix: sync book event form values with bookingData
This commit is contained in:
1 parent
d15b7d8168
commit
726af4970c
3 files changed
+22
-8
No files matched your search
@@ -34,7 +34,10 @@ export function useInitialFormValues({
|
||||
extraOptions,
|
||||
prefillFormParams,
|
||||
}: UseInitialFormValuesProps) {
|
||||
const [initialValues, setDefaultValues] = useState<Record<string, unknown>>({});
|
||||
const [initialValues, setDefaultValues] = useState<{
|
||||
responses?: Partial<z.infer<ReturnType<typeof getBookingResponsesSchema>>>;
|
||||
bookingId?: number;
|
||||
}>({});
|
||||
const bookingData = useBookerStore((state) => state.bookingData);
|
||||
const formValues = useBookerStore((state) => state.formValues);
|
||||
useEffect(() => {
|
||||
@@ -104,6 +107,7 @@ export function useInitialFormValues({
|
||||
|
||||
const defaults = {
|
||||
responses: {} as Partial<z.infer<ReturnType<typeof getBookingResponsesSchema>>>,
|
||||
bookingId: bookingData?.id,
|
||||
};
|
||||
|
||||
const responses = eventType.bookingFields.reduce((responses, field) => {
|
||||
@@ -126,6 +130,7 @@ export function useInitialFormValues({
|
||||
formValues,
|
||||
isRescheduling,
|
||||
bookingData,
|
||||
bookingData?.id,
|
||||
rescheduleUid,
|
||||
email,
|
||||
name,
|
||||
@@ -134,7 +139,8 @@ export function useInitialFormValues({
|
||||
]);
|
||||
|
||||
// When initialValues is available(after doing async schema parsing) or session is available(so that we can prefill logged-in user email and name), we need to reset the form with the initialValues
|
||||
const key = `${Object.keys(initialValues).length}_${hasSession ? 1 : 0}`;
|
||||
// We also need the key to change if the bookingId changes, so that the form is reset and rerendered with the new initialValues
|
||||
const key = `${Object.keys(initialValues).length}_${hasSession ? 1 : 0}_${initialValues?.bookingId ?? 0}`;
|
||||
|
||||
return { initialValues, key };
|
||||
}
|
||||
Reference in new issue
Block a user