1 import { None } from "@sniptt/monads/build";
2 import { Component } from "inferno";
6 VerifyEmail as VerifyEmailForm,
10 } from "lemmy-js-client";
11 import { Subscription } from "rxjs";
12 import { i18n } from "../../i18next";
13 import { WebSocketService } from "../../services";
21 import { HtmlTags } from "../common/html-tags";
24 verifyEmailForm: VerifyEmailForm;
25 siteRes: GetSiteResponse;
28 export class VerifyEmail extends Component<any, State> {
29 private isoData = setIsoData(this.context);
30 private subscription: Subscription;
33 verifyEmailForm: new VerifyEmailForm({
34 token: this.props.match.params.token,
36 siteRes: this.isoData.site_res,
39 constructor(props: any, context: any) {
40 super(props, context);
42 this.state = this.emptyState;
44 this.parseMessage = this.parseMessage.bind(this);
45 this.subscription = wsSubscribe(this.parseMessage);
49 WebSocketService.Instance.send(
50 wsClient.verifyEmail(this.state.verifyEmailForm)
54 componentWillUnmount() {
56 this.subscription.unsubscribe();
60 get documentTitle(): string {
61 return this.state.siteRes.site_view.match({
62 some: siteView => `${i18n.t("verify_email")} - ${siteView.site.name}`,
69 <div class="container">
71 title={this.documentTitle}
72 path={this.context.router.route.match.url}
77 <div class="col-12 col-lg-6 offset-lg-3 mb-4">
78 <h5>{i18n.t("verify_email")}</h5>
85 parseMessage(msg: any) {
86 let op = wsUserOp(msg);
89 toast(i18n.t(msg.error), "danger");
90 this.setState(this.state);
91 this.props.history.push("/");
93 } else if (op == UserOperation.VerifyEmail) {
94 let data = wsJsonToRes<VerifyEmailResponse>(msg, VerifyEmailResponse);
96 toast(i18n.t("email_verified"));
97 this.state = this.emptyState;
98 this.setState(this.state);
99 this.props.history.push("/login");