2021-12-30 15:26:45 +00:00
|
|
|
import { Component } from "inferno";
|
2023-06-14 12:20:40 +00:00
|
|
|
import { GetSiteResponse, VerifyEmailResponse } from "lemmy-js-client";
|
2021-12-30 15:26:45 +00:00
|
|
|
import { i18n } from "../../i18next";
|
2023-06-14 12:20:40 +00:00
|
|
|
import { HttpService, RequestState } from "../../services/HttpService";
|
|
|
|
import { setIsoData, toast } from "../../utils";
|
2021-12-30 15:26:45 +00:00
|
|
|
import { HtmlTags } from "../common/html-tags";
|
2023-06-14 12:20:40 +00:00
|
|
|
import { Spinner } from "../common/icon";
|
2021-12-30 15:26:45 +00:00
|
|
|
|
|
|
|
interface State {
|
2023-06-14 12:20:40 +00:00
|
|
|
verifyRes: RequestState<VerifyEmailResponse>;
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class VerifyEmail extends Component<any, State> {
|
|
|
|
private isoData = setIsoData(this.context);
|
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
state: State = {
|
2023-06-14 12:20:40 +00:00
|
|
|
verifyRes: { state: "empty" },
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2021-12-30 15:26:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async verify() {
|
|
|
|
this.setState({
|
|
|
|
verifyRes: { state: "loading" },
|
|
|
|
});
|
2021-12-30 15:26:45 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
this.setState({
|
|
|
|
verifyRes: await HttpService.client.verifyEmail({
|
|
|
|
token: this.props.match.params.token,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.state.verifyRes.state == "success") {
|
|
|
|
toast(i18n.t("email_verified"));
|
|
|
|
this.props.history.push("/login");
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async componentDidMount() {
|
|
|
|
await this.verify();
|
|
|
|
}
|
|
|
|
|
2021-12-30 15:26:45 +00:00
|
|
|
get documentTitle(): string {
|
2022-11-09 19:53:07 +00:00
|
|
|
return `${i18n.t("verify_email")} - ${
|
|
|
|
this.state.siteRes.site_view.site.name
|
|
|
|
}`;
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2023-06-20 18:46:16 +00:00
|
|
|
<div className="verfy-email container-lg">
|
2021-12-30 15:26:45 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12 col-lg-6 offset-lg-3 mb-4">
|
2021-12-30 15:26:45 +00:00
|
|
|
<h5>{i18n.t("verify_email")}</h5>
|
2023-06-14 12:20:40 +00:00
|
|
|
{this.state.verifyRes.state == "loading" && (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
)}
|
2021-12-30 15:26:45 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|