]> Untitled Git - lemmy-ui.git/blob - src/shared/components/person/verify-email.tsx
Merge branch 'LemmyNet:main' into added-darkly-compact-552
[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 { FirstLoadService, 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     FirstLoadService.isFirstLoad;
27   }
28
29   async verify() {
30     this.setState({
31       verifyRes: { state: "loading" },
32     });
33
34     this.setState({
35       verifyRes: await HttpService.client.verifyEmail({
36         token: this.props.match.params.token,
37       }),
38     });
39
40     if (this.state.verifyRes.state == "success") {
41       toast(I18NextService.i18n.t("email_verified"));
42       this.props.history.push("/login");
43     }
44   }
45
46   async componentDidMount() {
47     await this.verify();
48   }
49
50   get documentTitle(): string {
51     return `${I18NextService.i18n.t("verify_email")} - ${
52       this.state.siteRes.site_view.site.name
53     }`;
54   }
55
56   render() {
57     return (
58       <div className="verfy-email container-lg">
59         <HtmlTags
60           title={this.documentTitle}
61           path={this.context.router.route.match.url}
62         />
63         <div className="row">
64           <div className="col-12 col-lg-6 offset-lg-3 mb-4">
65             <h5>{I18NextService.i18n.t("verify_email")}</h5>
66             {this.state.verifyRes.state == "loading" && (
67               <h5>
68                 <Spinner large />
69               </h5>
70             )}
71           </div>
72         </div>
73       </div>
74     );
75   }
76 }