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/next/components/account/config/layout.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert, Divider, Layout, Space } from "antd";6import { join } from "path";78import { Icon } from "@cocalc/frontend/components/icon";9import { capitalize } from "@cocalc/util/misc";10import { COLORS } from "@cocalc/util/theme";11import Avatar from "components/account/avatar";12import Config from "components/account/config";13import InPlaceSignInOrUp from "components/auth/in-place-sign-in-or-up";14import { Paragraph, Text, Title } from "components/misc";15import A from "components/misc/A";16import Loading from "components/share/loading";17import SiteName from "components/share/site-name";18import basePath from "lib/base-path";19import useIsBrowser from "lib/hooks/is-browser";20import useProfile from "lib/hooks/profile";21import { useRouter } from "next/router";22import Anonymous from "./anonymous";23import ConfigMenu from "./menu";24import { menu } from "./register";25import Search from "./search/component";26import AIAvatar from "@cocalc/frontend/components/ai-avatar";2728const { Content, Sider } = Layout;2930interface Props {31page: string[]; // e.g. ["account", "name"]32}3334export default function ConfigLayout({ page }: Props) {35const router = useRouter();36const isBrowser = useIsBrowser();37const profile = useProfile({ noCache: true });38if (!profile) {39return (40<div41style={{ textAlign: "center", minHeight: "400px", paddingTop: "100px" }}42>43<Loading large />44</div>45);46}47const { account_id, is_anonymous } = profile;4849if (!account_id) {50return (51<Alert52style={{ margin: "15px auto" }}53type="warning"54message={55<InPlaceSignInOrUp56title="Account Configuration"57why="to edit your account configuration"58onSuccess={() => {59router.reload();60}}61/>62}63/>64);65}6667if (is_anonymous) {68return <Anonymous />;69}7071const [main, sub] = page;72const info = menu[main]?.[sub];7374function renderIcon() {75const { icon } = info;76if (icon === "ai") {77return (78<AIAvatar79size={22}80style={{ position: "relative", top: "-12px", paddingRight: "15px" }}81/>82);83} else {84return <Icon name={icon} style={{ marginRight: "5px" }} />;85}86}8788const content = (89<Content90style={{91padding: 24,92margin: 0,93minHeight: 500,94...(info?.danger95? { color: "#ff4d4f", backgroundColor: COLORS.ATND_BG_RED_L }96: undefined),97}}98>99<Space style={{ marginBottom: "15px" }}>100<Avatar account_id={account_id} style={{ marginRight: "15px" }} />101<div style={{ color: COLORS.GRAY }}>102<Text strong style={{ fontSize: "13pt" }}>103{profile?.first_name} {profile?.last_name}104{profile.name ? ` (@${profile.name})` : ""}105</Text>106<div>Your account</div>107</div>108</Space>109{main != "search" && <Search />}110{info && (111<>112<Title level={2}>113{renderIcon()} {capitalize(main)} - {info.title}114</Title>115<Paragraph type="secondary">{info.desc}</Paragraph>116<Divider />117</>118)}119{info?.desc?.toLowerCase().includes("todo") && (120<Alert121style={{ margin: "15px auto", maxWidth: "600px" }}122message={<b>Under Constructions</b>}123description={124<Paragraph>125This page is under construction. To configure your <SiteName />{" "}126account, visit{" "}127<A href={join(basePath, "settings")} external>128Account Preferences129</A>130.131</Paragraph>132}133type="warning"134showIcon135/>136)}137<Config main={main} sub={sub} />138</Content>139);140141return (142<Layout>143<Sider width={"30ex"} breakpoint="sm" collapsedWidth="0">144{isBrowser && <ConfigMenu main={main} sub={sub} />}145</Sider>146<Layout147style={{148padding: "0",149backgroundColor: "white",150color: COLORS.GRAY_D,151maxWidth: "1200px",152}}153>154{content}155</Layout>156</Layout>157);158}159160161