aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/moderation/registration-list/registration-list.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+admin/moderation/registration-list/registration-list.component.ts')
-rw-r--r--client/src/app/+admin/moderation/registration-list/registration-list.component.ts125
1 files changed, 125 insertions, 0 deletions
diff --git a/client/src/app/+admin/moderation/registration-list/registration-list.component.ts b/client/src/app/+admin/moderation/registration-list/registration-list.component.ts
new file mode 100644
index 000000000..37514edf5
--- /dev/null
+++ b/client/src/app/+admin/moderation/registration-list/registration-list.component.ts
@@ -0,0 +1,125 @@
1import { SortMeta } from 'primeng/api'
2import { Component, OnInit, ViewChild } from '@angular/core'
3import { ActivatedRoute, Router } from '@angular/router'
4import { MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core'
5import { AdvancedInputFilter } from '@app/shared/shared-forms'
6import { DropdownAction } from '@app/shared/shared-main'
7import { UserRegistration, UserRegistrationState } from '@shared/models'
8import { AdminRegistrationService } from './admin-registration.service'
9import { ProcessRegistrationModalComponent } from './process-registration-modal.component'
10
11@Component({
12 selector: 'my-registration-list',
13 templateUrl: './registration-list.component.html',
14 styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './registration-list.component.scss' ]
15})
16export class RegistrationListComponent extends RestTable implements OnInit {
17 @ViewChild('processRegistrationModal', { static: true }) processRegistrationModal: ProcessRegistrationModalComponent
18
19 registrations: (UserRegistration & { registrationReasonHTML?: string, moderationResponseHTML?: string })[] = []
20 totalRecords = 0
21 sort: SortMeta = { field: 'createdAt', order: -1 }
22 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
23
24 registrationActions: DropdownAction<UserRegistration>[][] = []
25
26 inputFilters: AdvancedInputFilter[] = []
27
28 requiresEmailVerification: boolean
29
30 constructor (
31 protected route: ActivatedRoute,
32 protected router: Router,
33 private server: ServerService,
34 private notifier: Notifier,
35 private markdownRenderer: MarkdownService,
36 private adminRegistrationService: AdminRegistrationService
37 ) {
38 super()
39
40 this.registrationActions = [
41 [
42 {
43 label: $localize`Accept this registration`,
44 handler: registration => this.openRegistrationRequestProcessModal(registration, 'accept'),
45 isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING
46 },
47 {
48 label: $localize`Reject this registration`,
49 handler: registration => this.openRegistrationRequestProcessModal(registration, 'reject'),
50 isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING
51 },
52 {
53 label: $localize`Remove this registration request`,
54 handler: registration => this.removeRegistration(registration),
55 isDisplayed: registration => registration.state.id !== UserRegistrationState.PENDING
56 }
57 ]
58 ]
59 }
60
61 ngOnInit () {
62 this.initialize()
63
64 this.server.getConfig()
65 .subscribe(config => {
66 this.requiresEmailVerification = config.signup.requiresEmailVerification
67 })
68 }
69
70 getIdentifier () {
71 return 'RegistrationListComponent'
72 }
73
74 isRegistrationAccepted (registration: UserRegistration) {
75 return registration.state.id === UserRegistrationState.ACCEPTED
76 }
77
78 isRegistrationRejected (registration: UserRegistration) {
79 return registration.state.id === UserRegistrationState.REJECTED
80 }
81
82 onRegistrationProcessed () {
83 this.reloadData()
84 }
85
86 protected reloadData () {
87 this.adminRegistrationService.listRegistrations({
88 pagination: this.pagination,
89 sort: this.sort,
90 search: this.search
91 }).subscribe({
92 next: async resultList => {
93 this.totalRecords = resultList.total
94 this.registrations = resultList.data
95
96 for (const registration of this.registrations) {
97 registration.registrationReasonHTML = await this.toHtml(registration.registrationReason)
98 registration.moderationResponseHTML = await this.toHtml(registration.moderationResponse)
99 }
100 },
101
102 error: err => this.notifier.error(err.message)
103 })
104 }
105
106 private openRegistrationRequestProcessModal (registration: UserRegistration, mode: 'accept' | 'reject') {
107 this.processRegistrationModal.openModal(registration, mode)
108 }
109
110 private removeRegistration (registration: UserRegistration) {
111 this.adminRegistrationService.removeRegistration(registration)
112 .subscribe({
113 next: () => {
114 this.notifier.success($localize`Registration request deleted.`)
115 this.reloadData()
116 },
117
118 error: err => this.notifier.error(err.message)
119 })
120 }
121
122 private toHtml (text: string) {
123 return this.markdownRenderer.textMarkdownToHTML({ markdown: text })
124 }
125}