From cc584ea15e302ee5fa92c396a43ff9835077c168 Mon Sep 17 00:00:00 2001 From: Josephat Mwakyusa Date: Tue, 4 Jul 2023 09:47:43 +0300 Subject: [PATCH] feat: add support to request account activation/deactivate and attend it --- src/app/core/services/datastore.service.ts | 38 ++-- src/app/core/services/users.service.ts | 34 +++- .../request-user-accounts.component.ts | 4 +- .../requests-list-dashboard.component.html | 2 + ...r-account-request-container.component.html | 62 ++++++- .../user-accounts-feedbacks-list.component.ts | 2 +- .../users-list/users-list.component.html | 169 ++++++++++-------- .../users-list/users-list.component.ts | 115 +++++++++++- ...approve-user-accounts-modal.component.html | 25 ++- .../approve-user-accounts-modal.component.ts | 37 ++++ ...pdate-user-activation-modal.component.html | 21 ++- .../update-user-activation-modal.component.ts | 5 + 12 files changed, 397 insertions(+), 117 deletions(-) diff --git a/src/app/core/services/datastore.service.ts b/src/app/core/services/datastore.service.ts index 9edfe61..77da5c1 100644 --- a/src/app/core/services/datastore.service.ts +++ b/src/app/core/services/datastore.service.ts @@ -195,24 +195,26 @@ export class DataStoreDataService { if (configurations?.category == 'UA') { return { ...dataItem, - searchingText: dataItem?.payload - ?.map((user) => - user?.firstName + - user?.surname + - user?.phoneNumber + - user?.email + - dataItem?.ticketNumber + - user?.organisationUnits?.length > - 0 - ? user?.organisationUnits - ?.map((ou) => ou?.name) - .join('') - : '' + - dataItem?.user?.organisationUnits[0]?.name + - dataItem?.user?.displayName + - dataItem?.user?.email - ) - .join(','), + searchingText: !dataItem?.payload?.userCredentials + ? dataItem?.payload?.userCredentials + ?.map((user) => + user?.firstName + + user?.surname + + user?.phoneNumber + + user?.email + + dataItem?.ticketNumber + + user?.organisationUnits?.length > + 0 + ? user?.organisationUnits + ?.map((ou) => ou?.name) + .join('') + : '' + + dataItem?.user?.organisationUnits[0]?.name + + dataItem?.user?.displayName + + dataItem?.user?.email + ) + .join(',') + : '', }; } else { return dataItem; diff --git a/src/app/core/services/users.service.ts b/src/app/core/services/users.service.ts index ed5a535..283501b 100644 --- a/src/app/core/services/users.service.ts +++ b/src/app/core/services/users.service.ts @@ -4,12 +4,16 @@ import { NgxDhis2HttpClientService } from '@iapps/ngx-dhis2-http-client'; import { Observable, of, zip } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { FeedbackRecepientModel } from 'src/app/shared/models/users.model'; +import { HttpClient } from '@angular/common/http'; @Injectable({ providedIn: 'root', }) export class UsersDataService { - constructor(private httpClient: NgxDhis2HttpClientService) {} + constructor( + private httpClient: NgxDhis2HttpClientService, + private httpClientService: HttpClient + ) {} getUsersByUserGroup( userGroupId: string @@ -34,7 +38,8 @@ export class UsersDataService { .pipe( map((response) => { return response; - }) + }), + catchError((error) => of(error)) ); } @@ -77,6 +82,31 @@ export class UsersDataService { map((response) => response), catchError((error) => of(error)) ); + } else if (data?.method === 'PATCH') { + return zip( + data?.payload + ? this.httpClientService.patch( + `../../../api/${data?.url}`, + data?.payload + ) + : of(null), + this.httpClient.delete(`dataStore/dhis2-user-support/${data?.id}`), + data?.messageConversation + ? this.httpClient.post( + `messageConversations/${data?.messageConversation?.id}`, + data?.messageConversation?.approvalMessage + ) + : of(null), + data?.messageConversation + ? this.httpClient.post( + `messageConversations/${data?.messageConversation?.id}/status?messageConversationStatus=SOLVED`, + null + ) + : this.httpClient.post(`messageConversations`, data?.messageBody) + ).pipe( + map((response) => response), + catchError((error) => of(error)) + ); } else { return of(null); } diff --git a/src/app/pages/user-accounts/components/request-user-accounts/request-user-accounts.component.ts b/src/app/pages/user-accounts/components/request-user-accounts/request-user-accounts.component.ts index 95bdfad..47c2009 100644 --- a/src/app/pages/user-accounts/components/request-user-accounts/request-user-accounts.component.ts +++ b/src/app/pages/user-accounts/components/request-user-accounts/request-user-accounts.component.ts @@ -245,7 +245,7 @@ export class RequestUserAccountsComponent implements OnInit { onSave(event: Event): void { event.stopPropagation(); - console.log('formDataToStoreLocally', this.formDataToStoreLocally); + // console.log('formDataToStoreLocally', this.formDataToStoreLocally); this.dialog .open(ConfirmSendingAccountsRequestComponent, { minWidth: '30%', @@ -352,7 +352,7 @@ export class RequestUserAccountsComponent implements OnInit { .subscribe((response) => { window.localStorage.removeItem('usersToCreate'); this.saving = false; - this.openSnackBar('Successfully sent form request', 'Close'); + this.openSnackBar('Successfully sent the request', 'Close'); setTimeout(() => { this._snackBar.dismiss(); this.router.navigate(['/user-accounts/list']); diff --git a/src/app/pages/user-accounts/components/requests-list-dashboard/requests-list-dashboard.component.html b/src/app/pages/user-accounts/components/requests-list-dashboard/requests-list-dashboard.component.html index 70bd104..9799c0d 100644 --- a/src/app/pages/user-accounts/components/requests-list-dashboard/requests-list-dashboard.component.html +++ b/src/app/pages/user-accounts/components/requests-list-dashboard/requests-list-dashboard.component.html @@ -14,6 +14,7 @@ mode="indeterminate" *ngIf="!params?.allDataForUserSupport" > +
@@ -52,6 +53,7 @@ - - - - - - - - + + + + + + + - + + + + + + + + + + + + + + +
- {{ (currentPage - 1) * pageSize + count + 1 }} - - {{ user?.name }} - - {{ user?.userCredentials?.username }} - - {{ user?.email }} - - {{ user?.userCredentials?.lastLogin }} - - {{ user?.userCredentials?.disabled ? 'Yes' : '' }} - - - + +
+ {{ (currentPage - 1) * pageSize + count + 1 }} + + {{ user?.name }} + + {{ user?.userCredentials?.username }} + + {{ user?.email }} + + {{ user?.userCredentials?.lastLogin }} + + done + - - - - -
+ +
-
+
+
diff --git a/src/app/pages/user-accounts/modals/approve-user-accounts-modal/approve-user-accounts-modal.component.ts b/src/app/pages/user-accounts/modals/approve-user-accounts-modal/approve-user-accounts-modal.component.ts index d985149..1f7298a 100644 --- a/src/app/pages/user-accounts/modals/approve-user-accounts-modal/approve-user-accounts-modal.component.ts +++ b/src/app/pages/user-accounts/modals/approve-user-accounts-modal/approve-user-accounts-modal.component.ts @@ -29,6 +29,7 @@ export class ApproveUserAccountsModalComponent implements OnInit { } ngOnInit(): void { + console.log('DATA', this.dialogData); this.getRequestInformation(); } @@ -139,6 +140,42 @@ export class ApproveUserAccountsModalComponent implements OnInit { }); } + onUpdateUser(event: Event, request: any): void { + event.stopPropagation(); + // console.log(request); + this.saving = true; + + this.messageAndDataStoreService + .searchMessageConversationByTicketNumber(request?.ticketNumber) + .subscribe((response) => { + if (response && response != 'none') { + const messageConversation = response; + const data = { + id: request?.id, + method: request?.method, + url: request?.url, + messageConversation: { + ...messageConversation, + approvalMessage: request?.replyMessage, + }, + payload: request?.payload, + }; + // console.log('data', data); + this.usersDataService.approveChanges(data).subscribe((response) => { + if (response) { + this.getRequestInformation(); + this.saving = false; + setTimeout(() => { + this.dialogRef.close(true); + }); + } + }); + } else { + // Logic to first create approval message + } + }); + } + onApprove(event: Event, userToApprove: any, request: any): void { event.stopPropagation(); this.saving = true; diff --git a/src/app/pages/user-accounts/modals/update-user-activation-modal/update-user-activation-modal.component.html b/src/app/pages/user-accounts/modals/update-user-activation-modal/update-user-activation-modal.component.html index b0ef9d3..ca821ee 100644 --- a/src/app/pages/user-accounts/modals/update-user-activation-modal/update-user-activation-modal.component.html +++ b/src/app/pages/user-accounts/modals/update-user-activation-modal/update-user-activation-modal.component.html @@ -1,3 +1,18 @@ -

- update-user-activation-modal works! -

+

{{ data?.header }}

+ +

+ {{ data?.message }} +

+
+ + + + diff --git a/src/app/pages/user-accounts/modals/update-user-activation-modal/update-user-activation-modal.component.ts b/src/app/pages/user-accounts/modals/update-user-activation-modal/update-user-activation-modal.component.ts index 7f45617..6f5445f 100644 --- a/src/app/pages/user-accounts/modals/update-user-activation-modal/update-user-activation-modal.component.ts +++ b/src/app/pages/user-accounts/modals/update-user-activation-modal/update-user-activation-modal.component.ts @@ -13,4 +13,9 @@ export class UpdateUserActivationModalComponent implements OnInit { ) {} ngOnInit() {} + + onConfirm(event: Event): void { + event.stopPropagation(); + this.matDialogRef.close(true); + } }