From b4980b4a538de35732e54b171b2651e006aade86 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Tue, 28 Nov 2023 01:22:35 +0400 Subject: [PATCH] Clear when re-opening form --- .../SecretListView/CreateReminderForm.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/frontend/src/views/SecretMainPage/components/SecretListView/CreateReminderForm.tsx b/frontend/src/views/SecretMainPage/components/SecretListView/CreateReminderForm.tsx index b8846b4ab..3474e6e88 100644 --- a/frontend/src/views/SecretMainPage/components/SecretListView/CreateReminderForm.tsx +++ b/frontend/src/views/SecretMainPage/components/SecretListView/CreateReminderForm.tsx @@ -9,8 +9,6 @@ import { z } from "zod"; import { Button, FormControl, Input, Modal, ModalContent, TextArea } from "@app/components/v2"; -export type TReminderFormSchema = z.infer; - const ReminderFormSchema = z.object({ note: z.string().optional(), days: z @@ -19,6 +17,7 @@ const ReminderFormSchema = z.object({ .max(365, { message: "Must be less than 365 days" }), cron: z.string().refine(isValidCron, { message: "Invalid cron expression" }) }); +export type TReminderFormSchema = z.infer; interface ReminderFormProps { isOpen: boolean; @@ -29,6 +28,7 @@ export const CreateReminderForm = ({ isOpen, onOpenChange }: ReminderFormProps) const { register, watch, + reset, setValue, handleSubmit, formState: { errors, isSubmitting } @@ -44,10 +44,19 @@ export const CreateReminderForm = ({ isOpen, onOpenChange }: ReminderFormProps) }; useEffect(() => { - if (!daysWatch) return; - setValue("cron", `0 0 */${daysWatch} * *`); + if (!daysWatch) { + setValue("cron", ""); + } else { + setValue("cron", `0 0 */${daysWatch} * *`); + } }, [daysWatch]); + useEffect(() => { + if (isOpen) { + reset(); + } + }, [isOpen]); + return ( setValue("days", parseInt(el.target.value, 10))} type="number" placeholder="every 5 days" - onChange={(el) => setValue("days", parseInt(el.target.value, 10))} /> {!!daysWatch && cronWatch && isValidCron(cronWatch) && (