From 7d21046b5189eb14a5957bda6fa788d743d8ebb6 Mon Sep 17 00:00:00 2001 From: Mo Date: Fri, 7 Oct 2022 08:23:18 -0500 Subject: [PATCH] feat(mobile): delete account option in settings (#1768) --- .../Settings/Sections/DeleteSection.tsx | 50 +++++++++++++++++++ .../Settings/Sections/WorkspacesSection.tsx | 2 +- .../mobile/src/Screens/Settings/Settings.tsx | 2 + 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 packages/mobile/src/Screens/Settings/Sections/DeleteSection.tsx diff --git a/packages/mobile/src/Screens/Settings/Sections/DeleteSection.tsx b/packages/mobile/src/Screens/Settings/Sections/DeleteSection.tsx new file mode 100644 index 000000000..1e9c5a20f --- /dev/null +++ b/packages/mobile/src/Screens/Settings/Sections/DeleteSection.tsx @@ -0,0 +1,50 @@ +import { ApplicationContext } from '@Root/ApplicationContext' +import { ButtonCell } from '@Root/Components/ButtonCell' +import { SectionHeader } from '@Root/Components/SectionHeader' +import { TableSection } from '@Root/Components/TableSection' +import { ButtonType } from '@standardnotes/snjs' +import React, { useContext, useState } from 'react' +import { RegularView } from './AuthSection.styled' + +export const DeleteSection = () => { + const application = useContext(ApplicationContext) + const [deleting, setDeleting] = useState(false) + + const deleteAccount = async () => { + const message = + "This action is irreversible. After deletion completes, you will be signed out on all devices, and this application will exit. 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." + const confirmed = await application!.alertService.confirm( + message, + 'Are you sure?', + 'Delete Account', + ButtonType.Danger, + ) + + if (!confirmed) { + return + } + + setDeleting(true) + + const result = await application!.user.deleteAccount() + if (result.error) { + void application!.alertService.alert('An error occurred while deleting your account. Please try again.') + } + } + + return ( + + + + + + + ) +} diff --git a/packages/mobile/src/Screens/Settings/Sections/WorkspacesSection.tsx b/packages/mobile/src/Screens/Settings/Sections/WorkspacesSection.tsx index 92c5e2e85..f49409c51 100644 --- a/packages/mobile/src/Screens/Settings/Sections/WorkspacesSection.tsx +++ b/packages/mobile/src/Screens/Settings/Sections/WorkspacesSection.tsx @@ -153,7 +153,7 @@ export const WorkspacesSection = () => { } await appGroup.unloadCurrentAndCreateNewDescriptor() - }, [WorkspaceAction.AddAnother, appGroup, applicationDescriptors, getWorkspaceActionConfirmation]) + }, [WorkspaceAction.AddAnother, appGroup, getWorkspaceActionConfirmation]) const signOutAllWorkspaces = useCallback(async () => { try { diff --git a/packages/mobile/src/Screens/Settings/Settings.tsx b/packages/mobile/src/Screens/Settings/Settings.tsx index 84d0442c5..4ba4814b0 100644 --- a/packages/mobile/src/Screens/Settings/Settings.tsx +++ b/packages/mobile/src/Screens/Settings/Settings.tsx @@ -8,6 +8,7 @@ import { ApplicationEvent, FeatureIdentifier, FeatureStatus } from '@standardnot import React, { useCallback, useEffect, useState } from 'react' import { AuthSection } from './Sections/AuthSection' import { CompanySection } from './Sections/CompanySection' +import { DeleteSection } from './Sections/DeleteSection' import { EncryptionSection } from './Sections/EncryptionSection' import { NewMobileSection } from './Sections/NewMobilePreview' import { OptionsSection } from './Sections/OptionsSection' @@ -68,6 +69,7 @@ export const Settings = (props: Props) => { + {application.hasAccount() && } ) }