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/invoices-and-receipts.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert, Table } from "antd";67import { Icon } from "@cocalc/frontend/components/icon";8import { cmp, stripeAmount } from "@cocalc/util/misc";9import License from "components/licenses/license";10import { Paragraph, Title } from "components/misc";11import A from "components/misc/A";12import Timestamp from "components/misc/timestamp";13import Loading from "components/share/loading";14import useAPI from "lib/hooks/api";1516function Description({ hosted_invoice_url, lines, metadata }) {17const license_id =18metadata?.license_id ?? lines.data[0]?.metadata?.license_id;19return (20<div style={{ wordWrap: "break-word", wordBreak: "break-word" }}>21{lines.data[0]?.description}22{(lines?.total_count ?? 1) > 1 && ", etc."}23{hosted_invoice_url && (24<div>25<A href={hosted_invoice_url}>26<Icon name="external-link" /> Invoice/Receipt27</A>28</div>29)}30{license_id && (31<div>32License: <License license_id={license_id} />33</div>34)}35</div>36);37}3839function Status({ status, due_date, hosted_invoice_url }) {40if (status == "paid") {41return <>Paid</>;42}43return (44<A style={{ color: "red" }} href={hosted_invoice_url}>45<Icon name="external-link" /> Due{" "}46<Timestamp epoch={1000 * due_date} dateOnly />47</A>48);49}5051function Created({ created }) {52return <Timestamp epoch={1000 * created} dateOnly />;53}5455function Amount({ total, currency }) {56return <>{stripeAmount(total, currency)}</>;57}5859const columns = [60{61responsive: ["xs"],62title: "Invoices and Receipts",63render: (_, invoice) => (64<div>65<Description {...invoice} />66Created: <Created {...invoice} />67<br />68<Amount {...invoice} />69<br />70<Status {...invoice} />71</div>72),73},74{75responsive: ["sm"],76title: "Description",77width: "50%",78render: (_, invoice) => <Description {...invoice} />,79},80{81responsive: ["sm"],82title: "Status",83align: "center" as "center",84render: (_, invoice) => <Status {...invoice} />,85sorter: { compare: (a, b) => cmp(a.status, b.status) },86},87{88responsive: ["sm"],89title: "Created",90align: "center" as "center",91render: (_, invoice) => <Created {...invoice} />,92sorter: { compare: (a, b) => -cmp(a.created, b.created) },93},94{95responsive: ["sm"],96title: "Amount",97align: "right",98render: (_, invoice) => <Amount {...invoice} />,99sorter: { compare: (a, b) => cmp(a.amount_paid ?? 0, b.amount_paid ?? 0) },100},101];102103export default function InvoicesAndReceipts() {104const { result, error } = useAPI("billing/get-invoices-and-receipts");105if (error) {106return <Alert type="error" message={error} />;107}108if (!result) {109return <Loading />;110}111return (112<div>113<Title level={2}>Invoices and Receipts</Title>114<Paragraph style={{ marginBottom: "30px" }}>115Your recent invoices and receipts are listed below. Click on the116"Invoice" link to get a printable invoice or receipt version.117</Paragraph>118<Table119columns={columns as any}120dataSource={result.data ?? []}121rowKey={"id"}122style={{ marginTop: "15px" }}123pagination={{ hideOnSinglePage: true, pageSize: 100 }}124/>125</div>126);127}128129130