diff --git a/app/auth/DeleteAccountModal.jsx b/app/auth/DeleteAccountModal.jsx new file mode 100644 index 0000000..4ecec64 --- /dev/null +++ b/app/auth/DeleteAccountModal.jsx @@ -0,0 +1,115 @@ +import { h, Component } from "preact"; +import linkState from "linkstate"; + +import api from "api.js"; +import errors from "errors.js"; + +import Modal from "ui/Modal.jsx"; + +export default class DeleteAccountModal extends Component { + constructor(props) { + super(props); + this.state = { + loading: false, + error: "", + + stage: 0, + password: "" + }; + } + + close() { + this.props.openModal(""); + } + + continueDelete() { + this.setState({ + stage: 1 + }); + } + + finishDelete() { + this.setState({ + loading: true, + error: "" + }, () => { + api.post("auth/requestAccountDelete", { + password: this.state.password, + clientType: "web" + }, (data) => { + if (data.status == "ok") { + this.setState({ + loading: false, + stage: 2 + }); + } else { + if (data.error == "creds_incorrect") { + this.setState({ + loading: false, + error: "The password was incorrect." + }); + return; + } + + this.setState({ + loading: false, + error: errors.getFriendlyString(data.error) + }); + } + }); + }); + } + + keyup(e) { + if (e.keyCode == 13) { + this.finishDelete(); + } + } + + render(props, state) { + if (state.stage == 1) { + return + + + ; + } + + if (state.stage == 2) { + return + + + ; + } + + return + + + ; + } +}; \ No newline at end of file diff --git a/app/settings/panes/account/AccountPane.jsx b/app/settings/panes/account/AccountPane.jsx index 3f9775a..cde2e81 100644 --- a/app/settings/panes/account/AccountPane.jsx +++ b/app/settings/panes/account/AccountPane.jsx @@ -37,6 +37,10 @@ export default class AccountPane extends Component { this.props.openModal("enroll", {}); } + deleteAccount() { + this.props.openModal("deleteAccount", {}); + } + resendVerificationEmail() { this.setState({ resendLoading: true @@ -78,6 +82,7 @@ export default class AccountPane extends Component { +
diff --git a/app/ui/ModalManager.jsx b/app/ui/ModalManager.jsx index 58bee99..13158a9 100644 --- a/app/ui/ModalManager.jsx +++ b/app/ui/ModalManager.jsx @@ -5,6 +5,7 @@ import { h, Component } from "preact"; import AccountMigrateModal from "auth/AccountMigrateModal.jsx"; import ChangeEmailModal from "auth/ChangeEmailModal.jsx"; import ChangePasswordModal from "auth/ChangePasswordModal.jsx"; +import DeleteAccountModal from "auth/DeleteAccountModal.jsx"; import EventModal from "calendar/EventModal.jsx"; import EventProvidedModal from "calendar/EventProvidedModal.jsx"; import ClassModal from "classes/ClassModal.jsx"; @@ -43,6 +44,7 @@ export default class ModalManager extends Component { imageInfo: ImageInfoModal, applicationDelete: MyApplicationDeleteModal, applicationSettings: MyApplicationSettingsModal, + deleteAccount: DeleteAccountModal }; var modal;