From 08cac861aec7f2630ee743b8321dc016d6dfd43c Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 7 Jul 2018 18:09:39 -0500 Subject: [PATCH] Done. Needs testing once back online --- app/scenes/Settings/Profile.js | 17 +++++++++++++++++ app/scenes/UserDelete.js | 10 ++++++++-- app/stores/AuthStore.js | 11 +++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/scenes/Settings/Profile.js b/app/scenes/Settings/Profile.js index c71236bd..e989889e 100644 --- a/app/scenes/Settings/Profile.js +++ b/app/scenes/Settings/Profile.js @@ -11,6 +11,7 @@ import Input, { LabelText } from 'components/Input'; import Button from 'components/Button'; import CenteredContent from 'components/CenteredContent'; import PageTitle from 'components/PageTitle'; +import UserDelete from 'scenes/UserDelete'; import Flex from 'shared/components/Flex'; type Props = { @@ -25,6 +26,7 @@ class Profile extends React.Component { @observable name: string; @observable avatarUrl: ?string; + @observable showDeleteModal: boolean = false; componentDidMount() { if (this.props.auth.user) { @@ -58,6 +60,10 @@ class Profile extends React.Component { this.props.ui.showToast(error || 'Unable to upload new avatar'); }; + toggleDeleteAccount = () => { + this.showDeleteModal = !this.showDeleteModal; + }; + get isValid() { return this.form && this.form.checkValidity(); } @@ -97,6 +103,17 @@ class Profile extends React.Component { {isSaving ? 'Saving…' : 'Save'} +

 

+ +

Delete Account

+

+ You may delete your account at any time, note that this is + unrecoverable.{' '} + Delete account. +

+ {this.showDeleteModal && ( + + )} ); } diff --git a/app/scenes/UserDelete.js b/app/scenes/UserDelete.js index a5b16b3c..70f122ff 100644 --- a/app/scenes/UserDelete.js +++ b/app/scenes/UserDelete.js @@ -10,6 +10,7 @@ import AuthStore from 'stores/AuthStore'; type Props = { auth: AuthStore, + onRequestClose: () => *, }; @observer @@ -19,7 +20,7 @@ class UserDelete extends React.Component { handleSubmit = async (ev: SyntheticEvent<*>) => { ev.preventDefault(); this.isDeleting = true; - const success = await this.props.auth.delete(); + const success = await this.props.auth.deleteUser(); if (success) { this.props.auth.logout(); @@ -40,8 +41,13 @@ class UserDelete extends React.Component { associated with your user and cannot be undone. You will be immediately logged out of Outline. + + + Note: Signing back in will cause your account to + be automatically reprovisioned. + diff --git a/app/stores/AuthStore.js b/app/stores/AuthStore.js index 52621025..ba9cd30d 100644 --- a/app/stores/AuthStore.js +++ b/app/stores/AuthStore.js @@ -50,6 +50,17 @@ class AuthStore { } }; + @action + deleteUser = async () => { + await client.post(`/user.delete`, { confirmation: true }); + + runInAction('AuthStore#updateUser', () => { + this.user = null; + this.team = null; + this.token = null; + }); + }; + @action updateUser = async (params: { name: string, avatarUrl: ?string }) => { this.isSaving = true;