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/billing/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 { unreachable } from "@cocalc/util/misc";6import { COLORS } from "@cocalc/util/theme";7import { Alert, Layout } from "antd";8import InPlaceSignInOrUp from "components/auth/in-place-sign-in-or-up";9import Anonymous from "components/misc/anonymous";10import Loading from "components/share/loading";11import { MAX_WIDTH } from "lib/config";12import useProfile from "lib/hooks/profile";13import useCustomize from "lib/use-customize";14import { useRouter } from "next/router";15import { MainPagesType } from "./consts";16import InvoicesAndReceipts from "./invoices-and-receipts";17import Menu from "./menu";18import Overview from "./overview";19import PaymentMethods from "./payment-methods";20import Subscriptions from "./subscriptions";2122const { Content } = Layout;2324interface Props {25page: [MainPagesType | undefined]; // empty array is the overview page26}2728export default function ConfigLayout({ page }: Props) {29const { isCommercial } = useCustomize();30const router = useRouter();31const profile = useProfile({ noCache: true });32if (!isCommercial) {33return (34<Alert35showIcon36style={{37margin: "30px auto",38maxWidth: "400px",39fontSize: "12pt",40padding: "15px 30px",41}}42type="warning"43message="Billing is not enabled for this server."44/>45);46}47if (!profile) {48return <Loading large center />;49}50const { account_id, is_anonymous } = profile;5152if (!account_id) {53return (54<Alert55style={{ margin: "15px auto" }}56type="warning"57message={58<InPlaceSignInOrUp59title="Account Configuration"60why="to see information about your licenses"61onSuccess={() => {62router.reload();63}}64/>65}66/>67);68}6970if (is_anonymous) {71return <Anonymous />;72}7374// page could be an empty array, then main is undefined → overview page75const [main] = page;7677function body() {78// main must be in MainPages defined in [[..page]].tsx79if (main == null) return <Overview />;80switch (main) {81case "cards":82return <PaymentMethods />;83case "subscriptions":84return <Subscriptions />;85case "receipts":86return <InvoicesAndReceipts />;87default:88unreachable(main);89}90}9192// this layout is the same as ../store/index.tsx93return (94<Layout95style={{96padding: "0 24px 24px",97backgroundColor: "white",98color: COLORS.GRAY_D,99}}100>101<Content102style={{103margin: 0,104minHeight: "60vh",105}}106>107<div style={{ maxWidth: MAX_WIDTH, margin: "auto" }}>108<Menu main={main} />109{body()}110</div>111</Content>112</Layout>113);114}115116117