|
1 | 1 | 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'; |
3 | 3 | import DOMPurify from 'dompurify'; |
4 | 4 | import { Accounts } from 'meteor/accounts-base'; |
5 | 5 | import type { ComponentProps, ReactElement } from 'react'; |
6 | | -import { useId, useCallback, useEffect } from 'react'; |
| 6 | +import { useId, useEffect } from 'react'; |
7 | 7 | import { Controller, useForm } from 'react-hook-form'; |
8 | 8 |
|
9 | 9 | import { e2e } from '../../../lib/e2ee/rocketchat.e2e'; |
| 10 | +import { useResetE2EPasswordMutation } from '../../hooks/useResetE2EPasswordMutation'; |
10 | 11 |
|
11 | 12 | const EndToEnd = (props: ComponentProps<typeof Box>): ReactElement => { |
12 | 13 | const t = useTranslation(); |
13 | 14 | const dispatchToastMessage = useToastMessageDispatch(); |
14 | | - const logout = useLogout(); |
15 | 15 |
|
16 | 16 | const publicKey = Accounts.storageLocation.getItem('public_key'); |
17 | 17 | const privateKey = Accounts.storageLocation.getItem('private_key'); |
18 | 18 |
|
19 | | - const resetE2eKey = useMethod('e2e.resetOwnE2EKey'); |
| 19 | + const resetE2EPassword = useResetE2EPasswordMutation(); |
20 | 20 |
|
21 | 21 | const { |
22 | 22 | handleSubmit, |
@@ -48,18 +48,6 @@ const EndToEnd = (props: ComponentProps<typeof Box>): ReactElement => { |
48 | 48 | } |
49 | 49 | }; |
50 | 50 |
|
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 | | - |
63 | 51 | useEffect(() => { |
64 | 52 | if (password?.trim() === '') { |
65 | 53 | resetField('passwordConfirm'); |
@@ -161,7 +149,7 @@ const EndToEnd = (props: ComponentProps<typeof Box>): ReactElement => { |
161 | 149 | {t('Reset_E2E_Key')} |
162 | 150 | </Box> |
163 | 151 | <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'> |
165 | 153 | {t('Reset_E2E_Key')} |
166 | 154 | </Button> |
167 | 155 | </Box> |
|
0 commit comments