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/store/menu.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import React, { useContext } from "react";6import { Menu, MenuProps, Typography, Flex } from "antd";7import { useRouter } from "next/router";89import { currency, round2down } from "@cocalc/util/misc";10import { COLORS } from "@cocalc/util/theme";11import { Icon } from "@cocalc/frontend/components/icon";1213import { StoreBalanceContext } from "../../lib/balance";1415const { Text } = Typography;1617type MenuItem = Required<MenuProps>["items"][number];1819const styles: { [k: string]: React.CSSProperties } = {20menuBookend: {21height: "100%",22whiteSpace: "nowrap",23flexGrow: 1,24textAlign: "end",25},26menu: {27width: "100%",28height: "100%",29border: 0,30},31menuRoot: {32marginBottom: "24px",33alignItems: "center",34border: 0,35borderBottom: "1px solid rgba(5, 5, 5, 0.06)",36boxShadow: "none",37},38menuContainer: {39alignItems: "center",40whiteSpace: "nowrap",41maxWidth: "100%",42flexGrow: 1,43},44};4546export interface ConfigMenuProps {47main?: string;48}4950export default function ConfigMenu({ main }: ConfigMenuProps) {51const router = useRouter();52const { balance } = useContext(StoreBalanceContext);5354const handleMenuItemSelect: MenuProps["onSelect"] = ({ keyPath }) => {55router.push(`/store/${keyPath[0]}`, undefined, {56scroll: false,57});58};5960const items: MenuItem[] = [61{62label: "Licenses",63key: "site-license",64icon: <Icon name="key" />,65},66{67label: "Cart",68key: "cart",69icon: <Icon name="shopping-cart" />,70},71{72label: "Checkout",73key: "checkout",74icon: <Icon name="list" />,75},76{77label: "Congrats",78key: "congrats",79icon: <Icon name="check-circle" />,80},81{82label: "Vouchers",83key: "vouchers",84icon: <Icon name="gift" />,85},86];8788return (89<Flex90gap="middle"91justify="space-between"92style={styles.menuRoot}93wrap="wrap"94>95<Flex style={styles.menuContainer} align="center">96<strong>97<a98onClick={() => {99router.push("/store", undefined, {100scroll: false,101});102}}103style={{ color: COLORS.GRAY_D, marginRight: "12px" }}104>105Store106</a>107</strong>108<Menu109mode="horizontal"110selectedKeys={main ? [main] : undefined}111style={styles.menu}112onSelect={handleMenuItemSelect}113items={items}114/>115</Flex>116<Text strong style={styles.menuBookend}>117{balance !== undefined118? `Balance: ${currency(round2down(balance))}`119: null}120</Text>121</Flex>122);123}124125126