11/*
22Copyright 2017 Vector Creations Ltd
3+ Copyright 2022 The Matrix.org Foundation C.I.C.
34
45Licensed under the Apache License, Version 2.0 (the "License");
56you may not use this file except in compliance with the License.
@@ -15,14 +16,16 @@ limitations under the License.
1516*/
1617
1718import FileSaver from 'file-saver' ;
18- import React , { createRef } from 'react' ;
19+ import React from 'react' ;
1920import { MatrixClient } from 'matrix-js-sdk/src/client' ;
2021import { logger } from "matrix-js-sdk/src/logger" ;
2122
2223import { _t } from '../../../../languageHandler' ;
2324import * as MegolmExportEncryption from '../../../../utils/MegolmExportEncryption' ;
2425import { IDialogProps } from "../../../../components/views/dialogs/IDialogProps" ;
2526import BaseDialog from "../../../../components/views/dialogs/BaseDialog" ;
27+ import Field from "../../../../components/views/elements/Field" ;
28+ import { KeysStartingWith } from "../../../../@types/common" ;
2629
2730enum Phase {
2831 Edit = "edit" ,
@@ -36,19 +39,23 @@ interface IProps extends IDialogProps {
3639interface IState {
3740 phase : Phase ;
3841 errStr : string ;
42+ passphrase1 : string ;
43+ passphrase2 : string ;
3944}
4045
46+ type AnyPassphrase = KeysStartingWith < IState , "passphrase" > ;
47+
4148export default class ExportE2eKeysDialog extends React . Component < IProps , IState > {
4249 private unmounted = false ;
43- private passphrase1 = createRef < HTMLInputElement > ( ) ;
44- private passphrase2 = createRef < HTMLInputElement > ( ) ;
4550
4651 constructor ( props : IProps ) {
4752 super ( props ) ;
4853
4954 this . state = {
5055 phase : Phase . Edit ,
5156 errStr : null ,
57+ passphrase1 : "" ,
58+ passphrase2 : "" ,
5259 } ;
5360 }
5461
@@ -59,8 +66,8 @@ export default class ExportE2eKeysDialog extends React.Component<IProps, IState>
5966 private onPassphraseFormSubmit = ( ev : React . FormEvent ) : boolean => {
6067 ev . preventDefault ( ) ;
6168
62- const passphrase = this . passphrase1 . current . value ;
63- if ( passphrase !== this . passphrase2 . current . value ) {
69+ const passphrase = this . state . passphrase1 ;
70+ if ( passphrase !== this . state . passphrase2 ) {
6471 this . setState ( { errStr : _t ( 'Passphrases must match' ) } ) ;
6572 return false ;
6673 }
@@ -112,6 +119,12 @@ export default class ExportE2eKeysDialog extends React.Component<IProps, IState>
112119 return false ;
113120 } ;
114121
122+ private onPassphraseChange = ( ev : React . ChangeEvent < HTMLInputElement > , phrase : AnyPassphrase ) => {
123+ this . setState ( {
124+ [ phrase ] : ev . target . value ,
125+ } as Pick < IState , AnyPassphrase > ) ;
126+ } ;
127+
115128 public render ( ) : JSX . Element {
116129 const disableForm = ( this . state . phase === Phase . Exporting ) ;
117130
@@ -146,36 +159,25 @@ export default class ExportE2eKeysDialog extends React.Component<IProps, IState>
146159 </ div >
147160 < div className = 'mx_E2eKeysDialog_inputTable' >
148161 < div className = 'mx_E2eKeysDialog_inputRow' >
149- < div className = 'mx_E2eKeysDialog_inputLabel' >
150- < label htmlFor = 'passphrase1' >
151- { _t ( "Enter passphrase" ) }
152- </ label >
153- </ div >
154- < div className = 'mx_E2eKeysDialog_inputCell' >
155- < input
156- ref = { this . passphrase1 }
157- id = 'passphrase1'
158- autoFocus = { true }
159- size = { 64 }
160- type = 'password'
161- disabled = { disableForm }
162- />
163- </ div >
162+ < Field
163+ label = { _t ( "Enter passphrase" ) }
164+ value = { this . state . passphrase1 }
165+ onChange = { e => this . onPassphraseChange ( e , "passphrase1" ) }
166+ autoFocus = { true }
167+ size = { 64 }
168+ type = "password"
169+ disabled = { disableForm }
170+ />
164171 </ div >
165172 < div className = 'mx_E2eKeysDialog_inputRow' >
166- < div className = 'mx_E2eKeysDialog_inputLabel' >
167- < label htmlFor = 'passphrase2' >
168- { _t ( "Confirm passphrase" ) }
169- </ label >
170- </ div >
171- < div className = 'mx_E2eKeysDialog_inputCell' >
172- < input ref = { this . passphrase2 }
173- id = 'passphrase2'
174- size = { 64 }
175- type = 'password'
176- disabled = { disableForm }
177- />
178- </ div >
173+ < Field
174+ label = { _t ( "Confirm passphrase" ) }
175+ value = { this . state . passphrase2 }
176+ onChange = { e => this . onPassphraseChange ( e , "passphrase2" ) }
177+ size = { 64 }
178+ type = "password"
179+ disabled = { disableForm }
180+ />
179181 </ div >
180182 </ div >
181183 </ div >
0 commit comments