From 5db47e83e82993bb9d210cb264d05f59ea1db5f3 Mon Sep 17 00:00:00 2001 From: Vardan Hakobyan Date: Tue, 27 Sep 2022 18:13:54 +0400 Subject: [PATCH] feat: delete account (#1653) * feat: delete account * fix: copy adjustments Co-authored-by: Mo --- .../ApplicationView/ApplicationView.tsx | 2 + .../ConfirmDeleteAccountModal.tsx | 70 +++++++++++++++++++ .../Panes/Account/AccountPreferences.tsx | 2 + .../Panes/Account/DeleteAccount.tsx | 42 +++++++++++ .../web/src/javascripts/Constants/Strings.ts | 2 + .../AccountMenu/AccountMenuController.ts | 7 ++ 6 files changed, 125 insertions(+) create mode 100644 packages/web/src/javascripts/Components/ConfirmDeleteAccountModal/ConfirmDeleteAccountModal.tsx create mode 100644 packages/web/src/javascripts/Components/Preferences/Panes/Account/DeleteAccount.tsx diff --git a/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx b/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx index cb4ce2442..47ba0deb1 100644 --- a/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx +++ b/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx @@ -25,6 +25,7 @@ import { PanelResizedData } from '@/Types/PanelResizedData' import TagContextMenuWrapper from '@/Components/Tags/TagContextMenuWrapper' import FileDragNDropProvider from '../FileDragNDropProvider/FileDragNDropProvider' import ResponsivePaneProvider from '../ResponsivePane/ResponsivePaneProvider' +import ConfirmDeleteAccountContainer from '@/Components/ConfirmDeleteAccountModal/ConfirmDeleteAccountModal' type Props = { application: WebApplication @@ -240,6 +241,7 @@ const ApplicationView: FunctionComponent = ({ application, mainApplicatio + diff --git a/packages/web/src/javascripts/Components/ConfirmDeleteAccountModal/ConfirmDeleteAccountModal.tsx b/packages/web/src/javascripts/Components/ConfirmDeleteAccountModal/ConfirmDeleteAccountModal.tsx new file mode 100644 index 000000000..1e0928343 --- /dev/null +++ b/packages/web/src/javascripts/Components/ConfirmDeleteAccountModal/ConfirmDeleteAccountModal.tsx @@ -0,0 +1,70 @@ +import { observer } from 'mobx-react-lite' +import { ViewControllerManager } from '@Controllers/ViewControllerManager' +import { AlertDialog, AlertDialogDescription, AlertDialogLabel } from '@reach/alert-dialog' +import { useRef } from 'react' +import { STRING_DELETE_ACCOUNT_CONFIRMATION } from '@/Constants/Strings' +import Button from '@/Components/Button/Button' +import { WebApplication } from '@/Application/Application' + +type Props = { + viewControllerManager: ViewControllerManager + application: WebApplication +} + +const ConfirmDeleteAccountModal = ({ application, viewControllerManager }: Props) => { + function closeDialog() { + viewControllerManager.accountMenuController.setDeletingAccount(false) + } + + const cancelRef = useRef(null) + + return ( + +
+
+
+
+
+ Delete account? + +
+

{STRING_DELETE_ACCOUNT_CONFIRMATION}

+
+
+ +
+ + +
+
+
+
+
+
+
+ ) +} + +ConfirmDeleteAccountModal.displayName = 'ConfirmDeleteAccountModal' + +const ConfirmDeleteAccountContainer = (props: Props) => { + if (!props.viewControllerManager.accountMenuController.deletingAccount) { + return null + } + return +} + +export default observer(ConfirmDeleteAccountContainer) diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/Account/AccountPreferences.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/Account/AccountPreferences.tsx index f9f9e77ce..e19b7d04c 100644 --- a/packages/web/src/javascripts/Components/Preferences/Panes/Account/AccountPreferences.tsx +++ b/packages/web/src/javascripts/Components/Preferences/Panes/Account/AccountPreferences.tsx @@ -10,6 +10,7 @@ import FilesSection from './Files' import PreferencesPane from '../../PreferencesComponents/PreferencesPane' import SubscriptionSharing from './SubscriptionSharing/SubscriptionSharing' import Email from './Email' +import DeleteAccount from '@/Components/Preferences/Panes/Account/DeleteAccount' type Props = { application: WebApplication @@ -33,6 +34,7 @@ const AccountPreferences = ({ application, viewControllerManager }: Props) => ( )} + ) diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/Account/DeleteAccount.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/Account/DeleteAccount.tsx new file mode 100644 index 000000000..e4eec4db7 --- /dev/null +++ b/packages/web/src/javascripts/Components/Preferences/Panes/Account/DeleteAccount.tsx @@ -0,0 +1,42 @@ +import { observer } from 'mobx-react-lite' +import PreferencesSegment from '@/Components/Preferences/PreferencesComponents/PreferencesSegment' +import { Text, Title } from '@/Components/Preferences/PreferencesComponents/Content' +import Button from '@/Components/Button/Button' +import PreferencesGroup from '@/Components/Preferences/PreferencesComponents/PreferencesGroup' +import { ViewControllerManager } from '@Controllers/ViewControllerManager' +import { WebApplication } from '@/Application/Application' + +type Props = { + application: WebApplication + viewControllerManager: ViewControllerManager +} + +const DeleteAccount = ({ application, viewControllerManager }: Props) => { + if (!application.hasAccount()) { + return null + } + return ( + + + Delete account + + This action is irreversible. After deletion completes, you will be signed out on all devices. If you have an + active paid subscription, cancel the subscription first. Otherwise, if you'd like to keep the subscription, + you can re-register with the same email after deletion, and your subscription will be linked back up with your + account. + +
+
+
+
+ ) +} + +export default observer(DeleteAccount) diff --git a/packages/web/src/javascripts/Constants/Strings.ts b/packages/web/src/javascripts/Constants/Strings.ts index 7b04c2bbd..9c59711b0 100644 --- a/packages/web/src/javascripts/Constants/Strings.ts +++ b/packages/web/src/javascripts/Constants/Strings.ts @@ -99,6 +99,8 @@ export const STRING_UPGRADE_ACCOUNT_CONFIRM_BUTTON = 'Upgrade' export const STRING_REMOVE_OFFLINE_KEY_CONFIRMATION = 'This will delete the previously saved offline key.' +export const STRING_DELETE_ACCOUNT_CONFIRMATION = 'Are you sure you want to permanently delete your account?' + export const STRING_FAILED_TO_UPDATE_USER_SETTING = 'There was an error while trying to update your settings. Please try again.' diff --git a/packages/web/src/javascripts/Controllers/AccountMenu/AccountMenuController.ts b/packages/web/src/javascripts/Controllers/AccountMenu/AccountMenuController.ts index 99edfeeaf..d72f1c48f 100644 --- a/packages/web/src/javascripts/Controllers/AccountMenu/AccountMenuController.ts +++ b/packages/web/src/javascripts/Controllers/AccountMenu/AccountMenuController.ts @@ -24,6 +24,7 @@ export class AccountMenuController extends AbstractViewController { encryptionStatusString = '' isBackupEncrypted = false showSignIn = false + deletingAccount = false showRegister = false shouldAnimateCloseMenu = false currentPane = AccountMenuPane.GeneralMenu @@ -49,6 +50,7 @@ export class AccountMenuController extends AbstractViewController { encryptionStatusString: observable, isBackupEncrypted: observable, showSignIn: observable, + deletingAccount: observable, showRegister: observable, currentPane: observable, shouldAnimateCloseMenu: observable, @@ -64,6 +66,7 @@ export class AccountMenuController extends AbstractViewController { setCurrentPane: action, setEnableServerOption: action, setServer: action, + setDeletingAccount: action, notesAndTagsCount: computed, }) @@ -155,6 +158,10 @@ export class AccountMenuController extends AbstractViewController { this.currentPane = pane } + setDeletingAccount = (deletingAccount: boolean): void => { + this.deletingAccount = deletingAccount + } + get notesAndTagsCount(): number { return this.notesAndTags.length }