-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): add delete user ui (#4609)
- Loading branch information
1 parent
bbcc24f
commit 14df155
Showing
7 changed files
with
402 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ReactNode>(null); | ||
|
||
const [commit, isCommitting] = useMutation<DeleteUserButtonMutation>(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( | ||
<Dialog title="Delete User"> | ||
<View padding="size-200"> | ||
<Text color="danger"> | ||
{`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.`} | ||
</Text> | ||
</View> | ||
<View | ||
paddingEnd="size-200" | ||
paddingTop="size-100" | ||
paddingBottom="size-100" | ||
borderTopColor="light" | ||
borderTopWidth="thin" | ||
> | ||
<Flex direction="row" justifyContent="end"> | ||
<Button | ||
variant="danger" | ||
onClick={() => { | ||
handleDelete(); | ||
setDialog(null); | ||
}} | ||
> | ||
Delete user | ||
</Button> | ||
</Flex> | ||
</View> | ||
</Dialog> | ||
); | ||
}; | ||
return ( | ||
<> | ||
<Button | ||
variant="danger" | ||
size="compact" | ||
icon={<Icon svg={<Icons.TrashOutline />} />} | ||
aria-label="Delete User" | ||
onClick={() => { | ||
onDelete(); | ||
}} | ||
disabled={isCommitting} | ||
/> | ||
<DialogContainer | ||
isDismissable | ||
onDismiss={() => { | ||
setDialog(null); | ||
}} | ||
> | ||
{dialog} | ||
</DialogContainer> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
app/src/pages/settings/__generated__/DeleteUserButtonMutation.graphql.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 10 additions & 3 deletions
13
app/src/pages/settings/__generated__/UsersCardQuery.graphql.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.