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/cost-info-bar.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { CostInputPeriod } from "@cocalc/util/licenses/purchase/types";6import { Flex, Typography } from "antd";7import { MAX_WIDTH } from "lib/config";8import { AddToCartButton } from "./add-box";9import { describeItem, DisplayCost } from "./site-license-cost";10// import { NAVBAR_HEIGHT_PX } from "../landing/header";11const { Text } = Typography;1213const INNER_STYLE: React.CSSProperties = {14paddingRight: "10px",15};1617interface Props {18show: boolean;19cost: CostInputPeriod | undefined;20router: any;21form: any;22cartError: string | undefined;23setCartError: (error) => void;24noAccount: boolean;25}2627// this is like a minimal "add box"28export const InfoBar: React.FC<Props> = (props: Props) => {29const { show, cost, router, form, cartError, setCartError, noAccount } =30props;3132if (!show) return null;3334function renderInfoBarContent() {35if (cost?.input.type == "cash-voucher") return null;36// if any of the fields in cost that start with the string "cost" are NaN, return null37const disabled =38!cost ||39Object.keys(cost).some((k) => k.startsWith("cost") && isNaN(cost[k]));40return (41<>42{disabled ? (43<Text type="secondary" italic={true} style={INNER_STYLE}>44License is not fully configured.45</Text>46) : (47<>48<>{describeItem({ info: cost.input, variant: "short" })}: </>49<Text strong={true} style={INNER_STYLE}>50<DisplayCost51cost={cost}52oneLine={true}53simple={true}54simpleShowPeriod={false}55discountTooltip={true}56/>57</Text>58</>59)}60{!noAccount && (61<AddToCartButton62cartError={cartError}63cost={cost}64form={form}65router={router}66setCartError={setCartError}67variant={"small"}68disabled={disabled}69/>70)}71</>72);73}7475// this is a thin bar at the top, fixed position and height76// the width limit of the inner div is the same as for the div77// inside the "Content", i.e. the form itself, such that everything78// alignes nicely.79return (80<Flex81style={{82minHeight: "30px",83display: "flex", // we want to align the content at the bottom84backgroundColor: "white",85position: "fixed",86textAlign: "right",87// top: `${NAVBAR_HEIGHT_PX}px`,88top: 0,89left: 0,90right: 0,91zIndex: 1000,92padding: "8px",93boxShadow: "0 4px 4px rgba(0,0,0,0.2)",94overflow: "hidden",95}}96>97<div98style={{99maxWidth: MAX_WIDTH,100marginLeft: "auto",101marginRight: "auto",102alignSelf: "center",103flex: 1,104// whiteSpace: "nowrap",105}}106>107{renderInfoBarContent()}108</div>109</Flex>110);111};112113114