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/frontend/admin/users/money.tsx
Views: 687
1
import api from "@cocalc/frontend/client/api";
2
import { useEffect, useState } from "react";
3
import { Spin } from "antd";
4
import { currency, round2 } from "@cocalc/util/misc";
5
import { TimeAgo } from "@cocalc/frontend/components";
6
7
export default function Money({ account_id }) {
8
const [data, setData] = useState<{
9
cocalc_purchase_timestamp: string;
10
cocalc_balance: number;
11
cocalc_last_month_spend: number;
12
cocalc_last_year_spend: number;
13
} | null>(null);
14
15
useEffect(() => {
16
(async () => {
17
setData(await api("salesloft/money", { account_id }));
18
})();
19
}, []);
20
21
if (data == null) {
22
return <Spin />;
23
}
24
25
if (
26
data.cocalc_last_year_spend == 0 &&
27
data.cocalc_last_month_spend == 0 &&
28
data.cocalc_balance == 0
29
) {
30
return <div>Not A Recent Paying Customer</div>;
31
}
32
33
return (
34
<div>
35
Balance: {currency(round2(data.cocalc_balance))}, Last Month Spend:{" "}
36
{currency(round2(data.cocalc_last_month_spend))}, Last Year Spend:{" "}
37
{currency(round2(data.cocalc_last_year_spend))}, Last Daily Statement:{" "}
38
<TimeAgo date={new Date(data.cocalc_purchase_timestamp)} />{" "}
39
</div>
40
);
41
}
42
43