From 9e983e24c891c144f370e8f5476de6404ada3a16 Mon Sep 17 00:00:00 2001 From: Vardhaman Bhandari Date: Mon, 21 Oct 2024 16:38:55 +0530 Subject: [PATCH 1/4] fix: reset form fields in delete dialog on reopen --- .../[permissionId]/delete-permission.tsx | 26 +++++++++++++---- .../roles/[roleId]/delete-role.tsx | 29 ++++++++++++++----- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx b/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx index a19d2efd0f..7d8adccaae 100644 --- a/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx +++ b/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx @@ -44,7 +44,9 @@ export const DeletePermission: React.FC = ({ trigger, permission }) => { const [open, setOpen] = useState(false); const formSchema = z.object({ - name: z.string().refine((v) => v === permission.name, "Please confirm the role's name"), + name: z + .string() + .refine((v) => v === permission.name, "Please confirm the role's name"), }); const form = useForm>({ @@ -68,8 +70,13 @@ export const DeletePermission: React.FC = ({ trigger, permission }) => { deletePermission.mutate({ permissionId: permission.id }); } + function handleDialogOpenChange(newState: boolean) { + setOpen(newState); + form.reset(); + } + return ( - setOpen(o)}> + {trigger} @@ -79,10 +86,15 @@ export const DeletePermission: React.FC = ({ trigger, permission }) => {
- + Warning - This action is not reversible. Please be certain. + + This action is not reversible. Please be certain. + = ({ trigger, permission }) => { {" "} Enter the permission's name{" "} - {permission.name} to - continue: + + {permission.name} + {" "} + to continue: diff --git a/apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx b/apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx index 5fc71addd7..db159f8ba5 100644 --- a/apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx +++ b/apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx @@ -43,7 +43,9 @@ export const DeleteRole: React.FC = ({ trigger, role }) => { const [open, setOpen] = useState(false); const formSchema = z.object({ - name: z.string().refine((v) => v === role.name, "Please confirm the role's name"), + name: z + .string() + .refine((v) => v === role.name, "Please confirm the role's name"), }); const form = useForm>({ @@ -69,22 +71,32 @@ export const DeleteRole: React.FC = ({ trigger, role }) => { deleteRole.mutate({ roleId: role.id }); } + function handleDialogOpenChange(newState: boolean) { + setOpen(newState); + form.reset(); + } + return ( - setOpen(o)}> + {trigger} Delete Role - This role will be deleted, keys with this role will be disconnected from all permissions - granted by this role. + This role will be deleted, keys with this role will be disconnected + from all permissions granted by this role. - + Warning - This action is not reversible. Please be certain. + + This action is not reversible. Please be certain. + = ({ trigger, role }) => { {" "} Enter the role's key{" "} - {role.name} to continue: + + {role.name} + {" "} + to continue: From ecca65668081820b38eef5b1b0ab8b8d1be53114 Mon Sep 17 00:00:00 2001 From: Vardhaman Bhandari Date: Thu, 24 Oct 2024 14:57:11 +0530 Subject: [PATCH 2/4] fix: remaining dialog form reset --- .../permissions/create-new-permission.tsx | 27 +++++++--- .../authorization/roles/create-new-role.tsx | 36 +++++++++---- .../settings/delete-namespace.tsx | 51 ++++++++++++++----- .../[gatewayId]/settings/delete-gateway.tsx | 38 +++++++++++--- 4 files changed, 113 insertions(+), 39 deletions(-) diff --git a/apps/dashboard/app/(app)/authorization/permissions/create-new-permission.tsx b/apps/dashboard/app/(app)/authorization/permissions/create-new-permission.tsx index 089349cd67..8a4fd562a8 100644 --- a/apps/dashboard/app/(app)/authorization/permissions/create-new-permission.tsx +++ b/apps/dashboard/app/(app)/authorization/permissions/create-new-permission.tsx @@ -75,18 +75,27 @@ export const CreateNewPermission: React.FC = ({ trigger }) => { async function onSubmit(values: z.infer) { createPermission.mutate(values); } + function handleDialogOpenChange(newState: boolean) { + setOpen(newState); + form.reset(); + } return ( - + {trigger} Create a new permission - Permissions allow your key to do certain actions. + + Permissions allow your key to do certain actions. + - + = ({ trigger }) => { - A unique key to identify your permission. We suggest using . (dot) - separated names, to structure your hierarchy. For example we use{" "} - api.create_key or api.update_api in our own - permissions. + A unique key to identify your permission. We suggest using{" "} + . (dot) separated names, to structure your + hierarchy. For example we use api.create_key or{" "} + api.update_api in our own permissions. @@ -119,7 +128,9 @@ export const CreateNewPermission: React.FC = ({ trigger }) => {