]> Untitled Git - lemmy-ui.git/blob - src/shared/components/person/verify-email.tsx
fix: Fix heading levels
[lemmy-ui.git] / src / shared / components / person / verify-email.tsx
1 import { setIsoData } from "@utils/app";
2 import { Component } from "inferno";
3 import { GetSiteResponse, VerifyEmailResponse } from "lemmy-js-client";
4 import { I18NextService } from "../../services";
5 import { HttpService, RequestState } from "../../services/HttpService";
6 import { toast } from "../../toast";
7 import { HtmlTags } from "../common/html-tags";
8 import { Spinner } from "../common/icon";
9
10 interface State {
11   verifyRes: RequestState<VerifyEmailResponse>;
12   siteRes: GetSiteResponse;
13 }
14
15 export class VerifyEmail extends Component<any, State> {
16   private isoData = setIsoData(this.context);
17
18   state: State = {
19     verifyRes: { state: "empty" },
20     siteRes: this.isoData.site_res,
21   };
22
23   constructor(props: any, context: any) {
24     super(props, context);
25   }
26
27   async verify() {
28     this.setState({
29       verifyRes: { state: "loading" },
30     });
31
32     this.setState({
33       verifyRes: await HttpService.client.verifyEmail({
34         token: this.props.match.params.token,
35       }),
36     });
37
38     if (this.state.verifyRes.state == "success") {
39       toast(I18NextService.i18n.t("email_verified"));
40       this.props.history.push("/login");
41     }
42   }
43
44   async componentDidMount() {
45     await this.verify();
46   }
47
48   get documentTitle(): string {
49     return `${I18NextService.i18n.t("verify_email")} - ${
50       this.state.siteRes.site_view.site.name
51     }`;
52   }
53
54   render() {
55     return (
56       <div className="verfy-email container-lg">
57         <HtmlTags
58           title={this.documentTitle}
59           path={this.context.router.route.match.url}
60         />
61         <div className="row">
62           <div className="col-12 col-lg-6 offset-lg-3 mb-4">
63             <h1 className="h4 mb-4">{I18NextService.i18n.t("verify_email")}</h1>
64             {this.state.verifyRes.state == "loading" && (
65               <h5>
66                 <Spinner large />
67               </h5>
68             )}
69           </div>
70         </div>
71       </div>
72     );
73   }
74 }