Skip to content

Commit e9f037a

Browse files
committed
feat: create link to open modal
1 parent 34f05ee commit e9f037a

File tree

6 files changed

+72
-22
lines changed

6 files changed

+72
-22
lines changed

apps/meteor/app/e2e/server/methods/resetOwnE2EKey.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ Meteor.methods<ServerMethods>({
2222
}
2323

2424
if (!(await resetUserE2EEncriptionKey(userId, false))) {
25-
return false;
25+
throw new Meteor.Error('failed-reset-e2e-password', 'Failed to reset E2E password', {
26+
method: 'resetOwnE2EKey',
27+
});
2628
}
2729
return true;
2830
}),

apps/meteor/client/views/account/security/AccountSecurityPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ const AccountSecurityPage = (): ReactElement => {
4949
{allowPasswordChange && (
5050
<FormProvider {...methods}>
5151
<Accordion>
52-
<AccordionItem title={t('Password')} expanded={!require2faSetup}>
52+
<AccordionItem title={t('Password')} defaultExpanded={!require2faSetup}>
5353
<ChangePassword id={passwordFormId} />
5454
</AccordionItem>
5555
</Accordion>
5656
</FormProvider>
5757
)}
5858
<Accordion>
5959
{(twoFactorTOTP || showEmailTwoFactor) && twoFactorEnabled && (
60-
<AccordionItem expanded={require2faSetup} title={t('Two Factor Authentication')}>
60+
<AccordionItem defaultExpanded={require2faSetup} title={t('Two Factor Authentication')}>
6161
{require2faSetup && (
6262
<Callout type='warning' title={t('Enable_two-factor_authentication')} mbe='24px'>
6363
{t('Enable_two-factor_authentication_callout_description')}

apps/meteor/client/views/account/security/EndToEnd.tsx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { Box, PasswordInput, Field, FieldGroup, FieldLabel, FieldRow, FieldError, FieldHint, Button, Divider } from '@rocket.chat/fuselage';
2-
import { useToastMessageDispatch, useMethod, useTranslation, useLogout } from '@rocket.chat/ui-contexts';
2+
import { useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts';
33
import DOMPurify from 'dompurify';
44
import { Accounts } from 'meteor/accounts-base';
55
import type { ComponentProps, ReactElement } from 'react';
6-
import { useId, useCallback, useEffect } from 'react';
6+
import { useId, useEffect } from 'react';
77
import { Controller, useForm } from 'react-hook-form';
88

99
import { e2e } from '../../../lib/e2ee/rocketchat.e2e';
10+
import { useResetE2EPasswordMutation } from '../../hooks/useResetE2EPasswordMutation';
1011

1112
const EndToEnd = (props: ComponentProps<typeof Box>): ReactElement => {
1213
const t = useTranslation();
1314
const dispatchToastMessage = useToastMessageDispatch();
14-
const logout = useLogout();
1515

1616
const publicKey = Accounts.storageLocation.getItem('public_key');
1717
const privateKey = Accounts.storageLocation.getItem('private_key');
1818

19-
const resetE2eKey = useMethod('e2e.resetOwnE2EKey');
19+
const resetE2EPassword = useResetE2EPasswordMutation();
2020

2121
const {
2222
handleSubmit,
@@ -48,18 +48,6 @@ const EndToEnd = (props: ComponentProps<typeof Box>): ReactElement => {
4848
}
4949
};
5050

51-
const handleResetE2eKey = useCallback(async () => {
52-
try {
53-
const result = await resetE2eKey();
54-
if (result) {
55-
dispatchToastMessage({ type: 'success', message: t('User_e2e_key_was_reset') });
56-
logout();
57-
}
58-
} catch (error) {
59-
dispatchToastMessage({ type: 'error', message: error });
60-
}
61-
}, [dispatchToastMessage, resetE2eKey, logout, t]);
62-
6351
useEffect(() => {
6452
if (password?.trim() === '') {
6553
resetField('passwordConfirm');
@@ -161,7 +149,7 @@ const EndToEnd = (props: ComponentProps<typeof Box>): ReactElement => {
161149
{t('Reset_E2E_Key')}
162150
</Box>
163151
<Box is='p' fontScale='p1' mbe={12} dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(t('E2E_Reset_Key_Explanation')) }} />
164-
<Button onClick={handleResetE2eKey} data-qa-type='e2e-encryption-reset-key-button'>
152+
<Button onClick={() => resetE2EPassword.mutate()} data-qa-type='e2e-encryption-reset-key-button'>
165153
{t('Reset_E2E_Key')}
166154
</Button>
167155
</Box>

apps/meteor/client/views/e2e/EnterE2EPasswordModal/EnterE2EPasswordModal.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { Box, PasswordInput, Field, FieldGroup, FieldRow, FieldError } from '@rocket.chat/fuselage';
1+
import { Box, PasswordInput, Field, FieldGroup, FieldRow, FieldError, FieldLink } from '@rocket.chat/fuselage';
22
import { GenericModal } from '@rocket.chat/ui-client';
33
import DOMPurify from 'dompurify';
4-
import { useEffect, useId } from 'react';
4+
import { useEffect, useId, useState } from 'react';
55
import { Controller, useForm } from 'react-hook-form';
66
import { useTranslation } from 'react-i18next';
77

8+
import { useResetE2EPasswordMutation } from '../../hooks/useResetE2EPasswordMutation';
9+
810
type EnterE2EPasswordModalProps = {
911
onConfirm: (password: string) => void;
1012
onClose: () => void;
@@ -13,6 +15,9 @@ type EnterE2EPasswordModalProps = {
1315

1416
const EnterE2EPasswordModal = ({ onConfirm, onClose, onCancel }: EnterE2EPasswordModalProps) => {
1517
const { t } = useTranslation();
18+
const [confirmResetPassword, setConfirmResetPassword] = useState(false);
19+
const resetE2EPassword = useResetE2EPasswordMutation({ options: { onSettled: () => onClose() } });
20+
1621
const {
1722
handleSubmit,
1823
control,
@@ -30,6 +35,22 @@ const EnterE2EPasswordModal = ({ onConfirm, onClose, onCancel }: EnterE2EPasswor
3035
setFocus('password');
3136
}, [setFocus]);
3237

38+
if (confirmResetPassword) {
39+
return (
40+
<GenericModal
41+
variant='warning'
42+
title={t('Reset_E2EE_password')}
43+
icon='warning'
44+
confirmText={t('Reset_E2EE_password')}
45+
onClose={onClose}
46+
onCancel={onClose}
47+
onConfirm={() => resetE2EPassword.mutate()}
48+
>
49+
<Box is='p'>{t('Reset_E2EE_password_description')}</Box>
50+
</GenericModal>
51+
);
52+
}
53+
3354
return (
3455
<GenericModal
3556
wrapperFunction={(props) => <Box is='form' onSubmit={handleSubmit(({ password }) => onConfirm(password))} {...props} />}
@@ -66,6 +87,18 @@ const EnterE2EPasswordModal = ({ onConfirm, onClose, onCancel }: EnterE2EPasswor
6687
{errors.password.message}
6788
</FieldError>
6889
)}
90+
<FieldRow alignSelf='end'>
91+
<FieldLink
92+
href='#'
93+
target={undefined}
94+
onClick={(e) => {
95+
e.preventDefault();
96+
setConfirmResetPassword(true);
97+
}}
98+
>
99+
{t('Forgot_E2EE_Password')}
100+
</FieldLink>
101+
</FieldRow>
69102
</Field>
70103
</FieldGroup>
71104
</GenericModal>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { useLogout, useMethod, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
2+
import type { MutationOptions } from '@tanstack/react-query';
3+
import { useMutation } from '@tanstack/react-query';
4+
import { useTranslation } from 'react-i18next';
5+
6+
export const useResetE2EPasswordMutation = ({ options }: { options?: MutationOptions } = {}) => {
7+
const { t } = useTranslation();
8+
9+
const logout = useLogout();
10+
const resetE2eKey = useMethod('e2e.resetOwnE2EKey');
11+
const dispatchToastMessage = useToastMessageDispatch();
12+
13+
return useMutation({
14+
mutationFn: async () => resetE2eKey(),
15+
onSuccess: () => {
16+
dispatchToastMessage({ type: 'success', message: t('User_e2e_key_was_reset') });
17+
logout();
18+
},
19+
onError: (error) => {
20+
dispatchToastMessage({ type: 'error', message: error });
21+
},
22+
...options,
23+
});
24+
};

packages/i18n/src/locales/en.i18n.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,7 @@
22922292
"Forgot_Password_Email_Subject": "[Site_Name] - Password Recovery",
22932293
"Forgot_password": "Forgot your password?",
22942294
"Forgot_password_section": "Forgot password",
2295+
"Forgot_E2EE_Password": "Forgot E2EE password?",
22952296
"Format": "Format",
22962297
"Forward": "Forward",
22972298
"Forward_chat": "Forward chat",
@@ -4329,6 +4330,8 @@
43294330
"Reset": "Reset",
43304331
"Reset_Connection": "Reset Connection",
43314332
"Reset_E2E_Key": "Reset E2EE key",
4333+
"Reset_E2EE_password": "Reset E2EE password",
4334+
"Reset_E2EE_password_description": "Resetting will log you out and generate a new E2EE password upon logging back in. You‘ll regain access to encrypted rooms with online members, but not to those without any members online.",
43324335
"Reset_TOTP": "Reset TOTP",
43334336
"Reset_password": "Reset password",
43344337
"Reset_priorities": "Reset priorities",

0 commit comments

Comments
 (0)