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/account-preferences.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Form, Switch, Tooltip } from "antd";6import { join } from "path";7import { FormattedMessage } from "react-intl";8import { Col, Row } from "@cocalc/frontend/antd-bootstrap";9import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";10import { A, Loading } from "@cocalc/frontend/components";11import { Footer } from "@cocalc/frontend/customize";12import { appBasePath } from "@cocalc/frontend/customize/app-base-path";13import track from "@cocalc/frontend/user-tracking";14import { EditorSettings } from "./editor-settings/editor-settings";15import { KeyboardSettings } from "./keyboard-settings";16import { OtherSettings } from "./other-settings";17import { ProfileSettings } from "./profile-settings";18import { AccountSettings } from "./settings/account-settings";19import ApiKeys from "./settings/api-keys";20import TableError from "./table-error";21import { TerminalSettings } from "./terminal-settings";2223export const AccountPreferences: React.FC = () => {24const account_id = useTypedRedux("account", "account_id");25const first_name = useTypedRedux("account", "first_name");26const last_name = useTypedRedux("account", "last_name");27const name = useTypedRedux("account", "name");28const email_address = useTypedRedux("account", "email_address");29const email_address_verified = useTypedRedux(30"account",31"email_address_verified",32);33const passports = useTypedRedux("account", "passports");34const sign_out_error = useTypedRedux("account", "sign_out_error");35const stripe_customer = useTypedRedux("account", "stripe_customer");36const other_settings = useTypedRedux("account", "other_settings");37const is_anonymous = useTypedRedux("account", "is_anonymous");38const created = useTypedRedux("account", "created");39const strategies = useTypedRedux("account", "strategies");40const unlisted = useTypedRedux("account", "unlisted");41const email_enabled = useTypedRedux("customize", "email_enabled");42const verify_emails = useTypedRedux("customize", "verify_emails");43const kucalc = useTypedRedux("customize", "kucalc");4445function render_account_settings(): JSX.Element {46return (47<AccountSettings48account_id={account_id}49first_name={first_name}50last_name={last_name}51name={name}52email_address={email_address}53email_address_verified={email_address_verified}54passports={passports}55sign_out_error={sign_out_error}56other_settings={other_settings as any}57is_anonymous={is_anonymous}58email_enabled={email_enabled}59verify_emails={verify_emails}60created={created}61strategies={strategies}62unlisted={unlisted}63/>64);65}6667function render_other_settings(): JSX.Element {68if (other_settings == null) return <Loading />;69return (70<OtherSettings71other_settings={other_settings as any}72is_stripe_customer={73!!stripe_customer?.getIn(["subscriptions", "total_count"])74}75kucalc={kucalc}76/>77);78}7980function renderDarkMode(): JSX.Element {81return (82<Tooltip title="Enable dark mode across the entire user interface. See further dark mode configuration below.">83<Form>84<Form.Item85label={86<div87onClick={() => {88redux89.getActions("account")90.set_other_settings(91"dark_mode",92!other_settings.get("dark_mode"),93);94}}95style={{96cursor: "pointer",97color: "rgba(229, 224, 216)",98backgroundColor: "rgb(36, 37, 37)",99padding: "5px 10px",100borderRadius: "3px",101}}102>103Dark Mode104</div>105}106>107<Switch108checked={other_settings.get("dark_mode")}109onChange={(checked) => {110redux111.getActions("account")112.set_other_settings("dark_mode", checked);113track("dark-mode", { how: "settings page", checked });114}}115/>116</Form.Item>117</Form>118</Tooltip>119);120}121122function render_all_settings(): JSX.Element {123return (124<>125<div style={{ float: "right" }}>{renderDarkMode()}</div>126<h2>127<FormattedMessage128id="account.account_preferences.title"129defaultMessage={"Account Preferences"}130/>131</h2>132<div style={{ fontSize: "14pt" }}>133<FormattedMessage134id="accountaccount.account_preferences.subtitle"135defaultMessage={136"Adjust account preferences below. <A>Visit your account configuration for more...</A>"137}138values={{139A: (ch) => <A href={join(appBasePath, "config")}>{ch}</A>,140}}141/>142</div>143<br />144<br />145<Row>146<Col xs={12} md={6}>147{render_account_settings()}148<ProfileSettings149email_address={email_address}150// first_name={first_name}151// last_name={last_name}152/>153{render_other_settings()}154{!is_anonymous && <ApiKeys />}155</Col>156<Col xs={12} md={6}>157<EditorSettings />158<TerminalSettings />159<KeyboardSettings />160</Col>161</Row>162<Footer />163</>164);165}166167return (168<div style={{ marginTop: "1em" }}>169<TableError />170{is_anonymous ? render_account_settings() : render_all_settings()}171</div>172);173};174175176