Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/account/delete-account.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert, Button, Input } from "antd";6import { FormattedMessage, useIntl } from "react-intl";78import {9React,10Rendered,11useState,12useTypedRedux,13} from "@cocalc/frontend/app-framework";14import { ErrorDisplay, Icon } from "@cocalc/frontend/components";15import { CancelText } from "@cocalc/frontend/i18n/components";1617interface Props {18initial_click: () => void;19confirm_click: () => void;20cancel_click: () => void;21user_name: string;22show_confirmation?: boolean;23style?: React.CSSProperties;24}2526export function DeleteAccount(props: Props) {27const intl = useIntl();2829return (30<div>31<div style={{ height: "26px" }}>32<Button33disabled={props.show_confirmation}34className="pull-right"35style={props.style}36onClick={props.initial_click}37>38<Icon name="trash" />{" "}39{intl.formatMessage({40id: "account.delete-account.button",41defaultMessage: "Delete Account",42})}43...44</Button>45</div>46{props.show_confirmation ? (47<DeleteAccountConfirmation48confirm_click={props.confirm_click}49cancel_click={props.cancel_click}50required_text={props.user_name}51/>52) : undefined}53</div>54);55}5657interface ConfProps {58confirm_click: () => void;59cancel_click: () => void;60required_text: string;61}6263// Concious choice to make them actually click the confirm delete button.64function DeleteAccountConfirmation({65confirm_click,66cancel_click,67required_text,68}: ConfProps) {69const intl = useIntl();7071const account_deletion_error = useTypedRedux(72"account",73"account_deletion_error",74);7576// State is lost on re-render from cancel. But this is what we want.77const [confirmation_text, set_confirmation_text] = useState<string>("");7879function render_error(): Rendered {80if (account_deletion_error == null) {81return;82}83return <ErrorDisplay error={account_deletion_error} />;84}8586return (87<Alert88showIcon89type="warning"90style={{91marginTop: "26px",92}}93message={94<FormattedMessage95id="account.delete-account.alert.message"96defaultMessage={"Are you sure you want to DELETE YOUR ACCOUNT?"}97/>98}99description={100<div>101<br />102<FormattedMessage103id="account.delete-account.alert.description"104defaultMessage={`You will <b>immediately</b> lose access to <b>all</b> of your projects,105any subscriptions will be canceled, and all unspent credit will be lost.106{br}107{hr}108To DELETE YOUR ACCOUNT, first enter "{required_text}" below:`}109values={{110required_text: required_text,111br: <br />,112hr: <hr style={{ marginTop: "10px", marginBottom: "10px" }} />,113}}114/>115<br />116<Input117autoFocus118value={confirmation_text}119placeholder="Full name"120type="text"121onChange={(e) => {122set_confirmation_text((e.target as any).value);123}}124style={{125margin: "15px",126width: "90%",127}}128/>129<div style={{ display: "flex" }}>130<Button131type="primary"132onClick={cancel_click}133style={{ marginRight: "15px" }}134>135<CancelText />136</Button>137<Button138disabled={confirmation_text !== required_text}139onClick={() => confirm_click()}140>141<Icon name="trash" />{" "}142{intl.formatMessage({143id: "account.delete-account.confirmation",144defaultMessage: "Yes, DELETE MY ACCOUNT",145})}146</Button>147</div>148{render_error()}149</div>150}151/>152);153}154155156