Path: blob/master/src/packages/frontend/account/account-preferences.tsx
1503 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Flex, Form, Switch, Tooltip } from "antd";67import { Col, Row } from "@cocalc/frontend/antd-bootstrap";8import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";9import { Loading } from "@cocalc/frontend/components";10import track from "@cocalc/frontend/user-tracking";11import { KUCALC_COCALC_COM } from "@cocalc/util/db-schema/site-defaults";12import { EditorSettings } from "./editor-settings/editor-settings";13import { KeyboardSettings } from "./keyboard-settings";14import { OtherSettings } from "./other-settings";15import { ProfileSettings } from "./profile-settings";16import { AccountSettings } from "./settings/account-settings";17import ApiKeys from "./settings/api-keys";18import GlobalSSHKeys from "./ssh-keys/global-ssh-keys";19import TableError from "./table-error";20import { TerminalSettings } from "./terminal-settings";2122export const AccountPreferences: React.FC = () => {23const account_id = useTypedRedux("account", "account_id");24const first_name = useTypedRedux("account", "first_name");25const last_name = useTypedRedux("account", "last_name");26const name = useTypedRedux("account", "name");27const email_address = useTypedRedux("account", "email_address");28const email_address_verified = useTypedRedux(29"account",30"email_address_verified",31);32const passports = useTypedRedux("account", "passports");33const sign_out_error = useTypedRedux("account", "sign_out_error");34const stripe_customer = useTypedRedux("account", "stripe_customer");35const other_settings = useTypedRedux("account", "other_settings");36const is_anonymous = useTypedRedux("account", "is_anonymous");37const created = useTypedRedux("account", "created");38const strategies = useTypedRedux("account", "strategies");39const unlisted = useTypedRedux("account", "unlisted");40const email_enabled = useTypedRedux("customize", "email_enabled");41const verify_emails = useTypedRedux("customize", "verify_emails");42const kucalc = useTypedRedux("customize", "kucalc");43const ssh_gateway = useTypedRedux("customize", "ssh_gateway");4445function render_account_settings(): React.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(): React.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(): React.JSX.Element {81return (82<Tooltip title="Enable dark mode across the entire user interface. See further dark mode configuration below.">83<Form style={{ height: "37px" }}>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(): React.JSX.Element {123return (124<>125<Flex>126<div style={{ flex: 1 }} />127{renderDarkMode()}128</Flex>129<Row>130<Col xs={12} md={6}>131{render_account_settings()}132<ProfileSettings133email_address={email_address}134// first_name={first_name}135// last_name={last_name}136/>137{render_other_settings()}138{(ssh_gateway || kucalc === KUCALC_COCALC_COM) && <GlobalSSHKeys />}139{!is_anonymous && <ApiKeys />}140</Col>141<Col xs={12} md={6}>142<EditorSettings />143<TerminalSettings />144<KeyboardSettings />145</Col>146</Row>147</>148);149}150151return (152<div>153<TableError />154{is_anonymous ? render_account_settings() : render_all_settings()}155</div>156);157};158159160