From 521330682df27623aee5553e8e019360116997f9 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 12 Jul 2025 16:18:33 -0600 Subject: [PATCH] feat(users): enhance user display and management options - Added functionality to display the current user with a "(You)" label in the user list. - Updated the dropdown menu to conditionally show actions based on user roles, preventing owners from being deleted or unlinked. - Improved user deletion and unlinking processes with success and error notifications. --- .../dashboard/settings/users/show-users.tsx | 197 +++++++++--------- 1 file changed, 97 insertions(+), 100 deletions(-) diff --git a/apps/dokploy/components/dashboard/settings/users/show-users.tsx b/apps/dokploy/components/dashboard/settings/users/show-users.tsx index 5de8741ba..62bcdd23a 100644 --- a/apps/dokploy/components/dashboard/settings/users/show-users.tsx +++ b/apps/dokploy/components/dashboard/settings/users/show-users.tsx @@ -34,6 +34,7 @@ import { AddUserPermissions } from "./add-permissions"; import { AddUserPermissionsV2 } from "./add-permissions-v2"; export const ShowUsers = () => { + const { data: user } = api.user.get.useQuery(); const { data: isCloud } = api.settings.isCloud.useQuery(); const { data, isLoading, refetch } = api.user.all.useQuery(); const { mutateAsync } = api.user.remove.useMutation(); @@ -85,10 +86,12 @@ export const ShowUsers = () => { {data?.map((member) => { + const isSameUser = member.user.id === user?.user.id; + return ( - - {member.user.email} + + {member.user.email} {isSameUser && "(You)"} { - - - - - - - Actions - + {member.role !== "owner" && !isSameUser && ( + + + + + + + Actions + - {member.role !== "owner" && ( <> { userId={member.user.id} /> - )} - {member.role !== "owner" && ( - <> - {!isCloud && ( - { + {!isCloud && ( + { + await mutateAsync({ + userId: member.user.id, + }) + .then(() => { + toast.success( + "User deleted successfully", + ); + refetch(); + }) + .catch(() => { + toast.error( + "Error deleting destination", + ); + }); + }} + > + e.preventDefault()} + > + Delete User + + + )} + + { + if (!isCloud) { + const orgCount = + await utils.user.checkUserOrganizations.fetch( + { + userId: member.user.id, + }, + ); + + console.log(orgCount); + + if (orgCount === 1) { await mutateAsync({ userId: member.user.id, }) @@ -158,86 +201,40 @@ export const ShowUsers = () => { }) .catch(() => { toast.error( - "Error deleting destination", + "Error deleting user", ); }); - }} - > - - e.preventDefault() - } - > - Delete User - - - )} - - { - if (!isCloud) { - const orgCount = - await utils.user.checkUserOrganizations.fetch( - { - userId: member.user.id, - }, - ); - - console.log(orgCount); - - if (orgCount === 1) { - await mutateAsync({ - userId: member.user.id, - }) - .then(() => { - toast.success( - "User deleted successfully", - ); - refetch(); - }) - .catch(() => { - toast.error( - "Error deleting user", - ); - }); - return; - } + return; } + } - const { error } = - await authClient.organization.removeMember( - { - memberIdOrEmail: member.id, - }, - ); + const { error } = + await authClient.organization.removeMember( + { + memberIdOrEmail: member.id, + }, + ); - if (!error) { - toast.success( - "User unlinked successfully", - ); - refetch(); - } else { - toast.error( - "Error unlinking user", - ); - } - }} + if (!error) { + toast.success( + "User unlinked successfully", + ); + refetch(); + } else { + toast.error("Error unlinking user"); + } + }} + > + e.preventDefault()} > - e.preventDefault()} - > - Unlink User - - - - )} - - + Unlink User + + + + + )} );