-
-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): display user password information on user details page (…
- Loading branch information
Showing
24 changed files
with
198 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@logto/console": minor | ||
"@logto/phrases": minor | ||
--- | ||
|
||
display user password information on user details page |
34 changes: 34 additions & 0 deletions
34
packages/console/src/pages/UserDetails/UserSettings/UserPassword/index.module.scss
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,34 @@ | ||
@use '@/scss/underscore' as _; | ||
|
||
.password { | ||
display: flex; | ||
align-items: center; | ||
user-select: none; | ||
border: 1px solid var(--color-divider); | ||
border-radius: 12px; | ||
padding: _.unit(3) _.unit(6); | ||
justify-content: space-between; | ||
font: var(--font-body-2); | ||
|
||
.label { | ||
flex: 5; | ||
display: flex; | ||
align-items: center; | ||
|
||
.icon { | ||
margin-right: _.unit(3); | ||
color: var(--color-text-secondary); | ||
} | ||
} | ||
|
||
.text { | ||
flex: 8; | ||
color: var(--color-text-secondary); | ||
} | ||
|
||
.actionButton { | ||
flex: 3; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
packages/console/src/pages/UserDetails/UserSettings/UserPassword/index.tsx
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,102 @@ | ||
import { type UserProfileResponse } from '@logto/schemas'; | ||
import { useRef, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import ReactModal from 'react-modal'; | ||
|
||
import Key from '@/assets/icons/key.svg?react'; | ||
import UserAccountInformation from '@/components/UserAccountInformation'; | ||
import Button from '@/ds-components/Button'; | ||
import DynamicT from '@/ds-components/DynamicT'; | ||
import modalStyles from '@/scss/modal.module.scss'; | ||
|
||
import ResetPasswordForm from '../../components/ResetPasswordForm'; | ||
|
||
import styles from './index.module.scss'; | ||
|
||
type Props = { | ||
readonly user: UserProfileResponse; | ||
readonly onResetPassword: () => void; | ||
}; | ||
|
||
function UserPassword({ user, onResetPassword }: Props) { | ||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); | ||
const { hasPassword = false } = user; | ||
|
||
const [isResetPasswordFormOpen, setIsResetPasswordFormOpen] = useState(false); | ||
const [newPassword, setNewPassword] = useState<string>(); | ||
|
||
// Use a ref to store the initial state of hasPassword to determine which title to show when the password has been reset | ||
const initialHasPassword = useRef(hasPassword); | ||
|
||
return ( | ||
<> | ||
<div className={styles.password}> | ||
<div className={styles.label}> | ||
<Key className={styles.icon} /> | ||
<span> | ||
<DynamicT forKey="user_details.field_password" /> | ||
</span> | ||
</div> | ||
<div className={styles.text}> | ||
<DynamicT | ||
forKey={`user_details.${hasPassword ? 'password_already_set' : 'no_password_set'}`} | ||
/> | ||
</div> | ||
<div className={styles.actionButton}> | ||
<Button | ||
title={`general.${hasPassword ? 'reset' : 'generate'}`} | ||
type="text" | ||
size="small" | ||
onClick={() => { | ||
setIsResetPasswordFormOpen(true); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
<ReactModal | ||
shouldCloseOnEsc | ||
isOpen={isResetPasswordFormOpen} | ||
className={modalStyles.content} | ||
overlayClassName={modalStyles.overlay} | ||
onRequestClose={() => { | ||
setIsResetPasswordFormOpen(false); | ||
}} | ||
> | ||
<ResetPasswordForm | ||
userId={user.id} | ||
hasPassword={hasPassword} | ||
onClose={(password) => { | ||
setIsResetPasswordFormOpen(false); | ||
|
||
if (password) { | ||
setNewPassword(password); | ||
onResetPassword(); | ||
} | ||
}} | ||
/> | ||
</ReactModal> | ||
{newPassword && ( | ||
<UserAccountInformation | ||
title={`user_details.reset_password.${ | ||
initialHasPassword.current ? 'reset_complete' : 'generate_complete' | ||
}`} | ||
user={user} | ||
password={newPassword} | ||
passwordLabel={t( | ||
`user_details.reset_password.${ | ||
initialHasPassword.current ? 'new_password' : 'password' | ||
}` | ||
)} | ||
onClose={() => { | ||
setNewPassword(undefined); | ||
// Update the initial state to true once the user has acknowledged the new password | ||
// eslint-disable-next-line @silverhand/fp/no-mutation | ||
initialHasPassword.current = true; | ||
}} | ||
/> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default UserPassword; |
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
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
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
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
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
Oops, something went wrong.