@@ -52,26 +52,36 @@ const usePasswordComplexity = (password: string): PasswordComplexity => {
5252 return result ;
5353} ;
5454
55+ type PasswordVariant = "register" | "change" ;
56+
5557export default function PasswordCreationDoubleInput ( {
5658 siteConfig,
5759 forceShowNewPasswordInvalid,
58- newPasswordFieldName,
59- newPasswordLabel,
60- newPasswordAgainFieldName,
61- newPasswordAgainLabel,
60+ variant= "change" ,
6261} : {
6362 siteConfig : FragmentType < typeof CONFIG_FRAGMENT > ;
6463 forceShowNewPasswordInvalid : boolean ;
65- newPasswordFieldName : string ;
66- newPasswordLabel : string ;
67- newPasswordAgainFieldName : string ;
68- newPasswordAgainLabel : string ;
64+ variant ?: PasswordVariant ;
6965} ) : React . ReactElement {
7066 const { t } = useTranslation ( ) ;
7167 const { minimumPasswordComplexity } = useFragment (
7268 CONFIG_FRAGMENT ,
7369 siteConfig ,
7470 ) ;
71+ const variantFields = {
72+ register : {
73+ passwordFieldName : "password" ,
74+ passwordLabel : t ( "common.password" ) ,
75+ passwordConfirmFieldName : "password_confirm" ,
76+ passwordConfirmLabel : t ( "common.password_confirm" ) ,
77+ } ,
78+ change : {
79+ passwordFieldName : "new_password" ,
80+ passwordLabel : t ( "common.password" ) ,
81+ passwordConfirmFieldName : "new_password_again" ,
82+ passwordConfirmLabel : t ( "common.password_confirm" ) ,
83+ }
84+ } [ variant ] ;
7585
7686 const newPasswordRef = useRef < HTMLInputElement > ( null ) ;
7787 const newPasswordAgainRef = useRef < HTMLInputElement > ( null ) ;
@@ -89,8 +99,8 @@ export default function PasswordCreationDoubleInput({
8999
90100 return (
91101 < >
92- < Form . Field name = { newPasswordFieldName } >
93- < Form . Label > { newPasswordLabel } </ Form . Label >
102+ < Form . Field name = { variantFields . passwordFieldName } >
103+ < Form . Label > { variantFields . passwordLabel } </ Form . Label >
94104
95105 < Form . PasswordControl
96106 required
@@ -134,13 +144,13 @@ export default function PasswordCreationDoubleInput({
134144 ) }
135145 </ Form . Field >
136146
137- < Form . Field name = { newPasswordAgainFieldName } >
147+ < Form . Field name = { variantFields . passwordConfirmFieldName } >
138148 { /*
139149 TODO This field has validation defects,
140150 some caused by Radix-UI upstream bugs.
141151 https://github.com/matrix-org/matrix-authentication-service/issues/2855
142152 */ }
143- < Form . Label > { newPasswordAgainLabel } </ Form . Label >
153+ < Form . Label > { variantFields . passwordConfirmLabel } </ Form . Label >
144154
145155 < Form . PasswordControl
146156 required
@@ -153,7 +163,7 @@ export default function PasswordCreationDoubleInput({
153163 </ Form . ErrorMessage >
154164
155165 < Form . ErrorMessage
156- match = { ( v , form ) => v !== form . get ( newPasswordFieldName ) }
166+ match = { ( v , form ) => v !== form . get ( variantFields . passwordFieldName ) }
157167 >
158168 { t ( "frontend.password_change.passwords_no_match" ) }
159169 </ Form . ErrorMessage >
0 commit comments