2021-12-30 15:26:45 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
|
|
|
import {
|
2022-06-21 21:42:29 +00:00
|
|
|
GetSiteResponse,
|
2021-12-30 15:26:45 +00:00
|
|
|
ListRegistrationApplications,
|
|
|
|
ListRegistrationApplicationsResponse,
|
|
|
|
RegistrationApplicationResponse,
|
|
|
|
UserOperation,
|
2022-06-21 21:42:29 +00:00
|
|
|
wsJsonToRes,
|
|
|
|
wsUserOp,
|
2021-12-30 15:26:45 +00:00
|
|
|
} from "lemmy-js-client";
|
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { InitialFetchRequest } from "../../interfaces";
|
|
|
|
import { UserService, WebSocketService } from "../../services";
|
|
|
|
import {
|
2023-05-30 00:40:00 +00:00
|
|
|
WithPromiseKeys,
|
2021-12-30 15:26:45 +00:00
|
|
|
fetchLimit,
|
|
|
|
isBrowser,
|
2023-01-04 16:56:24 +00:00
|
|
|
myAuth,
|
2021-12-30 15:26:45 +00:00
|
|
|
setIsoData,
|
|
|
|
setupTippy,
|
|
|
|
toast,
|
|
|
|
updateRegistrationApplicationRes,
|
|
|
|
wsClient,
|
|
|
|
wsSubscribe,
|
|
|
|
} from "../../utils";
|
|
|
|
import { HtmlTags } from "../common/html-tags";
|
|
|
|
import { Spinner } from "../common/icon";
|
|
|
|
import { Paginator } from "../common/paginator";
|
|
|
|
import { RegistrationApplication } from "../common/registration-application";
|
|
|
|
|
|
|
|
enum UnreadOrAll {
|
|
|
|
Unread,
|
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
interface RegistrationApplicationsData {
|
|
|
|
listRegistrationApplicationsResponse: ListRegistrationApplicationsResponse;
|
|
|
|
}
|
|
|
|
|
2021-12-30 15:26:45 +00:00
|
|
|
interface RegistrationApplicationsState {
|
2023-01-04 16:56:24 +00:00
|
|
|
listRegistrationApplicationsResponse?: ListRegistrationApplicationsResponse;
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2021-12-30 15:26:45 +00:00
|
|
|
unreadOrAll: UnreadOrAll;
|
2023-05-15 19:53:29 +00:00
|
|
|
page: number;
|
2021-12-30 15:26:45 +00:00
|
|
|
loading: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class RegistrationApplications extends Component<
|
|
|
|
any,
|
|
|
|
RegistrationApplicationsState
|
|
|
|
> {
|
2023-05-30 00:40:00 +00:00
|
|
|
private isoData = setIsoData<RegistrationApplicationsData>(this.context);
|
2023-01-04 16:56:24 +00:00
|
|
|
private subscription?: Subscription;
|
|
|
|
state: RegistrationApplicationsState = {
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2021-12-30 15:26:45 +00:00
|
|
|
unreadOrAll: UnreadOrAll.Unread,
|
2023-05-15 19:53:29 +00:00
|
|
|
page: 1,
|
2021-12-30 15:26:45 +00:00
|
|
|
loading: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
|
|
|
|
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
|
|
|
|
|
|
|
// Only fetch the data if coming from another route
|
2023-05-30 00:40:00 +00:00
|
|
|
if (this.isoData.path === this.context.router.route.match.url) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2023-05-30 00:40:00 +00:00
|
|
|
listRegistrationApplicationsResponse:
|
|
|
|
this.isoData.routeData.listRegistrationApplicationsResponse,
|
2022-09-22 15:03:35 +00:00
|
|
|
loading: false,
|
|
|
|
};
|
2021-12-30 15:26:45 +00:00
|
|
|
} else {
|
|
|
|
this.refetch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (isBrowser()) {
|
2023-01-04 16:56:24 +00:00
|
|
|
this.subscription?.unsubscribe();
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2023-01-04 16:56:24 +00:00
|
|
|
let mui = UserService.Instance.myUserInfo;
|
|
|
|
return mui
|
|
|
|
? `@${mui.local_user_view.person.name} ${i18n.t(
|
2022-11-09 19:53:07 +00:00
|
|
|
"registration_applications"
|
2023-01-04 16:56:24 +00:00
|
|
|
)} - ${this.state.siteRes.site_view.site.name}`
|
|
|
|
: "";
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2022-10-03 18:16:36 +00:00
|
|
|
<div className="container-lg">
|
2021-12-30 15:26:45 +00:00
|
|
|
{this.state.loading ? (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
) : (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12">
|
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
|
|
|
<h5 className="mb-2">{i18n.t("registration_applications")}</h5>
|
2021-12-30 15:26:45 +00:00
|
|
|
{this.selects()}
|
|
|
|
{this.applicationList()}
|
|
|
|
<Paginator
|
|
|
|
page={this.state.page}
|
|
|
|
onChange={this.handlePageChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
unreadOrAllRadios() {
|
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="btn-group btn-group-toggle flex-wrap mb-2">
|
2021-12-30 15:26:45 +00:00
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UnreadOrAll.Unread}
|
|
|
|
checked={this.state.unreadOrAll == UnreadOrAll.Unread}
|
|
|
|
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("unread")}
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.unreadOrAll == UnreadOrAll.All && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UnreadOrAll.All}
|
|
|
|
checked={this.state.unreadOrAll == UnreadOrAll.All}
|
|
|
|
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("all")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
selects() {
|
|
|
|
return (
|
|
|
|
<div className="mb-2">
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="mr-3">{this.unreadOrAllRadios()}</span>
|
2021-12-30 15:26:45 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
applicationList() {
|
2023-01-04 16:56:24 +00:00
|
|
|
let res = this.state.listRegistrationApplicationsResponse;
|
|
|
|
return (
|
|
|
|
res && (
|
2022-06-21 21:42:29 +00:00
|
|
|
<div>
|
|
|
|
{res.registration_applications.map(ra => (
|
|
|
|
<>
|
|
|
|
<hr />
|
|
|
|
<RegistrationApplication
|
|
|
|
key={ra.registration_application.id}
|
|
|
|
application={ra}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-01-04 16:56:24 +00:00
|
|
|
)
|
|
|
|
);
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleUnreadOrAllChange(i: RegistrationApplications, event: any) {
|
2023-05-15 19:53:29 +00:00
|
|
|
i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
|
2021-12-30 15:26:45 +00:00
|
|
|
i.refetch();
|
|
|
|
}
|
|
|
|
|
2023-05-15 19:53:29 +00:00
|
|
|
handlePageChange(page: number) {
|
2021-12-30 15:26:45 +00:00
|
|
|
this.setState({ page });
|
|
|
|
this.refetch();
|
|
|
|
}
|
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
static fetchInitialData({
|
|
|
|
auth,
|
|
|
|
client,
|
|
|
|
}: InitialFetchRequest): WithPromiseKeys<RegistrationApplicationsData> {
|
|
|
|
const form: ListRegistrationApplications = {
|
|
|
|
unread_only: true,
|
|
|
|
page: 1,
|
|
|
|
limit: fetchLimit,
|
|
|
|
auth: auth as string,
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
listRegistrationApplicationsResponse:
|
|
|
|
client.listRegistrationApplications(form),
|
|
|
|
};
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refetch() {
|
|
|
|
let unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let form: ListRegistrationApplications = {
|
|
|
|
unread_only: unread_only,
|
|
|
|
page: this.state.page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.listRegistrationApplications(form)
|
|
|
|
);
|
|
|
|
}
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parseMessage(msg: any) {
|
|
|
|
let op = wsUserOp(msg);
|
|
|
|
console.log(msg);
|
|
|
|
if (msg.error) {
|
|
|
|
toast(i18n.t(msg.error), "danger");
|
|
|
|
return;
|
|
|
|
} else if (msg.reconnect) {
|
|
|
|
this.refetch();
|
|
|
|
} else if (op == UserOperation.ListRegistrationApplications) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<ListRegistrationApplicationsResponse>(msg);
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
2023-01-04 16:56:24 +00:00
|
|
|
listRegistrationApplicationsResponse: data,
|
2022-09-22 15:03:35 +00:00
|
|
|
loading: false,
|
|
|
|
});
|
2021-12-30 15:26:45 +00:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
} else if (op == UserOperation.ApproveRegistrationApplication) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<RegistrationApplicationResponse>(msg);
|
2021-12-30 15:26:45 +00:00
|
|
|
updateRegistrationApplicationRes(
|
|
|
|
data.registration_application,
|
2022-06-21 21:42:29 +00:00
|
|
|
this.state.listRegistrationApplicationsResponse
|
2023-01-04 16:56:24 +00:00
|
|
|
?.registration_applications
|
2021-12-30 15:26:45 +00:00
|
|
|
);
|
|
|
|
let uacs = UserService.Instance.unreadApplicationCountSub;
|
|
|
|
// Minor bug, where if the application switches from deny to approve, the count will still go down
|
2023-05-15 19:53:29 +00:00
|
|
|
uacs.next(uacs.getValue() - 1);
|
2021-12-30 15:26:45 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|