11import { Button , DialogActions , DialogContent } from '@material-ui/core'
22import TextField from '@material-ui/core/TextField'
3+ import { GenericContent } from '@sensenet/default-content-types'
34import { useLogger , useRepository } from '@sensenet/hooks-react'
45import React , { useState } from 'react'
56import { useAuth } from '../../context/auth-provider'
@@ -9,13 +10,18 @@ import { DialogTitle, useDialog } from '.'
910
1011type PasswordFieldKeys = 'newPassword' | 'confirmPassword'
1112
12- export function ChangePasswordDialog ( ) {
13+ export type ChangePasswordDialogProps = {
14+ content ?: GenericContent
15+ }
16+
17+ export function ChangePasswordDialog ( { content } : ChangePasswordDialogProps ) {
1318 const { closeLastDialog } = useDialog ( )
1419 const localization = useLocalization ( ) . changePassword
1520 const logger = useLogger ( 'change-password' )
1621 const globalClasses = useGlobalStyles ( )
1722 const repo = useRepository ( )
1823 const { user } = useAuth ( )
24+ const targetContent = content || user
1925 const [ passwordFields , setPasswordFields ] = useState < {
2026 [ K in PasswordFieldKeys ] ?: string
2127 } > ( {
@@ -32,7 +38,7 @@ export function ChangePasswordDialog() {
3238
3339 try {
3440 await repo . executeAction ( {
35- idOrPath : user ! . Path ,
41+ idOrPath : targetContent ! . Path ,
3642 name : 'ChangePassword' ,
3743 method : 'POST' ,
3844 body : {
@@ -65,7 +71,11 @@ export function ChangePasswordDialog() {
6571 return (
6672 < >
6773 < DialogTitle >
68- < div className = { globalClasses . centered } > { localization . changeYourPassword } </ div >
74+ < div className = { globalClasses . centered } >
75+ { content
76+ ? localization . changePasswordFor . replace ( '{0}' , content . DisplayName || content . Name )
77+ : localization . changeYourPassword }
78+ </ div >
6979 </ DialogTitle >
7080 < >
7181 < DialogContent data-test = "change-password-fields" >
0 commit comments