1 import { Component, linkEvent } from "inferno";
3 ApproveRegistrationApplication,
5 ListRegistrationApplications,
6 ListRegistrationApplicationsResponse,
7 RegistrationApplicationView,
8 } from "lemmy-js-client";
9 import { i18n } from "../../i18next";
10 import { InitialFetchRequest } from "../../interfaces";
11 import { UserService } from "../../services";
12 import { FirstLoadService } from "../../services/FirstLoadService";
13 import { HttpService, RequestState } from "../../services/HttpService";
15 editRegistrationApplication,
21 import { HtmlTags } from "../common/html-tags";
22 import { Spinner } from "../common/icon";
23 import { Paginator } from "../common/paginator";
24 import { RegistrationApplication } from "../common/registration-application";
31 interface RegistrationApplicationsState {
32 appsRes: RequestState<ListRegistrationApplicationsResponse>;
33 siteRes: GetSiteResponse;
34 unreadOrAll: UnreadOrAll;
36 isIsomorphic: boolean;
39 export class RegistrationApplications extends Component<
41 RegistrationApplicationsState
43 private isoData = setIsoData(this.context);
44 state: RegistrationApplicationsState = {
45 appsRes: { state: "empty" },
46 siteRes: this.isoData.site_res,
47 unreadOrAll: UnreadOrAll.Unread,
52 constructor(props: any, context: any) {
53 super(props, context);
55 this.handlePageChange = this.handlePageChange.bind(this);
56 this.handleApproveApplication = this.handleApproveApplication.bind(this);
58 // Only fetch the data if coming from another route
59 if (FirstLoadService.isFirstLoad) {
62 appsRes: this.isoData.routeData[0],
68 async componentDidMount() {
69 if (!this.state.isIsomorphic) {
75 get documentTitle(): string {
76 const mui = UserService.Instance.myUserInfo;
78 ? `@${mui.local_user_view.person.name} ${i18n.t(
79 "registration_applications"
80 )} - ${this.state.siteRes.site_view.site.name}`
85 switch (this.state.appsRes.state) {
93 const apps = this.state.appsRes.data.registration_applications;
96 <div className="col-12">
98 title={this.documentTitle}
99 path={this.context.router.route.match.url}
101 <h5 className="mb-2">{i18n.t("registration_applications")}</h5>
103 {this.applicationList(apps)}
105 page={this.state.page}
106 onChange={this.handlePageChange}
116 return <div className="container-lg">{this.renderApps()}</div>;
119 unreadOrAllRadios() {
121 <div className="btn-group btn-group-toggle flex-wrap mb-2">
123 className={`btn btn-outline-secondary pointer
124 ${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
129 value={UnreadOrAll.Unread}
130 checked={this.state.unreadOrAll == UnreadOrAll.Unread}
131 onChange={linkEvent(this, this.handleUnreadOrAllChange)}
136 className={`btn btn-outline-secondary pointer
137 ${this.state.unreadOrAll == UnreadOrAll.All && "active"}
142 value={UnreadOrAll.All}
143 checked={this.state.unreadOrAll == UnreadOrAll.All}
144 onChange={linkEvent(this, this.handleUnreadOrAllChange)}
154 <div className="mb-2">
155 <span className="mr-3">{this.unreadOrAllRadios()}</span>
160 applicationList(apps: RegistrationApplicationView[]) {
166 <RegistrationApplication
167 key={ra.registration_application.id}
169 onApproveApplication={this.handleApproveApplication}
177 handleUnreadOrAllChange(i: RegistrationApplications, event: any) {
178 i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
182 handlePageChange(page: number) {
183 this.setState({ page });
187 static fetchInitialData({
190 }: InitialFetchRequest): Promise<any>[] {
191 const promises: Promise<RequestState<any>>[] = [];
194 const form: ListRegistrationApplications = {
200 promises.push(client.listRegistrationApplications(form));
202 promises.push(Promise.resolve({ state: "empty" }));
209 const unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
211 appsRes: { state: "loading" },
214 appsRes: await HttpService.client.listRegistrationApplications({
215 unread_only: unread_only,
216 page: this.state.page,
218 auth: myAuthRequired(),
223 async handleApproveApplication(form: ApproveRegistrationApplication) {
224 const approveRes = await HttpService.client.approveRegistrationApplication(
228 if (s.appsRes.state == "success" && approveRes.state == "success") {
229 s.appsRes.data.registration_applications = editRegistrationApplication(
230 approveRes.data.registration_application,
231 s.appsRes.data.registration_applications