1 import { None, Option, Some } from "@sniptt/monads";
2 import { Component, 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 { WebSocketService } from "../../services";
10 import { auth, mdToHtml, wsClient } from "../../utils";
11 import { PersonListing } from "../person/person-listing";
12 import { MarkdownTextArea } from "./markdown-textarea";
13 import { MomentTime } from "./moment-time";
15 interface RegistrationApplicationProps {
16 application: RegistrationApplicationView;
19 interface RegistrationApplicationState {
20 denyReason: Option<string>;
21 denyExpanded: boolean;
24 export class RegistrationApplication extends Component<
25 RegistrationApplicationProps,
26 RegistrationApplicationState
28 private emptyState: RegistrationApplicationState = {
29 denyReason: this.props.application.registration_application.deny_reason,
33 constructor(props: any, context: any) {
34 super(props, context);
36 this.state = this.emptyState;
37 this.handleDenyReasonChange = this.handleDenyReasonChange.bind(this);
41 let a = this.props.application;
42 let ra = this.props.application.registration_application;
43 let accepted = a.creator_local_user.accepted_application;
48 {i18n.t("applicant")}: <PersonListing person={a.creator} />
51 {i18n.t("created")}:{" "}
52 <MomentTime showAgo published={ra.published} updated={None} />
54 <div>{i18n.t("answer")}:</div>
55 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(ra.answer)} />
61 <T i18nKey="approved_by">
63 <PersonListing person={admin} />
67 <T i18nKey="denied_by">
69 <PersonListing person={admin} />
71 {ra.deny_reason.match({
72 some: deny_reason => (
74 {i18n.t("deny_reason")}:{" "}
76 className="md-div d-inline-flex"
77 dangerouslySetInnerHTML={mdToHtml(deny_reason)}
90 {this.state.denyExpanded && (
91 <div className="form-group row">
92 <label className="col-sm-2 col-form-label">
93 {i18n.t("deny_reason")}
95 <div className="col-sm-10">
97 initialContent={this.state.denyReason}
98 onContentChange={this.handleDenyReasonChange}
102 hideNavigationWarnings
107 {(ra.admin_id.isNone() || (ra.admin_id.isSome() && !accepted)) && (
109 className="btn btn-secondary mr-2 my-2"
110 onClick={linkEvent(this, this.handleApprove)}
111 aria-label={i18n.t("approve")}
116 {(ra.admin_id.isNone() || (ra.admin_id.isSome() && accepted)) && (
118 className="btn btn-secondary mr-2"
119 onClick={linkEvent(this, this.handleDeny)}
120 aria-label={i18n.t("deny")}
129 handleApprove(i: RegistrationApplication) {
130 i.setState({ denyExpanded: false });
131 let form = new ApproveRegistrationApplication({
132 id: i.props.application.registration_application.id,
135 auth: auth().unwrap(),
137 WebSocketService.Instance.send(
138 wsClient.approveRegistrationApplication(form)
142 handleDeny(i: RegistrationApplication) {
143 if (i.state.denyExpanded) {
144 i.setState({ denyExpanded: false });
145 let form = new ApproveRegistrationApplication({
146 id: i.props.application.registration_application.id,
148 deny_reason: i.state.denyReason,
149 auth: auth().unwrap(),
151 WebSocketService.Instance.send(
152 wsClient.approveRegistrationApplication(form)
155 i.setState({ denyExpanded: true });
159 handleDenyReasonChange(val: string) {
160 this.setState({ denyReason: Some(val) });