Skip to content

Commit

Permalink
Merge branch 'dev' into create-realms
Browse files Browse the repository at this point in the history
  • Loading branch information
calebeby authored Jan 6, 2024
2 parents 6dfb1ab + d398e18 commit 3141b25
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/routes/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<EditableText
Expand All @@ -181,7 +198,11 @@ const SetPasswordButton = ({ user }: { user: UserInfo }) => {
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) => (
<Button flat onClick={startEditing}>
Expand Down Expand Up @@ -306,9 +327,11 @@ const UserProfileCard = ({
<EditableText
editable={editable}
label="Name"
save={(newText) => {
save={async (newText) => {
const [firstName, lastName] = newText.split(/\s+/)
return updateUser(user.id, { firstName, lastName })
if (await alertOnSaveAdmin(isCurrentUser, user)) {
return updateUser(user.id, { firstName, lastName })
}
}}
value={`${user.firstName} ${user.lastName}`}
>
Expand All @@ -321,7 +344,11 @@ const UserProfileCard = ({
<EditableText
editable={editable}
label="Username"
save={(username) => updateUser(user.id, { username })}
save={async (username) => {
if (await alertOnSaveAdmin(isCurrentUser, user)) {
updateUser(user.id, { username })
}
}}
value={user.username}
>
{(value, editIcon) => (
Expand Down Expand Up @@ -381,7 +408,9 @@ const UserProfileCard = ({
/>
</dl>
{editable && !isCurrentUser && <DeleteUserButton user={user} />}
{editable && <SetPasswordButton user={user} />}
{editable && (
<SetPasswordButton user={user} isCurrentUser={isCurrentUser} />
)}
</ErrorBoundary>
</Card>
)
Expand Down

0 comments on commit 3141b25

Please sign in to comment.