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