Path: blob/master/src/packages/next/components/store/congrats.tsx
1450 views
/*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";2324import type { JSX } from "react";2526export default function Congrats() {27const purchases = useAPI("/shopping/cart/recent-purchases", {28recent: "2 day",29});30const vouchers = useAPI("/vouchers/recent-vouchers", {31recent: "2 day",32});3334if (purchases.error) {35return <Alert type="error" message={purchases.error} />;36}37if (vouchers.error) {38return <Alert type="error" message={vouchers.error} />;39}40if (!purchases.result || !vouchers.result) {41return <Loading large center />;42}4344const billingInfo = (45<Alert46showIcon47style={{ margin: "15px 0" }}48type="info"49message={50<>51Browse your <A href="/settings/payments">invoices</A>,{" "}52<A href="/settings/purchases">receipts</A> and{" "}53<A href="/settings/subscriptions">subscriptions</A>, or visit the{" "}54<A href="/vouchers">voucher center</A>.55</>56}57/>58);5960if (purchases.result.length == 0 && vouchers.result.length == 0) {61return <div>You have no recent purchases or vouchers. {billingInfo}</div>;62}6364function renderNextSteps(): JSX.Element {65return (66<>67<h2>Here are your next steps</h2>68<ul>69{purchases.result.length > 0 && (70<li style={{ marginBottom: "15px" }}>71<b>Licenses:</b> You are a manager for each of the licenses you72purchased.{" "}73<A href="/settings/licenses">You manage your licenses</A>, add74other people as managers, edit the title, description and every75property of each license, and{" "}76<A href="/licenses/how-used">see how a license is being used</A>.77<ul>78<li style={{ marginBottom: "15px" }}>79You can{" "}80<A href="https://doc.cocalc.com/project-settings.html#project-add-license">81apply a license to projects82</A>83,{" "}84<A href="https://doc.cocalc.com/teaching-upgrade-course.html#install-course-license">85courses86</A>87, or directly share the license code, as{" "}88<A href="https://doc.cocalc.com/licenses.html">89explained here90</A>91. It's time to make your <SiteName /> projects much, much92better.93</li>94</ul>95</li>96)}97{vouchers.result.length > 0 && (98<li style={{ marginBottom: "15px" }}>99<b>Vouchers:</b> You can{" "}100<A href="/vouchers/created">101browse all the vouchers you have created102</A>103, and everything else involving vouchers at the{" "}104<A href="/vouchers">vouchers center</A>.105<ul>106<li style={{ marginBottom: "15px" }}>107If you're interested in{" "}108<A href="/store/vouchers">purchasing</A>,{" "}109<A href="/redeem">redeeming</A>, or checking on the{" "}110<A href="/vouchers/created">status of your vouchers</A>, visit111the <A href="/vouchers">Voucher Center</A> or the{" "}112<A href="https://doc.cocalc.com/vouchers.html">113voucher docs114</A>115.116</li>117</ul>118</li>119)}120{purchases.result.length > 0 ? (121<li style={{ marginBottom: "15px" }}>122<b>Payments:</b> You can{" "}123<A href="/settings/purchases">download your receipt</A> and{" "}124<A href="/settings/subscriptions">125check on the status of any subscriptions.126</A>127</li>128) : (129<li style={{ marginBottom: "15px" }}>130<b>Payments:</b> You can{" "}131<A href="/settings/purchases">download your receipt</A>.132</li>133)}134<li>135<b>Support:</b> If you have questions,{" "}136<A href="/support/new">create a support ticket</A>.137</li>138</ul>139{billingInfo}140</>141);142}143144function renderAutomaticallyApplied(): JSX.Element {145const appliedProjects = purchases.result.filter(146(x) => x.project_id != null,147);148const numApplied = appliedProjects.length;149if (numApplied == 0) return <></>;150return (151<>152<br />153<Alert154type="info"155message={156<>157<p>158The following {plural(numApplied, "project")} automatically got159a license applied:160</p>161<ul>162{appliedProjects.map((x) => (163<li key={x.project_id}>164Project{" "}165<A href={`/projects/${x.project_id}`} external={true}>166{x.project_id}167</A>{" "}168got license <License license_id={x.purchased?.license_id} />169.170</li>171))}172</ul>173</>174}175></Alert>176</>177);178}179180const licenses = purchases.result.filter((x) => x.purchased.license_id);181182return (183<>184<div style={{ float: "right" }}>185<Image src={bella} width={100} height={141} alt="Picture of Bella!" />186</div>187<div style={{ fontSize: "12pt" }}>188<h1 style={{ fontSize: "24pt" }}>189<Icon190name="check-circle"191style={{ color: "darkgreen", marginRight: "10px" }}192/>{" "}193Order Complete!194</h1>195{licenses.length > 0 && (196<Card197style={{ margin: "15px auto", maxWidth: "700px" }}198title={199<>200<Icon name="key" style={{ marginRight: "15px" }} />201Congrats! You recently ordered{" "}202{licenses.length >= 2 ? "these" : "this"} {licenses.length}{" "}203<SiteName /> {plural(licenses.length, "license")}.204</>205}206>207<ul>208{licenses.map((item) => (209<li key={item.purchased.license_id}>210<License211key={item.purchased.license_id}212license_id={item.purchased.license_id}213/>214, purchased <TimeAgo datetime={item.purchased.time} />215</li>216))}217</ul>218{renderAutomaticallyApplied()}219</Card>220)}221{vouchers.result.length > 0 && (222<Card223title={224<>225<Icon name="gift2" style={{ marginRight: "15px" }} />226Congrats! You recently created {vouchers.result.length}{" "}227{plural(vouchers.result.length, "voucher")}.228</>229}230style={{ margin: "15px auto", maxWidth: "700px" }}231>232You can download and track your voucher codes via the{" "}233{plural(vouchers.result.length, "link")} below.234<br />235<br />236<ul>237{vouchers.result.map((item, n) => (238<Voucher key={n} {...item} />239))}240</ul>241</Card>242)}243<br />244{renderNextSteps()}245</div>246</>247);248}249250function Voucher({ id, title, count, created }) {251return (252<li key={id}>253<A href={`/vouchers/${id}`}>254{title}: {count} voucher codes255</A>256, created <TimeAgo datetime={created} />257</li>258);259}260261262