diff options
Diffstat (limited to 'client/src/app/+admin/moderation/registration-list/process-registration-modal.component.ts')
-rw-r--r-- | client/src/app/+admin/moderation/registration-list/process-registration-modal.component.ts | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.ts b/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.ts new file mode 100644 index 000000000..3a7e5dea1 --- /dev/null +++ b/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.ts | |||
@@ -0,0 +1,122 @@ | |||
1 | import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' | ||
2 | import { Notifier, ServerService } from '@app/core' | ||
3 | import { FormReactive, FormReactiveService } from '@app/shared/shared-forms' | ||
4 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
5 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
6 | import { UserRegistration } from '@shared/models' | ||
7 | import { AdminRegistrationService } from './admin-registration.service' | ||
8 | import { REGISTRATION_MODERATION_RESPONSE_VALIDATOR } from './process-registration-validators' | ||
9 | |||
10 | @Component({ | ||
11 | selector: 'my-process-registration-modal', | ||
12 | templateUrl: './process-registration-modal.component.html', | ||
13 | styleUrls: [ './process-registration-modal.component.scss' ] | ||
14 | }) | ||
15 | export class ProcessRegistrationModalComponent extends FormReactive implements OnInit { | ||
16 | @ViewChild('modal', { static: true }) modal: NgbModal | ||
17 | |||
18 | @Output() registrationProcessed = new EventEmitter() | ||
19 | |||
20 | registration: UserRegistration | ||
21 | |||
22 | private openedModal: NgbModalRef | ||
23 | private processMode: 'accept' | 'reject' | ||
24 | |||
25 | constructor ( | ||
26 | protected formReactiveService: FormReactiveService, | ||
27 | private server: ServerService, | ||
28 | private modalService: NgbModal, | ||
29 | private notifier: Notifier, | ||
30 | private registrationService: AdminRegistrationService | ||
31 | ) { | ||
32 | super() | ||
33 | } | ||
34 | |||
35 | ngOnInit () { | ||
36 | this.buildForm({ | ||
37 | moderationResponse: REGISTRATION_MODERATION_RESPONSE_VALIDATOR, | ||
38 | preventEmailDelivery: null | ||
39 | }) | ||
40 | } | ||
41 | |||
42 | isAccept () { | ||
43 | return this.processMode === 'accept' | ||
44 | } | ||
45 | |||
46 | isReject () { | ||
47 | return this.processMode === 'reject' | ||
48 | } | ||
49 | |||
50 | openModal (registration: UserRegistration, mode: 'accept' | 'reject') { | ||
51 | this.processMode = mode | ||
52 | this.registration = registration | ||
53 | |||
54 | this.form.patchValue({ | ||
55 | preventEmailDelivery: !this.isEmailEnabled() || registration.emailVerified !== true | ||
56 | }) | ||
57 | |||
58 | this.openedModal = this.modalService.open(this.modal, { centered: true }) | ||
59 | } | ||
60 | |||
61 | hide () { | ||
62 | this.form.reset() | ||
63 | |||
64 | this.openedModal.close() | ||
65 | } | ||
66 | |||
67 | getSubmitValue () { | ||
68 | if (this.isAccept()) { | ||
69 | return $localize`Accept registration` | ||
70 | } | ||
71 | |||
72 | return $localize`Reject registration` | ||
73 | } | ||
74 | |||
75 | processRegistration () { | ||
76 | if (this.isAccept()) return this.acceptRegistration() | ||
77 | |||
78 | return this.rejectRegistration() | ||
79 | } | ||
80 | |||
81 | isEmailEnabled () { | ||
82 | return this.server.getHTMLConfig().email.enabled | ||
83 | } | ||
84 | |||
85 | isPreventEmailDeliveryChecked () { | ||
86 | return this.form.value.preventEmailDelivery | ||
87 | } | ||
88 | |||
89 | private acceptRegistration () { | ||
90 | this.registrationService.acceptRegistration({ | ||
91 | registration: this.registration, | ||
92 | moderationResponse: this.form.value.moderationResponse, | ||
93 | preventEmailDelivery: this.form.value.preventEmailDelivery | ||
94 | }).subscribe({ | ||
95 | next: () => { | ||
96 | this.notifier.success($localize`${this.registration.username} account created`) | ||
97 | |||
98 | this.registrationProcessed.emit() | ||
99 | this.hide() | ||
100 | }, | ||
101 | |||
102 | error: err => this.notifier.error(err.message) | ||
103 | }) | ||
104 | } | ||
105 | |||
106 | private rejectRegistration () { | ||
107 | this.registrationService.rejectRegistration({ | ||
108 | registration: this.registration, | ||
109 | moderationResponse: this.form.value.moderationResponse, | ||
110 | preventEmailDelivery: this.form.value.preventEmailDelivery | ||
111 | }).subscribe({ | ||
112 | next: () => { | ||
113 | this.notifier.success($localize`${this.registration.username} registration rejected`) | ||
114 | |||
115 | this.registrationProcessed.emit() | ||
116 | this.hide() | ||
117 | }, | ||
118 | |||
119 | error: err => this.notifier.error(err.message) | ||
120 | }) | ||
121 | } | ||
122 | } | ||