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 { mdToHtml, myAuth, 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 state: RegistrationApplicationState = {
28 denyReason: this.props.application.registration_application.deny_reason,
32 constructor(props: any, context: any) {
33 super(props, context);
34 this.handleDenyReasonChange = this.handleDenyReasonChange.bind(this);
38 let a = this.props.application;
39 let ra = this.props.application.registration_application;
40 let accepted = a.creator_local_user.accepted_application;
45 {i18n.t("applicant")}: <PersonListing person={a.creator} />
48 {i18n.t("created")}: <MomentTime showAgo published={ra.published} />
50 <div>{i18n.t("answer")}:</div>
51 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(ra.answer)} />
56 <T i18nKey="approved_by">
58 <PersonListing person={a.admin} />
62 <T i18nKey="denied_by">
64 <PersonListing person={a.admin} />
68 {i18n.t("deny_reason")}:{" "}
70 className="md-div d-inline-flex"
71 dangerouslySetInnerHTML={mdToHtml(ra.deny_reason)}
80 {this.state.denyExpanded && (
81 <div className="form-group row">
82 <label className="col-sm-2 col-form-label">
83 {i18n.t("deny_reason")}
85 <div className="col-sm-10">
87 initialContent={this.state.denyReason}
88 onContentChange={this.handleDenyReasonChange}
89 hideNavigationWarnings
96 {(!ra.admin_id || (ra.admin_id && !accepted)) && (
98 className="btn btn-secondary mr-2 my-2"
99 onClick={linkEvent(this, this.handleApprove)}
100 aria-label={i18n.t("approve")}
105 {(!ra.admin_id || (ra.admin_id && accepted)) && (
107 className="btn btn-secondary mr-2"
108 onClick={linkEvent(this, this.handleDeny)}
109 aria-label={i18n.t("deny")}
118 handleApprove(i: RegistrationApplication) {
121 i.setState({ denyExpanded: false });
122 let form: ApproveRegistrationApplication = {
123 id: i.props.application.registration_application.id,
127 WebSocketService.Instance.send(
128 wsClient.approveRegistrationApplication(form)
133 handleDeny(i: RegistrationApplication) {
134 if (i.state.denyExpanded) {
135 i.setState({ denyExpanded: false });
138 let form: ApproveRegistrationApplication = {
139 id: i.props.application.registration_application.id,
141 deny_reason: i.state.denyReason,
144 WebSocketService.Instance.send(
145 wsClient.approveRegistrationApplication(form)
149 i.setState({ denyExpanded: true });
153 handleDenyReasonChange(val: string) {
154 this.setState({ denyReason: val });