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/pages/token.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
Visit
8
9
https://cocalc.com/token?token=vZmCKcIMha2nKyFQ0rgK&type=...
10
11
to carry out the action associated with the token vZmCKcIMha2nKyFQ0rgK.
12
13
Also use https://cocalc.com/token?result=.... as a confirmation URL
14
for payments.
15
16
Note that https://cocalc.com/token?token=vZmCKcIMha2nKyFQ0rgK&type=... is DEPRECATED
17
and replaced by
18
19
https://cocalc.com/token/vZmCKcIMha2nKyFQ0rgK
20
21
which is a cleaner. We're leaving this deprecated endpoint with a redirect
22
for a few weeks to handle any outstanding tokens.
23
*/
24
25
import { Layout } from "antd";
26
import Footer from "components/landing/footer";
27
import Head from "components/landing/head";
28
import Header from "components/landing/header";
29
import { Customize, CustomizeType } from "lib/customize";
30
import withCustomize from "lib/with-customize";
31
import { Alert } from "antd";
32
import { useRouter } from "next/router";
33
import { capitalize } from "@cocalc/util/misc";
34
import { useEffect } from "react";
35
36
const STYLE = { margin: "30px auto", maxWidth: "600px", fontSize: "14pt" };
37
38
interface Props {
39
customize: CustomizeType;
40
}
41
42
export default function TokenActions(props: Props) {
43
const { customize } = props;
44
const router = useRouter();
45
46
useEffect(() => {
47
if (router.query.token) {
48
// redirect due to deprecation
49
router.push(`/token/${router.query.token}`);
50
}
51
}, []);
52
53
return (
54
<Customize value={customize}>
55
<Head title={getTitle(router.query.type)} />
56
<Layout>
57
<Header />
58
{router.query.result != null && (
59
<ShowResult result={router.query.result} />
60
)}
61
<Footer />
62
</Layout>
63
</Customize>
64
);
65
}
66
67
function ShowResult({ result }) {
68
return <Alert showIcon style={STYLE} type="info" message={result} />;
69
}
70
71
export async function getServerSideProps(context) {
72
return await withCustomize({ context });
73
}
74
75
function getTitle(type?: string | string[]) {
76
switch (type) {
77
case "make-payment":
78
return "Make a Payment";
79
case "disable-daily-statements":
80
return "Disable Daily Statements";
81
default:
82
if (typeof type == "string" && type) {
83
return capitalize(type.replace(/-/g, " "));
84
}
85
return "Token Action";
86
}
87
}
88
89