From 14df155f2a8f174a719122e3d4d773cbb7883d2e Mon Sep 17 00:00:00 2001 From: Parker Stafford <52351508+Parker-Stafford@users.noreply.github.com> Date: Fri, 13 Sep 2024 09:25:07 -0700 Subject: [PATCH] feat(auth): add delete user ui (#4609) --- .../components/auth/DeleteAPIKeyButton.tsx | 2 +- app/src/pages/settings/DeleteUserButton.tsx | 112 ++++++++++++++ app/src/pages/settings/UsersTable.tsx | 48 +++++- .../DeleteUserButtonMutation.graphql.ts | 79 ++++++++++ .../__generated__/UsersCardQuery.graphql.ts | 13 +- .../__generated__/UsersTableQuery.graphql.ts | 137 ++++++++++++++++++ .../__generated__/UsersTable_users.graphql.ts | 24 ++- 7 files changed, 402 insertions(+), 13 deletions(-) create mode 100644 app/src/pages/settings/DeleteUserButton.tsx create mode 100644 app/src/pages/settings/__generated__/DeleteUserButtonMutation.graphql.ts create mode 100644 app/src/pages/settings/__generated__/UsersTableQuery.graphql.ts diff --git a/app/src/components/auth/DeleteAPIKeyButton.tsx b/app/src/components/auth/DeleteAPIKeyButton.tsx index e38e376278..346b25c719 100644 --- a/app/src/components/auth/DeleteAPIKeyButton.tsx +++ b/app/src/components/auth/DeleteAPIKeyButton.tsx @@ -20,7 +20,7 @@ export function DeleteAPIKeyButton({ const onDelete = () => { setDialog( - + {`Are you sure you want to delete this key? This cannot be undone and will disable all uses of this key.`} diff --git a/app/src/pages/settings/DeleteUserButton.tsx b/app/src/pages/settings/DeleteUserButton.tsx new file mode 100644 index 0000000000..876b632c1d --- /dev/null +++ b/app/src/pages/settings/DeleteUserButton.tsx @@ -0,0 +1,112 @@ +import React, { ReactNode, useCallback, useState } from "react"; +import { graphql, useMutation } from "react-relay"; + +import { + Button, + Dialog, + DialogContainer, + Flex, + Icon, + Icons, + Text, + View, +} from "@arizeai/components"; + +import { useNotifyError, useNotifySuccess } from "@phoenix/contexts"; + +import { DeleteUserButtonMutation } from "./__generated__/DeleteUserButtonMutation.graphql"; + +export function DeleteUserButton({ + userId, + onDeleted, +}: { + userId: string; + onDeleted: () => void; +}) { + const [dialog, setDialog] = useState(null); + + const [commit, isCommitting] = useMutation(graphql` + mutation DeleteUserButtonMutation($input: DeleteUsersInput!) { + deleteUsers(input: $input) + } + `); + + const notifySuccess = useNotifySuccess(); + const notifyError = useNotifyError(); + + const handleDelete = useCallback(() => { + commit({ + variables: { + input: { + userIds: [userId], + }, + }, + onCompleted: () => { + notifySuccess({ + title: "User deleted", + message: "User has been deleted.", + }); + onDeleted(); + }, + onError: (error) => { + notifyError({ + title: "Failed to delete user", + message: error.message, + }); + }, + }); + }, [commit, notifyError, notifySuccess, onDeleted, userId]); + + const onDelete = () => { + setDialog( + + + + {`Are you sure you want to delete this user? This action cannot be undone. The user will be permanently blocked, and cannot be reactivated with the same email or username.`} + + + + + + + + + ); + }; + return ( + <> +