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/auth/redeem-verify-email.tsx
Views: 687
1
import apiPost from "lib/api/post";
2
import { useEffect, useState } from "react";
3
import { Icon } from "@cocalc/frontend/components/icon";
4
import { Alert } from "antd";
5
import Contact from "components/landing/contact";
6
7
import AuthPageContainer from "./fragments/auth-page-container";
8
9
interface Props {
10
token: string;
11
email_address: string;
12
}
13
14
export default function RedeemVerifyEmail({ token, email_address }: Props) {
15
const [redeeming, setRedeeming] = useState<boolean>(false);
16
const [error, setError] = useState<string>("");
17
const [success, setSuccess] = useState<string>("");
18
19
async function redeem(): Promise<void> {
20
setRedeeming(true);
21
setError("");
22
setSuccess("");
23
try {
24
await apiPost("/auth/redeem-verify-email", {
25
email_address,
26
token,
27
});
28
setSuccess("Successfully verified your email address. Thanks!");
29
} catch (err) {
30
setError(`${err}`);
31
} finally {
32
setRedeeming(false);
33
}
34
}
35
36
useEffect(() => {
37
redeem();
38
return;
39
}, []);
40
41
function Body() {
42
if (redeeming) {
43
return (
44
<div>
45
<Icon name="spinner" spin /> Verifying your email address...
46
</div>
47
);
48
}
49
if (error) {
50
return (
51
<div>
52
We weren't able to validate your e-mail address. ):
53
</div>
54
);
55
}
56
return (
57
<div>
58
{success && (
59
<Alert
60
style={{ marginTop: "20px" }}
61
message={<b>Success</b>}
62
description={<div style={{ fontSize: "12pt" }}>{success}</div>}
63
type="success"
64
showIcon
65
/>
66
)}
67
</div>
68
);
69
}
70
71
function renderError() {
72
return error && (
73
<div style={{ fontSize: "12pt" }}>
74
<b>{error}</b>
75
<br/>
76
If you are stuck, please <Contact lower/>.
77
</div>
78
);
79
}
80
81
function renderTitle() {
82
return `${success ? "Successfully " : ""}Verif${success ? "ied" : "y"} Your Email Address`;
83
}
84
85
return (
86
<AuthPageContainer
87
error={renderError()}
88
title={renderTitle()}
89
>
90
<div style={{ marginTop: "8px" }}>
91
<Body/>
92
</div>
93
</AuthPageContainer>
94
);
95
}
96
97