fix: type

This commit is contained in:
Lorenzo Migliorero
2024-07-25 09:15:13 +02:00
parent 115c8641e7
commit 4cacc6b3d1

View File

@@ -37,12 +37,11 @@ const hostnameRegex = /^[a-zA-Z0-9][a-zA-Z0-9\.-]*\.[a-zA-Z]{2,}$/;
const domain = z.object({ const domain = z.object({
host: z.string().regex(hostnameRegex, { message: "Invalid hostname" }), host: z.string().regex(hostnameRegex, { message: "Invalid hostname" }),
path: z.string().min(1).nullable(), path: z.string().min(1),
port: z port: z
.number() .number()
.min(1, { message: "Port must be at least 1" }) .min(1, { message: "Port must be at least 1" })
.max(65535, { message: "Port must be 65535 or below" }) .max(65535, { message: "Port must be 65535 or below" }),
.nullable(),
https: z.boolean(), https: z.boolean(),
certificateType: z.enum(["letsencrypt", "none"]), certificateType: z.enum(["letsencrypt", "none"]),
}); });
@@ -75,20 +74,26 @@ export const AddDomain = ({
? api.domain.update.useMutation() ? api.domain.update.useMutation()
: api.domain.create.useMutation(); : api.domain.create.useMutation();
const defaultValues: Domain = {
host: "",
https: false,
path: "/",
port: 3000,
certificateType: "none",
};
const form = useForm<Domain>({ const form = useForm<Domain>({
defaultValues: { defaultValues,
host: "",
https: false,
path: "/",
port: 3000,
certificateType: "none",
},
resolver: zodResolver(domain), resolver: zodResolver(domain),
}); });
useEffect(() => { useEffect(() => {
if (data) { if (data) {
form.reset(data); form.reset({
...data,
path: data.path || defaultValues.path,
port: data.port || defaultValues.port,
});
} }
}, [form, form.reset, data]); }, [form, form.reset, data]);
@@ -107,11 +112,7 @@ export const AddDomain = ({
await mutateAsync({ await mutateAsync({
domainId, domainId,
applicationId, applicationId,
host: data.host, ...data,
https: data.https,
path: data.path,
port: data.port,
certificateType: data.certificateType,
}) })
.then(async () => { .then(async () => {
toast.success(dictionary.success); toast.success(dictionary.success);