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/sign-out.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/4import { Button, Popconfirm } from "antd";5import { FormattedMessage, useIntl } from "react-intl";6import { Icon } from "@cocalc/frontend/components/icon";7import { React, Rendered, redux } from "@cocalc/frontend/app-framework";8import { labels } from "@cocalc/frontend/i18n";9import track from "@cocalc/frontend/user-tracking";1011interface Props {12everywhere?: boolean;13sign_in?: boolean;14highlight?: boolean;15style?: React.CSSProperties;16narrow?: boolean;17}1819export const SignOut: React.FC<Props> = (props: Readonly<Props>) => {20const { everywhere, sign_in, highlight, style, narrow = false } = props;2122const intl = useIntl();2324function sign_out(): void {25const account = redux.getActions("account");26if (account != null) {27track("sign-out", { how: "settings-page", everywhere, sign_in });28account.sign_out(!!everywhere, !!sign_in);29}30}3132function render_body(): Rendered {33if (sign_in) {34return (35<span>36<FormattedMessage37id="account.sign_out.body.sign_in"38description={"Sign in button, if not signed in"}39defaultMessage={"Sign in to your account..."}40/>41</span>42);43} else {44return (45<span>46<FormattedMessage47id="account.sign_out.body.sign_out"48description={"Sign out button, if signed in"}49defaultMessage={`Sign out{everywhere, select, true { everywhere} other {}}...`}50values={{ everywhere }}51/>52</span>53);54}55}5657// I think not using reduxProps is fine for this, since it's only rendered once58// you are signed in, and falling back to "your account" isn't bad.59const store = redux.getStore("account");60const account: string = store.get("email_address") ?? "your account";6162return (63<Popconfirm64title={65<div style={{ maxWidth: "60ex" }}>66<FormattedMessage67id="account.sign-out.button.title"68description="Sign out/Sign out everyhwere button in account settings"69defaultMessage={`Are you sure you want to sign {account} out70{everywhere, select,71true {on all web browsers? Every web browser will have to reauthenticate before using this account again.}72other {on this web browser?}73}74{is_anonymous, select,75true {Everything you have done using this TEMPORARY ACCOUNT will be immediately deleted! If you would like to save your work to a new account, click cancel and sign up below.}76other {}77}`}78values={{79account,80everywhere,81is_anonymous: store.get("is_anonymous"),82}}83/>84</div>85}86onConfirm={sign_out}87okText={intl.formatMessage(88{89id: "account.sign-out.button.ok",90defaultMessage: `Yes, sign out{everywhere, select, true { everywhere} other {}}`,91},92{ everywhere },93)}94cancelText={intl.formatMessage(labels.cancel)}95>96{/* NOTE: weirdly darkreader breaks when we use the antd LogoutOutlined icon!? */}97<Button type={highlight ? "primary" : undefined} style={style}>98<Icon name="sign-in" />{" "}99{!narrow || everywhere ? render_body() : undefined}100</Button>101</Popconfirm>102);103};104105106