From d398e18861b3237dce192a971b46886c76ab70b4 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 13 Dec 2023 16:13:21 -0800 Subject: [PATCH] add dialogs when admins edit other users (#1530) * created a dialog on editing EditableTexts by admins in user * refresh the user page after every change * switched to standard system of getting DB info for users * Revert "switched to standard system of getting DB info for users" This reverts commit 1c5a09e6992a03d6b5ee4912a478d46940905006. * changed all self props to isCurrentUser * separated alertOnSaveAdmin function, small changes * changed selfEdit to isCurrentUser and removed all refetch changes --- src/routes/user.tsx | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/routes/user.tsx b/src/routes/user.tsx index 86e05bbf7..8845340f5 100644 --- a/src/routes/user.tsx +++ b/src/routes/user.tsx @@ -170,7 +170,24 @@ const DeleteUserButton = ({ user }: { user: UserInfo }) => { ) } -const SetPasswordButton = ({ user }: { user: UserInfo }) => { +const alertOnSaveAdmin = async (isCurrentUser: boolean, user: UserInfo) => { + if (isCurrentUser) return true + const confirmation = await createDialog({ + title: 'Confirm Edit', + description: `This is not your own profile. Are you sure you want to edit ${user.firstName} ${user.lastName}'s profile?`, + confirm: 'Confirm', + dismiss: 'Cancel', + }) + return confirmation +} + +const SetPasswordButton = ({ + user, + isCurrentUser, +}: { + user: UserInfo + isCurrentUser: boolean +}) => { const emitError = useErrorEmitter() return ( { minLength={minPasswordLength} maxLength={maxPasswordLength} value={''} - save={(password) => modifyUser(user.id, { password }).catch(emitError)} + save={async (password) => { + if (await alertOnSaveAdmin(isCurrentUser, user)) { + modifyUser(user.id, { password }).catch(emitError) + } + }} > {(_password, _icon, startEditing) => (