Done. Needs testing once back online

This commit is contained in:
Tom Moor
2018-07-07 18:09:39 -05:00
parent dd52f4d82a
commit 08cac861ae
3 changed files with 36 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import Input, { LabelText } from 'components/Input';
import Button from 'components/Button'; import Button from 'components/Button';
import CenteredContent from 'components/CenteredContent'; import CenteredContent from 'components/CenteredContent';
import PageTitle from 'components/PageTitle'; import PageTitle from 'components/PageTitle';
import UserDelete from 'scenes/UserDelete';
import Flex from 'shared/components/Flex'; import Flex from 'shared/components/Flex';
type Props = { type Props = {
@ -25,6 +26,7 @@ class Profile extends React.Component<Props> {
@observable name: string; @observable name: string;
@observable avatarUrl: ?string; @observable avatarUrl: ?string;
@observable showDeleteModal: boolean = false;
componentDidMount() { componentDidMount() {
if (this.props.auth.user) { if (this.props.auth.user) {
@ -58,6 +60,10 @@ class Profile extends React.Component<Props> {
this.props.ui.showToast(error || 'Unable to upload new avatar'); this.props.ui.showToast(error || 'Unable to upload new avatar');
}; };
toggleDeleteAccount = () => {
this.showDeleteModal = !this.showDeleteModal;
};
get isValid() { get isValid() {
return this.form && this.form.checkValidity(); return this.form && this.form.checkValidity();
} }
@ -97,6 +103,17 @@ class Profile extends React.Component<Props> {
{isSaving ? 'Saving…' : 'Save'} {isSaving ? 'Saving…' : 'Save'}
</Button> </Button>
</form> </form>
<p>&nbsp;</p>
<h2>Delete Account</h2>
<p>
You may delete your account at any time, note that this is
unrecoverable.{' '}
<a onClick={this.toggleDeleteAccount}>Delete account</a>.
</p>
{this.showDeleteModal && (
<UserDelete onRequestClose={this.toggleDeleteAccount} />
)}
</CenteredContent> </CenteredContent>
); );
} }

View File

@ -10,6 +10,7 @@ import AuthStore from 'stores/AuthStore';
type Props = { type Props = {
auth: AuthStore, auth: AuthStore,
onRequestClose: () => *,
}; };
@observer @observer
@ -19,7 +20,7 @@ class UserDelete extends React.Component<Props> {
handleSubmit = async (ev: SyntheticEvent<*>) => { handleSubmit = async (ev: SyntheticEvent<*>) => {
ev.preventDefault(); ev.preventDefault();
this.isDeleting = true; this.isDeleting = true;
const success = await this.props.auth.delete(); const success = await this.props.auth.deleteUser();
if (success) { if (success) {
this.props.auth.logout(); this.props.auth.logout();
@ -40,8 +41,13 @@ class UserDelete extends React.Component<Props> {
associated with your user and cannot be undone. You will be associated with your user and cannot be undone. You will be
immediately logged out of Outline. immediately logged out of Outline.
</HelpText> </HelpText>
<HelpText>
<strong>Note:</strong> Signing back in will cause your account to
be automatically reprovisioned.
</HelpText>
<Button type="submit" danger> <Button type="submit" danger>
{this.isDeleting ? 'Deleting…' : 'Delete'} {this.isDeleting ? 'Deleting…' : 'Delete My Account'}
</Button> </Button>
</form> </form>
</Flex> </Flex>

View File

@ -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 @action
updateUser = async (params: { name: string, avatarUrl: ?string }) => { updateUser = async (params: { name: string, avatarUrl: ?string }) => {
this.isSaving = true; this.isSaving = true;