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/congrats.tsx
Views: 687
1
/*
2
Page that you show user after they successfully complete a purchase.
3
4
It queries the backend for "the most recent stuff you bought", thanks
5
you for your purchase, has useful links, etc.
6
7
NOTE: the current implementation is just a really simple one that assumes
8
you are purchasing a license for projects, since that's all we sell
9
right now. This will have to be a bit more sophisticated when there's
10
more products.
11
*/
12
13
import { Icon } from "@cocalc/frontend/components/icon";
14
import { plural } from "@cocalc/util/misc";
15
import { Alert, Card } from "antd";
16
import Image from "components/landing/image";
17
import License from "components/licenses/license";
18
import A from "components/misc/A";
19
import Loading from "components/share/loading";
20
import SiteName from "components/share/site-name";
21
import useAPI from "lib/hooks/api";
22
import bella from "public/shopping/bella.png";
23
import TimeAgo from "timeago-react";
24
25
export default function Congrats() {
26
const purchases = useAPI("/shopping/cart/recent-purchases", {
27
recent: "2 day",
28
});
29
const vouchers = useAPI("/vouchers/recent-vouchers", {
30
recent: "2 day",
31
});
32
33
if (purchases.error) {
34
return <Alert type="error" message={purchases.error} />;
35
}
36
if (vouchers.error) {
37
return <Alert type="error" message={vouchers.error} />;
38
}
39
if (!purchases.result || !vouchers.result) {
40
return <Loading large center />;
41
}
42
43
const billingInfo = (
44
<Alert
45
showIcon
46
style={{ margin: "15px 0" }}
47
type="info"
48
message={
49
<>
50
Browse your <A href="/billing/receipts">invoices, receipts</A> and{" "}
51
<A href="/billing/subscriptions">subscriptions</A> on the{" "}
52
<A href="/billing">billing page</A>, or visit the{" "}
53
<A href="/vouchers">voucher center</A>.
54
</>
55
}
56
/>
57
);
58
59
if (purchases.result.length == 0 && vouchers.result.length == 0) {
60
return <div>You have no recent purchases or vouchers. {billingInfo}</div>;
61
}
62
63
function renderNextSteps(): JSX.Element {
64
return (
65
<>
66
<h2>Here are your next steps</h2>
67
<ul>
68
{purchases.result.length > 0 && (
69
<li style={{ marginBottom: "15px" }}>
70
You are a manager for each of the licenses you purchased.{" "}
71
<A href="/licenses/managed">You can see your managed licenses</A>,
72
add other people as managers, edit the title and description of
73
each license, and see how a license is being used.
74
</li>
75
)}
76
{purchases.result.length > 0 && (
77
<li style={{ marginBottom: "15px" }}>
78
You can{" "}
79
<A href="https://doc.cocalc.com/project-settings.html#project-add-license">
80
apply a license to projects
81
</A>
82
,{" "}
83
<A href="https://doc.cocalc.com/teaching-upgrade-course.html#install-course-license">
84
courses
85
</A>
86
, or directly share the license code, as{" "}
87
<A href="https://doc.cocalc.com/licenses.html">explained here</A>.
88
It's time to make your <SiteName /> projects much, much better.
89
</li>
90
)}
91
{vouchers.result.length > 0 && (
92
<li style={{ marginBottom: "15px" }}>
93
You can{" "}
94
<A href="/vouchers/created">
95
browse all the vouchers you have created
96
</A>
97
, and everything else involving vouchers at the{" "}
98
<A href="/vouchers">vouchers center</A>.
99
</li>
100
)}
101
{purchases.result.length > 0 ? (
102
<li style={{ marginBottom: "15px" }}>
103
You can <A href="/billing/receipts">download your receipt</A> and{" "}
104
<A href="/billing/subscriptions">
105
check on the status of any subscriptions.
106
</A>
107
</li>
108
) : (
109
<li style={{ marginBottom: "15px" }}>
110
You can <A href="/billing/receipts">download your receipt</A>.
111
</li>
112
)}
113
<li style={{ marginBottom: "15px" }}>
114
If you're interested in <A href="/store/vouchers">purchasing</A>,{" "}
115
<A href="/redeem">redeeming</A>, or checking on the{" "}
116
<A href="/vouchers/created">status of your vouchers</A>, visit the{" "}
117
<A href="/vouchers">Voucher Center</A> or the{" "}
118
<A href="https://doc.cocalc.com/vouchers.html">voucher docs</A>.
119
</li>
120
<li>
121
If you have questions,{" "}
122
<A href="/support/new">create a support ticket</A>. Your request
123
will be more highly prioritized.
124
</li>
125
</ul>
126
{billingInfo}
127
</>
128
);
129
}
130
131
function renderAutomaticallyApplied(): JSX.Element {
132
const appliedProjects = purchases.result.filter(
133
(x) => x.project_id != null
134
);
135
const numApplied = appliedProjects.length;
136
if (numApplied == 0) return <></>;
137
return (
138
<>
139
<br />
140
<Alert
141
type="info"
142
message={
143
<>
144
<p>
145
The following {plural(numApplied, "project")} automatically got
146
a license applied:
147
</p>
148
<ul>
149
{appliedProjects.map((x) => (
150
<li key={x.project_id}>
151
Project{" "}
152
<A href={`/projects/${x.project_id}`} external={true}>
153
{x.project_id}
154
</A>{" "}
155
got license <License license_id={x.purchased?.license_id} />
156
.
157
</li>
158
))}
159
</ul>
160
</>
161
}
162
></Alert>
163
</>
164
);
165
}
166
167
return (
168
<>
169
<div style={{ float: "right" }}>
170
<Image src={bella} width={100} height={141} alt="Picture of Bella!" />
171
</div>
172
<div style={{ fontSize: "12pt" }}>
173
<h1 style={{ fontSize: "24pt" }}>
174
<Icon
175
name="check-circle"
176
style={{ color: "darkgreen", marginRight: "10px" }}
177
/>{" "}
178
Order Complete!
179
</h1>
180
{purchases.result.length > 0 && (
181
<Card
182
style={{ margin: "15px auto", maxWidth: "700px" }}
183
title={
184
<>
185
<Icon name="key" style={{ marginRight: "15px" }} />
186
Congrats! You recently ordered{" "}
187
{purchases.result.length >= 2 ? "these" : "this"}{" "}
188
{purchases.result.length} <SiteName />{" "}
189
{plural(purchases.result.length, "license")}
190
</>
191
}
192
>
193
<ul>
194
{purchases.result.map((item) => (
195
<li key={item.purchased.license_id}>
196
<License
197
key={item.purchased.license_id}
198
license_id={item.purchased.license_id}
199
/>
200
, purchased <TimeAgo datetime={item.purchased.time} />
201
</li>
202
))}
203
</ul>
204
{renderAutomaticallyApplied()}
205
</Card>
206
)}
207
{vouchers.result.length > 0 && (
208
<Card
209
title={
210
<>
211
<Icon name="gift2" style={{ marginRight: "15px" }} />
212
Congrats! You recently created {vouchers.result.length}{" "}
213
{plural(vouchers.result.length, "voucher")}.
214
</>
215
}
216
style={{ margin: "15px auto", maxWidth: "700px" }}
217
>
218
You can download the corresponding voucher codes via the{" "}
219
{plural(vouchers.result.length, "link")} below.
220
<br />
221
<br />
222
<ul>
223
{vouchers.result.map((item, n) => (
224
<Voucher key={n} {...item} />
225
))}
226
</ul>
227
</Card>
228
)}
229
<br />
230
{renderNextSteps()}
231
</div>
232
</>
233
);
234
}
235
236
function Voucher({ id, title, count, created }) {
237
return (
238
<li key={id}>
239
<A href={`/vouchers/${id}`}>
240
{title}: {count} voucher codes
241
</A>
242
, created <TimeAgo datetime={created} />
243
</li>
244
);
245
}
246
247