11import { Box , PasswordInput , Field , FieldGroup , FieldLabel , FieldRow , FieldError , FieldHint , Button , Divider } from '@rocket.chat/fuselage' ;
2- import { useToastMessageDispatch , useTranslation } from '@rocket.chat/ui-contexts' ;
2+ import { useToastMessageDispatch } from '@rocket.chat/ui-contexts' ;
33import DOMPurify from 'dompurify' ;
44import { Accounts } from 'meteor/accounts-base' ;
55import type { ComponentProps , ReactElement } from 'react' ;
66import { useId , useEffect } from 'react' ;
77import { Controller , useForm } from 'react-hook-form' ;
8+ import { Trans , useTranslation } from 'react-i18next' ;
89
910import { e2e } from '../../../lib/e2ee/rocketchat.e2e' ;
1011import { useResetE2EPasswordMutation } from '../../hooks/useResetE2EPasswordMutation' ;
1112
1213const EndToEnd = ( props : ComponentProps < typeof Box > ) : ReactElement => {
13- const t = useTranslation ( ) ;
14+ const { t } = useTranslation ( ) ;
1415 const dispatchToastMessage = useToastMessageDispatch ( ) ;
1516
1617 const publicKey = Accounts . storageLocation . getItem ( 'public_key' ) ;
@@ -29,11 +30,14 @@ const EndToEnd = (props: ComponentProps<typeof Box>): ReactElement => {
2930 password : '' ,
3031 passwordConfirm : '' ,
3132 } ,
32- mode : 'all' ,
3333 } ) ;
3434
3535 const { password } = watch ( ) ;
3636
37+ /**
38+ * TODO: We need to figure out a way to make this reactive,
39+ * so the form will allow change password as soon the user enter the current E2EE password
40+ */
3741 const keysExist = Boolean ( publicKey && privateKey ) ;
3842
3943 const hasTypedPassword = Boolean ( password ?. trim ( ) . length ) ;
@@ -66,65 +70,77 @@ const EndToEnd = (props: ComponentProps<typeof Box>): ReactElement => {
6670 id = { e2ePasswordExplanationId }
6771 dangerouslySetInnerHTML = { { __html : DOMPurify . sanitize ( t ( 'E2E_Encryption_Password_Explanation' ) ) } }
6872 />
69-
7073 < Box mbs = { 36 } w = 'full' >
7174 < Box is = 'h4' fontScale = 'h4' mbe = { 12 } >
72- { t ( 'E2E_Encryption_Password_Change ' ) }
75+ { t ( 'Change_E2EE_password ' ) }
7376 </ Box >
74-
7577 < FieldGroup w = 'full' >
7678 < Field >
77- < FieldLabel htmlFor = { passwordId } > { t ( 'New_encryption_password ' ) } </ FieldLabel >
79+ < FieldLabel htmlFor = { passwordId } > { t ( 'New_E2EE_password ' ) } </ FieldLabel >
7880 < FieldRow >
7981 < Controller
8082 control = { control }
8183 name = 'password'
82- rules = { { required : t ( 'Required_field' , { field : t ( 'New_encryption_password ' ) } ) } }
84+ rules = { { required : t ( 'Required_field' , { field : t ( 'New_E2EE_password ' ) } ) } }
8385 render = { ( { field } ) => (
8486 < PasswordInput
8587 { ...field }
8688 id = { passwordId }
8789 error = { errors . password ?. message }
88- placeholder = { t ( 'New_Password_Placeholder' ) }
8990 disabled = { ! keysExist }
9091 aria-describedby = { `${ e2ePasswordExplanationId } ${ passwordId } -hint ${ passwordId } -error` }
9192 aria-invalid = { errors . password ? 'true' : 'false' }
9293 />
9394 ) }
9495 />
9596 </ FieldRow >
96- { ! keysExist && < FieldHint id = { `${ passwordId } -hint` } > { t ( 'EncryptionKey_Change_Disabled' ) } </ FieldHint > }
97+ { ! keysExist && (
98+ < FieldHint id = { `${ passwordId } -hint` } >
99+ < Trans i18nKey = 'Enter_current_E2EE_password_to_set_new' >
100+ To set a new password, first
101+ < Box
102+ is = 'a'
103+ href = '#'
104+ onClick = { async ( e ) => {
105+ e . preventDefault ( ) ;
106+ await e2e . decodePrivateKeyFlow ( ) ;
107+ } }
108+ >
109+ enter your current E2EE password.
110+ </ Box >
111+ </ Trans >
112+ </ FieldHint >
113+ ) }
97114 { errors ?. password && (
98- < FieldError aria-live = 'assertive ' id = { `${ passwordId } -error` } >
115+ < FieldError role = 'alert ' id = { `${ passwordId } -error` } >
99116 { errors . password . message }
100117 </ FieldError >
101118 ) }
102119 </ Field >
103120 { hasTypedPassword && (
104121 < Field >
105- < FieldLabel htmlFor = { passwordConfirmId } > { t ( 'Confirm_new_encryption_password ' ) } </ FieldLabel >
122+ < FieldLabel htmlFor = { passwordConfirmId } > { t ( 'Confirm_new_E2EE_password ' ) } </ FieldLabel >
106123 < FieldRow >
107124 < Controller
108125 control = { control }
109126 name = 'passwordConfirm'
110127 rules = { {
111- required : t ( 'Required_field' , { field : t ( 'Confirm_new_encryption_password ' ) } ) ,
112- validate : ( value : string ) => ( password !== value ? 'Your passwords do no match' : true ) ,
128+ required : t ( 'Required_field' , { field : t ( 'Confirm_new_E2EE_password ' ) } ) ,
129+ validate : ( value : string ) => ( password !== value ? t ( 'Passwords_do_not_match' ) : true ) ,
113130 } }
114131 render = { ( { field } ) => (
115132 < PasswordInput
116133 { ...field }
117134 id = { passwordConfirmId }
118135 error = { errors . passwordConfirm ?. message }
119- placeholder = { t ( 'Confirm_New_Password_Placeholder' ) }
120136 aria-describedby = { `${ passwordConfirmId } -error` }
121- aria-invalid = { errors . password ? 'true' : 'false' }
137+ aria-invalid = { errors . passwordConfirm ? 'true' : 'false' }
122138 />
123139 ) }
124140 />
125141 </ FieldRow >
126142 { errors . passwordConfirm && (
127- < FieldError aria-live = 'assertive ' id = { `${ passwordConfirmId } -error` } >
143+ < FieldError role = 'alert ' id = { `${ passwordConfirmId } -error` } >
128144 { errors . passwordConfirm . message }
129145 </ FieldError >
130146 ) }
@@ -141,16 +157,16 @@ const EndToEnd = (props: ComponentProps<typeof Box>): ReactElement => {
141157 { t ( 'Save_changes' ) }
142158 </ Button >
143159 </ Box >
144-
145160 < Divider mb = { 36 } width = 'full' />
146-
147161 < Box >
148162 < Box is = 'h4' fontScale = 'h4' mbe = { 12 } >
149- { t ( 'Reset_E2E_Key' ) }
163+ { t ( 'Reset_E2EE_password' ) }
164+ </ Box >
165+ < Box is = 'p' fontScale = 'p1' mbe = { 12 } >
166+ { t ( 'Reset_E2EE_password_description' ) }
150167 </ Box >
151- < Box is = 'p' fontScale = 'p1' mbe = { 12 } dangerouslySetInnerHTML = { { __html : DOMPurify . sanitize ( t ( 'E2E_Reset_Key_Explanation' ) ) } } />
152168 < Button onClick = { ( ) => resetE2EPassword . mutate ( ) } data-qa-type = 'e2e-encryption-reset-key-button' >
153- { t ( 'Reset_E2E_Key ' ) }
169+ { t ( 'Reset_E2EE_password ' ) }
154170 </ Button >
155171 </ Box >
156172 </ Box >
0 commit comments