1 import { myAuthRequired } from "@utils/app";
2 import { Component, InfernoNode, linkEvent } from "inferno";
3 import { T } from "inferno-i18next-dess";
5 ApproveRegistrationApplication,
6 RegistrationApplicationView,
7 } from "lemmy-js-client";
8 import { i18n } from "../../i18next";
9 import { mdToHtml } from "../../markdown";
10 import { PersonListing } from "../person/person-listing";
11 import { Spinner } from "./icon";
12 import { MarkdownTextArea } from "./markdown-textarea";
13 import { MomentTime } from "./moment-time";
15 interface RegistrationApplicationProps {
16 application: RegistrationApplicationView;
17 onApproveApplication(form: ApproveRegistrationApplication): void;
20 interface RegistrationApplicationState {
22 denyExpanded: boolean;
23 approveLoading: boolean;
27 export class RegistrationApplication extends Component<
28 RegistrationApplicationProps,
29 RegistrationApplicationState
31 state: RegistrationApplicationState = {
32 denyReason: this.props.application.registration_application.deny_reason,
34 approveLoading: false,
38 constructor(props: any, context: any) {
39 super(props, context);
40 this.handleDenyReasonChange = this.handleDenyReasonChange.bind(this);
42 componentWillReceiveProps(
44 { children?: InfernoNode } & RegistrationApplicationProps
47 if (this.props != nextProps) {
50 approveLoading: false,
57 const a = this.props.application;
58 const ra = this.props.application.registration_application;
59 const accepted = a.creator_local_user.accepted_application;
62 <div className="registration-application">
64 {i18n.t("applicant")}: <PersonListing person={a.creator} />
67 {i18n.t("created")}: <MomentTime showAgo published={ra.published} />
69 <div>{i18n.t("answer")}:</div>
70 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(ra.answer)} />
75 <T i18nKey="approved_by">
77 <PersonListing person={a.admin} />
81 <T i18nKey="denied_by">
83 <PersonListing person={a.admin} />
87 {i18n.t("deny_reason")}:{" "}
89 className="md-div d-inline-flex"
90 dangerouslySetInnerHTML={mdToHtml(ra.deny_reason)}
99 {this.state.denyExpanded && (
100 <div className="mb-3 row">
101 <label className="col-sm-2 col-form-label">
102 {i18n.t("deny_reason")}
104 <div className="col-sm-10">
106 initialContent={this.state.denyReason}
107 onContentChange={this.handleDenyReasonChange}
108 hideNavigationWarnings
115 {(!ra.admin_id || (ra.admin_id && !accepted)) && (
117 className="btn btn-secondary me-2 my-2"
118 onClick={linkEvent(this, this.handleApprove)}
119 aria-label={i18n.t("approve")}
121 {this.state.approveLoading ? <Spinner /> : i18n.t("approve")}
124 {(!ra.admin_id || (ra.admin_id && accepted)) && (
126 className="btn btn-secondary me-2"
127 onClick={linkEvent(this, this.handleDeny)}
128 aria-label={i18n.t("deny")}
130 {this.state.denyLoading ? <Spinner /> : i18n.t("deny")}
137 handleApprove(i: RegistrationApplication) {
138 i.setState({ denyExpanded: false, approveLoading: true });
139 i.props.onApproveApplication({
140 id: i.props.application.registration_application.id,
142 auth: myAuthRequired(),
146 handleDeny(i: RegistrationApplication) {
147 if (i.state.denyExpanded) {
148 i.setState({ denyExpanded: false, denyLoading: true });
149 i.props.onApproveApplication({
150 id: i.props.application.registration_application.id,
152 deny_reason: i.state.denyReason,
153 auth: myAuthRequired(),
156 i.setState({ denyExpanded: true });
160 handleDenyReasonChange(val: string) {
161 this.setState({ denyReason: val });