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/frontend/account/settings/email-verification.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Map } from "immutable";6import { FormattedMessage, useIntl } from "react-intl";78import { alert_message } from "@cocalc/frontend/alerts";9import { Button } from "@cocalc/frontend/antd-bootstrap";10import {11Rendered,12useEffect,13useIsMountedRef,14useState,15} from "@cocalc/frontend/app-framework";16import { LabeledRow } from "@cocalc/frontend/components";17import { webapp_client } from "@cocalc/frontend/webapp-client";1819interface Props {20email_address?: string;21email_address_verified?: Map<string, boolean>;22}2324export function EmailVerification({25email_address,26email_address_verified,27}: Props) {28const intl = useIntl();2930const is_mounted = useIsMountedRef();31const [disabled_button, set_disabled_button] = useState(false);3233useEffect(() => {34set_disabled_button(false);35}, [email_address]);3637async function verify(): Promise<void> {38try {39await webapp_client.account_client.send_verification_email();40} catch (err) {41const err_msg = `Problem sending email verification: ${err}`;42console.log(err_msg);43alert_message({ type: "error", message: err_msg });44} finally {45if (is_mounted.current) {46set_disabled_button(true);47}48}49}5051function render_status(): Rendered {52if (email_address == null) {53return (54<span>55<FormattedMessage56id="account.settings.email-verification.unknown"57defaultMessage={"Unknown"}58/>59</span>60);61} else {62if (email_address_verified?.get(email_address)) {63return (64<span style={{ color: "green" }}>65<FormattedMessage66id="account.settings.email-verification.verified"67defaultMessage={"Verified"}68/>69</span>70);71} else {72return (73<>74<span key={1} style={{ color: "red", paddingRight: "3em" }}>75<FormattedMessage76id="account.settings.email-verification.button.label"77defaultMessage={"Not Verified"}78/>79</span>80<Button81onClick={verify}82bsStyle="success"83disabled={disabled_button}84>85<FormattedMessage86id="account.settings.email-verification.button.status"87defaultMessage={`{disabled_button, select, true {Email Sent} other {Send Verification Email}}`}88values={{ disabled_button }}89/>90</Button>91</>92);93}94}95}9697return (98<LabeledRow99label={intl.formatMessage({100id: "account.settings.email-verification.label",101defaultMessage: "Email verification",102})}103style={{ marginBottom: "15px" }}104>105<div>106<FormattedMessage107id="account.settings.email-verification.status"108defaultMessage={"Status: {status}"}109values={{ status: render_status() }}110/>111</div>112</LabeledRow>113);114}115116117