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/cost-info-bar.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 { CostInputPeriod } from "@cocalc/util/licenses/purchase/types";
7
import { Flex, Typography } from "antd";
8
import { MAX_WIDTH } from "lib/config";
9
import { AddToCartButton } from "./add-box";
10
import { describeItem, DisplayCost } from "./site-license-cost";
11
// import { NAVBAR_HEIGHT_PX } from "../landing/header";
12
const { Text } = Typography;
13
14
const INNER_STYLE: React.CSSProperties = {
15
paddingRight: "10px",
16
};
17
18
interface Props {
19
show: boolean;
20
cost: CostInputPeriod | undefined;
21
router: any;
22
form: any;
23
cartError: string | undefined;
24
setCartError: (error) => void;
25
noAccount: boolean;
26
}
27
28
// this is like a minimal "add box"
29
export const InfoBar: React.FC<Props> = (props: Props) => {
30
const { show, cost, router, form, cartError, setCartError, noAccount } =
31
props;
32
33
if (!show) return null;
34
35
function renderInfoBarContent() {
36
if (cost?.input.type == "cash-voucher") return null;
37
// if any of the fields in cost that start with the string "cost" are NaN, return null
38
const disabled =
39
!cost ||
40
Object.keys(cost).some((k) => k.startsWith("cost") && isNaN(cost[k]));
41
return (
42
<>
43
{disabled ? (
44
<Text type="secondary" italic={true} style={INNER_STYLE}>
45
License is not fully configured.
46
</Text>
47
) : (
48
<>
49
<>{describeItem({ info: cost.input, variant: "short" })}: </>
50
<Text strong={true} style={INNER_STYLE}>
51
<DisplayCost
52
cost={cost}
53
oneLine={true}
54
simple={true}
55
simpleShowPeriod={false}
56
discountTooltip={true}
57
/>
58
</Text>
59
</>
60
)}
61
{!noAccount && (
62
<AddToCartButton
63
cartError={cartError}
64
cost={cost}
65
form={form}
66
router={router}
67
setCartError={setCartError}
68
variant={"small"}
69
disabled={disabled}
70
/>
71
)}
72
</>
73
);
74
}
75
76
// this is a thin bar at the top, fixed position and height
77
// the width limit of the inner div is the same as for the div
78
// inside the "Content", i.e. the form itself, such that everything
79
// alignes nicely.
80
return (
81
<Flex
82
style={{
83
minHeight: "30px",
84
display: "flex", // we want to align the content at the bottom
85
backgroundColor: "white",
86
position: "fixed",
87
textAlign: "right",
88
// top: `${NAVBAR_HEIGHT_PX}px`,
89
top: 0,
90
left: 0,
91
right: 0,
92
zIndex: 1000,
93
padding: "8px",
94
boxShadow: "0 4px 4px rgba(0,0,0,0.2)",
95
overflow: "hidden",
96
}}
97
>
98
<div
99
style={{
100
maxWidth: MAX_WIDTH,
101
marginLeft: "auto",
102
marginRight: "auto",
103
alignSelf: "center",
104
flex: 1,
105
// whiteSpace: "nowrap",
106
}}
107
>
108
{renderInfoBarContent()}
109
</div>
110
</Flex>
111
);
112
};
113
114