1 import { useState } from 'react';
3 import { c } from 'ttag';
5 import { changeSSOUserBackupPassword } from '@proton/account/sso/passwordActions';
6 import { Button } from '@proton/atoms';
7 import type { ModalProps } from '@proton/components';
17 } from '@proton/components';
18 import useFormErrors from '@proton/components/components/v2/useFormErrors';
19 import useLoading from '@proton/hooks/useLoading';
20 import { useDispatch } from '@proton/redux-shared-store';
21 import { BRAND_NAME } from '@proton/shared/lib/constants';
23 confirmPasswordValidator,
24 passwordLengthValidator,
26 } from '@proton/shared/lib/helpers/formValidators';
27 import { AuthDeviceNonExistingError } from '@proton/shared/lib/keys/device';
29 import useNotifications from '../../hooks/useNotifications';
31 interface Props extends ModalProps {}
33 const ChangeBackupPasswordModal = ({ ...rest }: Props) => {
34 const dispatch = useDispatch();
35 const { validator, onFormSubmit } = useFormErrors();
36 const [loading, withLoading] = useLoading();
37 const [newBackupPassword, setNewPassword] = useState('');
38 const [confirmBackupPassword, setConfirmBackupPassword] = useState('');
39 const handleError = useErrorHandler();
40 const { createNotification } = useNotifications();
45 onClose={rest.onClose}
48 if (!onFormSubmit()) {
52 dispatch(changeSSOUserBackupPassword({ newBackupPassword }))
54 createNotification({ text: c('Success').t`Backup password updated` });
58 if (e instanceof AuthDeviceNonExistingError) {
60 text: c('sso').t`Sign out and in again to change your backup password`,
70 <ModalTwoHeader title={c('sso').t`Change backup password`} />
72 <div className="mb-6">
74 .t`${BRAND_NAME}'s encryption technology means that nobody can access your password - not even us.`}
77 .t`Make sure you save it somewhere safe so that you can get back into your account if you lose access to your Identity Provider credentials.`}
81 label={c('sso').t`New backup password`}
83 requiredValidator(newBackupPassword),
84 passwordLengthValidator(newBackupPassword),
88 autoComplete="new-password"
89 value={newBackupPassword}
90 onValue={setNewPassword}
96 label={c('sso').t`Confirm backup password`}
98 requiredValidator(confirmBackupPassword),
99 passwordLengthValidator(confirmBackupPassword),
100 confirmPasswordValidator(newBackupPassword, confirmBackupPassword),
102 as={PasswordInputTwo}
103 autoComplete="new-password"
104 value={confirmBackupPassword}
105 onValue={setConfirmBackupPassword}
110 <Button onClick={rest.onClose}>{c('Action').t`Cancel`}</Button>
111 <Button loading={loading} type="submit" color="norm">
112 {c('Action').t`Save`}
119 export default ChangeBackupPasswordModal;