2 editRegistrationApplication,
6 import { RouteDataResponse } from "@utils/types";
7 import { Component, linkEvent } from "inferno";
9 ApproveRegistrationApplication,
11 ListRegistrationApplicationsResponse,
12 RegistrationApplicationView,
13 } from "lemmy-js-client";
14 import { fetchLimit } from "../../config";
15 import { InitialFetchRequest } from "../../interfaces";
16 import { FirstLoadService, I18NextService, UserService } from "../../services";
17 import { HttpService, RequestState } from "../../services/HttpService";
18 import { setupTippy } from "../../tippy";
19 import { HtmlTags } from "../common/html-tags";
20 import { Spinner } from "../common/icon";
21 import { Paginator } from "../common/paginator";
22 import { RegistrationApplication } from "../common/registration-application";
29 type RegistrationApplicationsData = RouteDataResponse<{
30 listRegistrationApplicationsResponse: ListRegistrationApplicationsResponse;
33 interface RegistrationApplicationsState {
34 appsRes: RequestState<ListRegistrationApplicationsResponse>;
35 siteRes: GetSiteResponse;
36 unreadOrAll: UnreadOrAll;
38 isIsomorphic: boolean;
41 export class RegistrationApplications extends Component<
43 RegistrationApplicationsState
45 private isoData = setIsoData<RegistrationApplicationsData>(this.context);
46 state: RegistrationApplicationsState = {
47 appsRes: { state: "empty" },
48 siteRes: this.isoData.site_res,
49 unreadOrAll: UnreadOrAll.Unread,
54 constructor(props: any, context: any) {
55 super(props, context);
57 this.handlePageChange = this.handlePageChange.bind(this);
58 this.handleApproveApplication = this.handleApproveApplication.bind(this);
60 // Only fetch the data if coming from another route
61 if (FirstLoadService.isFirstLoad) {
64 appsRes: this.isoData.routeData.listRegistrationApplicationsResponse,
70 async componentDidMount() {
71 if (!this.state.isIsomorphic) {
77 get documentTitle(): string {
78 const mui = UserService.Instance.myUserInfo;
80 ? `@${mui.local_user_view.person.name} ${I18NextService.i18n.t(
81 "registration_applications"
82 )} - ${this.state.siteRes.site_view.site.name}`
87 switch (this.state.appsRes.state) {
95 const apps = this.state.appsRes.data.registration_applications;
98 <div className="col-12">
100 title={this.documentTitle}
101 path={this.context.router.route.match.url}
103 <h1 className="h4 mb-4">
104 {I18NextService.i18n.t("registration_applications")}
107 {this.applicationList(apps)}
109 page={this.state.page}
110 onChange={this.handlePageChange}
121 <div className="registration-applications container-lg">
127 unreadOrAllRadios() {
129 <div className="btn-group btn-group-toggle flex-wrap mb-2">
131 className={`btn btn-outline-secondary pointer
132 ${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
137 className="btn-check"
138 value={UnreadOrAll.Unread}
139 checked={this.state.unreadOrAll == UnreadOrAll.Unread}
140 onChange={linkEvent(this, this.handleUnreadOrAllChange)}
142 {I18NextService.i18n.t("unread")}
145 className={`btn btn-outline-secondary pointer
146 ${this.state.unreadOrAll == UnreadOrAll.All && "active"}
151 className="btn-check"
152 value={UnreadOrAll.All}
153 checked={this.state.unreadOrAll == UnreadOrAll.All}
154 onChange={linkEvent(this, this.handleUnreadOrAllChange)}
156 {I18NextService.i18n.t("all")}
164 <div className="mb-2">
165 <span className="me-3">{this.unreadOrAllRadios()}</span>
170 applicationList(apps: RegistrationApplicationView[]) {
176 <RegistrationApplication
177 key={ra.registration_application.id}
179 onApproveApplication={this.handleApproveApplication}
187 handleUnreadOrAllChange(i: RegistrationApplications, event: any) {
188 i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
192 handlePageChange(page: number) {
193 this.setState({ page });
197 static async fetchInitialData({
200 }: InitialFetchRequest): Promise<RegistrationApplicationsData> {
202 listRegistrationApplicationsResponse: auth
203 ? await client.listRegistrationApplications({
207 auth: auth as string,
209 : { state: "empty" },
214 const unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
216 appsRes: { state: "loading" },
219 appsRes: await HttpService.client.listRegistrationApplications({
220 unread_only: unread_only,
221 page: this.state.page,
223 auth: myAuthRequired(),
228 async handleApproveApplication(form: ApproveRegistrationApplication) {
229 const approveRes = await HttpService.client.approveRegistrationApplication(
233 if (s.appsRes.state == "success" && approveRes.state == "success") {
234 s.appsRes.data.registration_applications = editRegistrationApplication(
235 approveRes.data.registration_application,
236 s.appsRes.data.registration_applications