CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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