From c2bd259c1209c51e37328266ace54bcc92a592f7 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Thu, 15 Feb 2024 01:14:05 +0100 Subject: [PATCH] Added secret reminders to sidebar (and formatting) --- .../SecretListView/SecretDetaiSidebar.tsx | 536 ++++++++++-------- 1 file changed, 297 insertions(+), 239 deletions(-) diff --git a/frontend/src/views/SecretMainPage/components/SecretListView/SecretDetaiSidebar.tsx b/frontend/src/views/SecretMainPage/components/SecretListView/SecretDetaiSidebar.tsx index 1130c9d14..cf50e44f3 100644 --- a/frontend/src/views/SecretMainPage/components/SecretListView/SecretDetaiSidebar.tsx +++ b/frontend/src/views/SecretMainPage/components/SecretListView/SecretDetaiSidebar.tsx @@ -5,6 +5,7 @@ import { faCheckCircle, faCircle, faCircleDot, + faClock, faPlus, faTag } from "@fortawesome/free-solid-svg-icons"; @@ -33,9 +34,11 @@ import { Tooltip } from "@app/components/v2"; import { ProjectPermissionActions, ProjectPermissionSub, useProjectPermission } from "@app/context"; +import { useToggle } from "@app/hooks"; import { useGetSecretVersion } from "@app/hooks/api"; import { DecryptedSecret, UserWsKeyPair, WsTag } from "@app/hooks/api/types"; +import { CreateReminderForm } from "./CreateReminderForm"; import { formSchema, SecretActionType, TFormSchema } from "./SecretListView.utils"; type Props = { @@ -147,262 +150,317 @@ export const SecretDetailSidebar = ({ await onSaveSecret(secret, { ...secret, ...data }, () => reset()); }; + const [createReminderFormOpen, setCreateReminderFormOpen] = useToggle(false); + + const secretReminderRepeatDays = watch("reminderRepeatDays"); + const secretReminderNote = watch("reminderNote"); + return ( - { - if (isOpen && isDirty) { - if ( - // eslint-disable-next-line no-alert - window.confirm("You have edited the secret. Are you sure you want to reset the change?") - ) { - onToggle(false); - reset(); - } else return; - } - onToggle(state); - }} - isOpen={isOpen} - > - -
-
- - - - - {(isAllowed) => ( - ( - - - - )} - /> - )} - -
+ <> + { + setCreateReminderFormOpen.toggle(); + + if (data) { + setValue("reminderRepeatDays", data.days, { shouldDirty: true }); + setValue("reminderNote", data.note, { shouldDirty: true }); + } + }} + /> + { + if (isOpen && isDirty) { + if ( + // eslint-disable-next-line no-alert + window.confirm( + "You have edited the secret. Are you sure you want to reset the change?" + ) + ) { + onToggle(false); + reset(); + } else return; + } + onToggle(state); + }} + isOpen={isOpen} + > + + +
+ + + {(isAllowed) => ( - - Override with a personal value - + ( + + + + )} + /> )} -
- {isOverridden && ( - ( - - - - )} - /> - )} - -
- {fields.map(({ tagColor, id: formId, name, id }) => ( - { - if (cannotEditSecret) { - createNotification({ type: "error", text: "Access denied" }); - return; - } - const tag = tags?.find(({ id: tagId }) => id === tagId); - if (tag) handleTagSelect(tag); - }} - > -
-
{name}
- - ))} - - - {(isAllowed) => ( - - - - - - )} - - - Apply tags to this secrets - {tags.map((tag) => { - const { id: tagId, name, color } = tag; - - const isSelected = selectedTagsGroupById?.[tagId]; - return ( - handleTagSelect(tag)} - key={tagId} - icon={isSelected && } - iconPos="right" - > -
-
- {name} -
- - ); - })} - - {(isAllowed) => ( - - - - )} - - - -
- - -