-
-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): delete account option in settings (#1768)
- Loading branch information
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/mobile/src/Screens/Settings/Sections/DeleteSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<RegularView> | ||
<SectionHeader /> | ||
<TableSection> | ||
<ButtonCell | ||
first | ||
last | ||
important | ||
leftAligned={true} | ||
title={deleting ? 'Deleting...' : 'Delete Account'} | ||
onPress={deleteAccount} | ||
></ButtonCell> | ||
</TableSection> | ||
</RegularView> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters