From 20210d7471c6bd3d0c35704bd4007446c13763a9 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Mon, 27 Nov 2023 23:57:35 +0400 Subject: [PATCH] UI improvements --- .../SecretListView/CreateReminderForm.tsx | 42 ++++++++++++------- .../components/SecretListView/SecretItem.tsx | 2 +- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/frontend/src/views/SecretMainPage/components/SecretListView/CreateReminderForm.tsx b/frontend/src/views/SecretMainPage/components/SecretListView/CreateReminderForm.tsx index 426e9d6e6..b8846b4ab 100644 --- a/frontend/src/views/SecretMainPage/components/SecretListView/CreateReminderForm.tsx +++ b/frontend/src/views/SecretMainPage/components/SecretListView/CreateReminderForm.tsx @@ -1,3 +1,4 @@ +import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { faClock } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; @@ -8,13 +9,17 @@ 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 + .number() + .min(1, { message: "Must be at least 1 day" }) + .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; onOpenChange: (isOpen: boolean, data?: TReminderFormSchema) => void; @@ -24,16 +29,25 @@ export const CreateReminderForm = ({ isOpen, onOpenChange }: ReminderFormProps) const { register, watch, + setValue, handleSubmit, formState: { errors, isSubmitting } - } = useForm({ resolver: zodResolver(ReminderFormSchema) }); + } = useForm({ + resolver: zodResolver(ReminderFormSchema) + }); + const daysWatch = watch("days"); const cronWatch = watch("cron"); const handleFormSubmit = async (data: TReminderFormSchema) => { onOpenChange(false, data); }; + useEffect(() => { + if (!daysWatch) return; + setValue("cron", `0 0 */${daysWatch} * *`); + }, [daysWatch]); + return ( Set up a reminder for when this secret should be rotated. Everyone in the workspace will be notified when the reminder is triggered. -
- {/* eslint-disable-next-line react/jsx-no-target-blank */} - - - Learn more about cron expressions - - -
} > @@ -60,13 +66,17 @@ export const CreateReminderForm = ({ isOpen, onOpenChange }: ReminderFormProps)
- + setValue("days", parseInt(el.target.value, 10))} + /> - {!!cronWatch && isValidCron(cronWatch) && ( + {!!daysWatch && cronWatch && isValidCron(cronWatch) && (
{cronstrue.toString(cronWatch)}
)}
diff --git a/frontend/src/views/SecretMainPage/components/SecretListView/SecretItem.tsx b/frontend/src/views/SecretMainPage/components/SecretListView/SecretItem.tsx index ababdd95d..16c1f03bf 100644 --- a/frontend/src/views/SecretMainPage/components/SecretListView/SecretItem.tsx +++ b/frontend/src/views/SecretMainPage/components/SecretListView/SecretItem.tsx @@ -184,7 +184,7 @@ export const SecretItem = memo( <> { + onOpenChange={(_, data) => { setCreateReminderFormOpen.toggle(); if (data) {