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/pages/token.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Visit78https://cocalc.com/token?token=vZmCKcIMha2nKyFQ0rgK&type=...910to carry out the action associated with the token vZmCKcIMha2nKyFQ0rgK.1112Also use https://cocalc.com/token?result=.... as a confirmation URL13for payments.1415Note that https://cocalc.com/token?token=vZmCKcIMha2nKyFQ0rgK&type=... is DEPRECATED16and replaced by1718https://cocalc.com/token/vZmCKcIMha2nKyFQ0rgK1920which is a cleaner. We're leaving this deprecated endpoint with a redirect21for a few weeks to handle any outstanding tokens.22*/2324import { Layout } from "antd";25import Footer from "components/landing/footer";26import Head from "components/landing/head";27import Header from "components/landing/header";28import { Customize, CustomizeType } from "lib/customize";29import withCustomize from "lib/with-customize";30import { Alert } from "antd";31import { useRouter } from "next/router";32import { capitalize } from "@cocalc/util/misc";33import { useEffect } from "react";3435const STYLE = { margin: "30px auto", maxWidth: "600px", fontSize: "14pt" };3637interface Props {38customize: CustomizeType;39}4041export default function TokenActions(props: Props) {42const { customize } = props;43const router = useRouter();4445useEffect(() => {46if (router.query.token) {47// redirect due to deprecation48router.push(`/token/${router.query.token}`);49}50}, []);5152return (53<Customize value={customize}>54<Head title={getTitle(router.query.type)} />55<Layout>56<Header />57{router.query.result != null && (58<ShowResult result={router.query.result} />59)}60<Footer />61</Layout>62</Customize>63);64}6566function ShowResult({ result }) {67return <Alert showIcon style={STYLE} type="info" message={result} />;68}6970export async function getServerSideProps(context) {71return await withCustomize({ context });72}7374function getTitle(type?: string | string[]) {75switch (type) {76case "make-payment":77return "Make a Payment";78case "disable-daily-statements":79return "Disable Daily Statements";80default:81if (typeof type == "string" && type) {82return capitalize(type.replace(/-/g, " "));83}84return "Token Action";85}86}878889