Hotfix/Event Type Save Error with Multiple Durations (#6154)

* Fix .length being undefined when form is submitted without any change to duration

* Fix type error

Co-authored-by: Alex van Andel <me@alexvanandel.com>
This commit is contained in:
Hariom BalharaandAlex van Andel authored and GitHub committed 2022-12-22 11:13:33 +00:00
1 parent 64ecce1ccb
commit a076418989
2 files changed
+14 -6

No files matched your search

@@ -290,7 +290,7 @@ export const EventSetupTab = (
setDefaultDuration(
selectedMultipleDuration.find((opt) => opt.value === option?.value) ?? null
);
formMethods.setValue("length", Number(option?.value));
if (option) formMethods.setValue("length", option.value);
}}
/>
</div>
@@ -298,14 +298,11 @@ export const EventSetupTab = (
) : (
<TextField
required
name="length"
type="number"
label={t("duration")}
addOnSuffix={<>{t("minutes")}</>}
defaultValue={eventType.length ?? 15}
onChange={(e) => {
formMethods.setValue("length", Number(e.target.value));
}}
{...formMethods.register("length")}
addOnSuffix={<>{t("minutes")}</>}
/>
)}
<div className="!mt-4 [&_label]:my-1 [&_label]:font-normal">
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { useAutoAnimate } from "@formkit/auto-animate/react";
import { zodResolver } from "@hookform/resolvers/zod";
import { PeriodType, Prisma, SchedulingType } from "@prisma/client";
import { GetServerSidePropsContext } from "next";
import { useRouter } from "next/router";
@@ -204,6 +205,16 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
),
metadata,
},
resolver: zodResolver(
z
.object({
// Length if string, is converted to a number or it can be a number
// Make it optional because it's not submitted from all tabs of the page
length: z.union([z.string().transform((val) => +val), z.number()]).optional(),
})
// TODO: Add schema for other fields later.
.passthrough()
),
});
const appsMetadata = formMethods.getValues("metadata")?.apps;