1 import { Component, linkEvent } from "inferno";
2 import { T } from "inferno-i18next-dess";
4 ApproveRegistrationApplication,
5 RegistrationApplicationView,
6 } from "lemmy-js-client";
7 import { i18n } from "../../i18next";
8 import { WebSocketService } from "../../services";
9 import { authField, mdToHtml, wsClient } from "../../utils";
10 import { PersonListing } from "../person/person-listing";
11 import { MarkdownTextArea } from "./markdown-textarea";
12 import { MomentTime } from "./moment-time";
14 interface RegistrationApplicationProps {
15 application: RegistrationApplicationView;
18 interface RegistrationApplicationState {
20 denyExpanded: boolean;
23 export class RegistrationApplication extends Component<
24 RegistrationApplicationProps,
25 RegistrationApplicationState
27 private emptyState: RegistrationApplicationState = {
28 denyReason: this.props.application.registration_application.deny_reason,
32 constructor(props: any, context: any) {
33 super(props, context);
35 this.state = this.emptyState;
36 this.handleDenyReasonChange = this.handleDenyReasonChange.bind(this);
40 let a = this.props.application;
41 let ra = this.props.application.registration_application;
42 let accepted = a.creator_local_user.accepted_application;
47 {i18n.t("applicant")}: <PersonListing person={a.creator} />
50 {i18n.t("created")}: <MomentTime showAgo data={ra} />
52 <div>{i18n.t("answer")}:</div>
53 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(ra.answer)} />
58 <T i18nKey="approved_by">
60 <PersonListing person={a.admin} />
64 <T i18nKey="denied_by">
66 <PersonListing person={a.admin} />
69 {i18n.t("deny_reason")}:{" "}
71 className="md-div d-inline-flex"
72 dangerouslySetInnerHTML={mdToHtml(ra.deny_reason || "")}
80 {this.state.denyExpanded && (
81 <div class="form-group row">
82 <label class="col-sm-2 col-form-label">
83 {i18n.t("deny_reason")}
85 <div class="col-sm-10">
87 initialContent={this.state.denyReason}
88 onContentChange={this.handleDenyReasonChange}
89 hideNavigationWarnings
94 {(!ra.admin_id || (ra.admin_id && !accepted)) && (
96 className="btn btn-secondary mr-2 my-2"
97 onClick={linkEvent(this, this.handleApprove)}
98 aria-label={i18n.t("approve")}
103 {(!ra.admin_id || (ra.admin_id && accepted)) && (
105 className="btn btn-secondary mr-2"
106 onClick={linkEvent(this, this.handleDeny)}
107 aria-label={i18n.t("deny")}
116 handleApprove(i: RegistrationApplication) {
117 i.setState({ denyExpanded: false });
118 let form: ApproveRegistrationApplication = {
119 id: i.props.application.registration_application.id,
124 WebSocketService.Instance.send(
125 wsClient.approveRegistrationApplication(form)
129 handleDeny(i: RegistrationApplication) {
130 if (i.state.denyExpanded) {
131 i.setState({ denyExpanded: false });
132 let form: ApproveRegistrationApplication = {
133 id: i.props.application.registration_application.id,
135 deny_reason: i.state.denyReason,
138 WebSocketService.Instance.send(
139 wsClient.approveRegistrationApplication(form)
142 i.setState({ denyExpanded: true });
146 handleDenyReasonChange(val: string) {
147 this.state.denyReason = val;
148 this.setState(this.state);