From de68ba1c1243a96f15a942a9d2780901d5f23a36 Mon Sep 17 00:00:00 2001 From: Mojtaba Erfan Rad Date: Wed, 21 Aug 2024 12:56:54 +0330 Subject: [PATCH 01/16] fix(delete-user): fixed pagination on user delete --- .../manage-users/manage-users.component.ts | 8 ++++++-- .../user-delete-confirmation.component.ts | 15 ++++++++++++--- src/app/user/services/admin/admin.service.ts | 4 ++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/app/user/components/dashboard/manage-users/manage-users.component.ts b/src/app/user/components/dashboard/manage-users/manage-users.component.ts index 545073f..8dd654b 100644 --- a/src/app/user/components/dashboard/manage-users/manage-users.component.ts +++ b/src/app/user/components/dashboard/manage-users/manage-users.component.ts @@ -25,7 +25,7 @@ export class ManageUsersComponent implements OnInit { ]; length!: number; pageSize = 10; - pageIndex = 1; + pageIndex = 0; pageSizeOptions = [5, 10, 25]; hidePageSize = false; @@ -65,7 +65,11 @@ export class ManageUsersComponent implements OnInit { deleteUser(userData: UserData) { this.dialog.open(UserDeleteConfirmationComponent, { width: '22rem', - data: userData, + data: { + userData: userData, + pagSize: this.pageSize, + pageIndex: this.pageIndex, + }, }); } } diff --git a/src/app/user/components/dashboard/manage-users/user-delete-confirmation/user-delete-confirmation.component.ts b/src/app/user/components/dashboard/manage-users/user-delete-confirmation/user-delete-confirmation.component.ts index b1afc37..f91e6c8 100644 --- a/src/app/user/components/dashboard/manage-users/user-delete-confirmation/user-delete-confirmation.component.ts +++ b/src/app/user/components/dashboard/manage-users/user-delete-confirmation/user-delete-confirmation.component.ts @@ -8,7 +8,7 @@ import { AdminService } from '../../../../services/admin/admin.service'; template: `

Delete User

- Would you like to delete {{ this.userData.username }}? + Would you like to delete {{ this.userData.userData.username }}? @@ -25,11 +25,20 @@ import { AdminService } from '../../../../services/admin/admin.service'; }) export class UserDeleteConfirmationComponent { constructor( - @Inject(MAT_DIALOG_DATA) protected userData: UserData, + @Inject(MAT_DIALOG_DATA) + protected userData: { + userData: UserData; + pagSize: number; + pageIndex: number; + }, private adminService: AdminService ) {} deleteUser() { - this.adminService.deleteUser(this.userData.guid); + this.adminService.deleteUser( + this.userData.userData.guid, + this.userData.pagSize, + this.userData.pageIndex + ); } } diff --git a/src/app/user/services/admin/admin.service.ts b/src/app/user/services/admin/admin.service.ts index 579ee0f..7ebea44 100644 --- a/src/app/user/services/admin/admin.service.ts +++ b/src/app/user/services/admin/admin.service.ts @@ -37,13 +37,13 @@ export class AdminService { }); } - deleteUser(id: string) { + deleteUser(id: string, pageSize: number, pageIndex: number) { this.http .delete(`${this.apiUrl}/DeleteUser?id=${id}`, { withCredentials: true, }) .subscribe(() => { - this.getUsers(); + this.getUsers(pageSize, pageIndex); }); } From 74d62df4174d1335b4f3acc44e97036d46079789 Mon Sep 17 00:00:00 2001 From: Mojtaba Erfan Rad Date: Wed, 21 Aug 2024 14:28:17 +0330 Subject: [PATCH 02/16] fix(user-manage): fixed pagination on delete --- .../dashboard/manage-users/manage-users.component.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/app/user/components/dashboard/manage-users/manage-users.component.ts b/src/app/user/components/dashboard/manage-users/manage-users.component.ts index 8dd654b..458765f 100644 --- a/src/app/user/components/dashboard/manage-users/manage-users.component.ts +++ b/src/app/user/components/dashboard/manage-users/manage-users.component.ts @@ -49,6 +49,9 @@ export class ManageUsersComponent implements OnInit { } handlePageEvent(e: PageEvent) { + this.pageSize = e.pageSize; + this.pageIndex = e.pageIndex; + this.length = e.length; this.adminService.getUsers(e.pageSize, e.pageIndex); } From 1577d0def6029ff01001d55b5b737442684f61ee Mon Sep 17 00:00:00 2001 From: Zahra Masoumi Date: Wed, 21 Aug 2024 14:41:18 +0330 Subject: [PATCH 03/16] fix(url) --- angular.json | 8 +++++++- api-config/api-url.ts | 4 ++++ .../components/dashboard/add-user/add-user.component.html | 8 ++++++-- src/app/user/services/admin/admin.service.ts | 4 ++-- src/app/user/services/auth/auth.service.ts | 8 ++++---- src/app/user/services/user/user.service.ts | 2 +- 6 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 api-config/api-url.ts diff --git a/angular.json b/angular.json index 301c8df..33b33de 100644 --- a/angular.json +++ b/angular.json @@ -54,7 +54,13 @@ "maximumError": "4kB" } ], - "outputHashing": "all" + "outputHashing": "all", + "fileReplacements": [ + { + "replace": "api-config/api-url.dev.ts", + "with": "api-config/api-url.ts" + } + ] }, "development": { "optimization": false, diff --git a/api-config/api-url.ts b/api-config/api-url.ts new file mode 100644 index 0000000..5df7aac --- /dev/null +++ b/api-config/api-url.ts @@ -0,0 +1,4 @@ +export const environment = { + production: false, + apiUrl: 'https://staging.api.yourdomain.com', +}; diff --git a/src/app/user/components/dashboard/add-user/add-user.component.html b/src/app/user/components/dashboard/add-user/add-user.component.html index ac971b0..612a180 100644 --- a/src/app/user/components/dashboard/add-user/add-user.component.html +++ b/src/app/user/components/dashboard/add-user/add-user.component.html @@ -77,8 +77,12 @@

Add User

formControlName="roleName" > Admin - Option 2 - Option 3 + Data Manager + System Manager
diff --git a/src/app/user/services/admin/admin.service.ts b/src/app/user/services/admin/admin.service.ts index 8d3a7de..a63cc1d 100644 --- a/src/app/user/services/admin/admin.service.ts +++ b/src/app/user/services/admin/admin.service.ts @@ -14,8 +14,10 @@ import { environment } from '../../../../../api-config/api-url'; export class AdminService { private readonly apiUrl = environment.apiUrl + '/api/Admin'; private usersData = new Subject(); + private notification = new Subject<{ status: boolean; message: string }>(); usersData$ = this.usersData.asObservable(); + notification$ = this.notification.asObservable(); constructor(private http: HttpClient) {} @@ -25,7 +27,7 @@ export class AdminService { }); } - getUsers(limit = 10, page = 1) { + getUsers(limit = 10, page = 0) { this.http .get( `${this.apiUrl}/GetUsersPagination?limit=${limit}&page=${page}`, @@ -43,8 +45,20 @@ export class AdminService { .delete(`${this.apiUrl}/DeleteUser?id=${id}`, { withCredentials: true, }) - .subscribe(() => { - this.getUsers(pageSize, pageIndex); + .subscribe({ + next: () => { + this.getUsers(pageSize, pageIndex); + this.notification.next({ + status: true, + message: 'User deleted successfully!', + }); + }, + error: (error) => { + this.notification.next({ + status: false, + message: error, + }); + }, }); } diff --git a/src/app/user/user.module.ts b/src/app/user/user.module.ts index 2b8f03f..6496ef8 100644 --- a/src/app/user/user.module.ts +++ b/src/app/user/user.module.ts @@ -15,7 +15,7 @@ import { MatRippleModule } from '@angular/material/core'; import { AppRoutingModule } from '../app-routing.module'; import { MainPageComponent } from './components/dashboard/main-page/main-page.component'; import { SharedModule } from '../shared/shared.module'; -import { AddUserComponent } from './components/dashboard/add-user/add-user.component'; +import { AddUserComponent } from './components/dashboard/manage-users/add-user/add-user.component'; import { MatRadioModule } from '@angular/material/radio'; import { ManageAccountComponent } from './components/dashboard/manage-account/manage-account.component'; import { ManageUsersComponent } from './components/dashboard/manage-users/manage-users.component'; From 50d04aa6c0a152a7b4e6c039dd645c321d84706c Mon Sep 17 00:00:00 2001 From: Zahra Masoumi Date: Wed, 21 Aug 2024 15:36:12 +0330 Subject: [PATCH 08/16] feat(edit-user): add edit user dialog --- .../edit-user/edit-user.component.html | 72 +++++++++++++++++++ .../edit-user/edit-user.component.scss | 38 ++++++++++ .../edit-user/edit-user.component.spec.ts | 23 ++++++ .../edit-user/edit-user.component.ts | 45 ++++++++++++ .../manage-users/manage-users.component.html | 2 +- .../manage-users/manage-users.component.ts | 10 ++- src/app/user/user.module.ts | 2 + 7 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 src/app/user/components/dashboard/edit-user/edit-user.component.html create mode 100644 src/app/user/components/dashboard/edit-user/edit-user.component.scss create mode 100644 src/app/user/components/dashboard/edit-user/edit-user.component.spec.ts create mode 100644 src/app/user/components/dashboard/edit-user/edit-user.component.ts diff --git a/src/app/user/components/dashboard/edit-user/edit-user.component.html b/src/app/user/components/dashboard/edit-user/edit-user.component.html new file mode 100644 index 0000000..90af001 --- /dev/null +++ b/src/app/user/components/dashboard/edit-user/edit-user.component.html @@ -0,0 +1,72 @@ +

Edit User

+
+
+
+ + First Name + + + + Last Name + + + + Username + + + + Email + + + + Phone Number + + + + + Admin + Data Manager + + System Manager + + +
+ +
+
+
diff --git a/src/app/user/components/dashboard/edit-user/edit-user.component.scss b/src/app/user/components/dashboard/edit-user/edit-user.component.scss new file mode 100644 index 0000000..b2be2fd --- /dev/null +++ b/src/app/user/components/dashboard/edit-user/edit-user.component.scss @@ -0,0 +1,38 @@ +.title { + margin: 1.25rem 1.75rem; + color: var(--mat-sidenav-content-text-color); +} + +hr { + color: var(--mat-sidenav-content-text-color); +} + +.card { + padding: 2rem; + padding-block-start: 1rem; + overflow: auto; + max-height: 80vh; + + .add-user-form { + display: flex; + flex-direction: column; + gap: 0.5rem; + + .radio-buttons { + display: flex; + align-items: center; + } + + .label { + color: var(--mat-sidenav-content-text-color); + } + + .submit-button-container { + padding-block-start: 1rem; + + > button { + width: 100%; + } + } + } +} diff --git a/src/app/user/components/dashboard/edit-user/edit-user.component.spec.ts b/src/app/user/components/dashboard/edit-user/edit-user.component.spec.ts new file mode 100644 index 0000000..643be33 --- /dev/null +++ b/src/app/user/components/dashboard/edit-user/edit-user.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EditUserComponent } from './edit-user.component'; + +describe('EditUserComponent', () => { + let component: EditUserComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [EditUserComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(EditUserComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/user/components/dashboard/edit-user/edit-user.component.ts b/src/app/user/components/dashboard/edit-user/edit-user.component.ts new file mode 100644 index 0000000..7d5166d --- /dev/null +++ b/src/app/user/components/dashboard/edit-user/edit-user.component.ts @@ -0,0 +1,45 @@ +import { Component, Inject, OnInit } from '@angular/core'; +import { AdminService } from '../../../services/admin/admin.service'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { UserData } from '../../../interfaces/manage-users.interface'; + +@Component({ + selector: 'app-edit-user', + templateUrl: './edit-user.component.html', + styleUrl: './edit-user.component.scss', +}) +export class EditUserComponent implements OnInit { + constructor( + private adminService: AdminService, + @Inject(MAT_DIALOG_DATA) + protected userData: UserData, + ) {} + + myForm: FormGroup = new FormGroup({}); + + ngOnInit() { + this.myForm = new FormGroup({ + firstName: new FormControl(this.userData.firstName, Validators.required), + lastName: new FormControl(this.userData.lastName, Validators.required), + username: new FormControl(this.userData.username, Validators.required), + email: new FormControl(this.userData.email, [ + Validators.required, + Validators.email, + ]), + phoneNumber: new FormControl(this.userData.phoneNumber, [ + Validators.required, + Validators.pattern('^[0-9]*$'), + ]), + roleName: new FormControl(this.userData.roleName), + }); + } + + onSubmit() { + if (this.myForm.valid) { + this.adminService + .updateUser(this.userData.guid, this.myForm.value) + .subscribe(console.log); + } + } +} diff --git a/src/app/user/components/dashboard/manage-users/manage-users.component.html b/src/app/user/components/dashboard/manage-users/manage-users.component.html index 4b3fac4..9cece50 100644 --- a/src/app/user/components/dashboard/manage-users/manage-users.component.html +++ b/src/app/user/components/dashboard/manage-users/manage-users.component.html @@ -30,7 +30,7 @@ edit/delete - + + `, + + styles: `:host{display:flex}`, +}) +export class UserManageNotificationComponent {} diff --git a/src/app/user/user.module.ts b/src/app/user/user.module.ts index c9e137b..7a6f181 100644 --- a/src/app/user/user.module.ts +++ b/src/app/user/user.module.ts @@ -29,6 +29,12 @@ import { MatDialogTitle, } from '@angular/material/dialog'; import { EditUserComponent } from './components/dashboard/edit-user/edit-user.component'; +import { UserManageNotificationComponent } from './components/dashboard/manage-users/user-manage-notification/user-manage-notification.component'; +import { + MatSnackBarAction, + MatSnackBarActions, + MatSnackBarLabel, +} from '@angular/material/snack-bar'; @NgModule({ declarations: [ @@ -40,6 +46,7 @@ import { EditUserComponent } from './components/dashboard/edit-user/edit-user.co ManageUsersComponent, UserDeleteConfirmationComponent, EditUserComponent, + UserManageNotificationComponent, ], imports: [ CommonModule, @@ -63,6 +70,9 @@ import { EditUserComponent } from './components/dashboard/edit-user/edit-user.co MatDialogActions, MatDialogClose, MatDialogTitle, + MatSnackBarAction, + MatSnackBarActions, + MatSnackBarLabel, ], }) export class UserModule {} From 9d97a34f91c21ee988a2ba12000cb6e62e290f5f Mon Sep 17 00:00:00 2001 From: Mojtaba Erfan Rad Date: Wed, 21 Aug 2024 16:23:30 +0330 Subject: [PATCH 10/16] fix(notification): notification works perfectly --- .../dashboard-header.component.ts | 5 ++++- .../manage-users/manage-users.component.ts | 15 +++++++++---- .../user-manage-notification.component.ts | 21 +++++++++++-------- src/app/user/user.module.ts | 8 +------ src/styles.scss | 19 +++++++++++++++++ 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/app/shared/components/dashboard-header/dashboard-header.component.ts b/src/app/shared/components/dashboard-header/dashboard-header.component.ts index 15d556b..a963728 100644 --- a/src/app/shared/components/dashboard-header/dashboard-header.component.ts +++ b/src/app/shared/components/dashboard-header/dashboard-header.component.ts @@ -27,6 +27,9 @@ export class DashboardHeaderComponent { } infoClick() { - this._snackBar.open('Coming soon...', 'Ok :(', { duration: 2000 }); + this._snackBar.open('Coming soon...', 'Ok :(', { + duration: 2000, + panelClass: ['info-notification'], + }); } } diff --git a/src/app/user/components/dashboard/manage-users/manage-users.component.ts b/src/app/user/components/dashboard/manage-users/manage-users.component.ts index 47b170b..a8be968 100644 --- a/src/app/user/components/dashboard/manage-users/manage-users.component.ts +++ b/src/app/user/components/dashboard/manage-users/manage-users.component.ts @@ -8,8 +8,9 @@ import { AddUserComponent } from './add-user/add-user.component'; import { PageEvent } from '@angular/material/paginator'; import { UserDeleteConfirmationComponent } from './user-delete-confirmation/user-delete-confirmation.component'; import { AdminService } from '../../../services/admin/admin.service'; -import {MatSnackBar} from "@angular/material/snack-bar"; -import {EditUserComponent} from "../edit-user/edit-user.component"; +import { MatSnackBar } from '@angular/material/snack-bar'; +import { EditUserComponent } from '../edit-user/edit-user.component'; +import { UserManageNotificationComponent } from './user-manage-notification/user-manage-notification.component'; @Component({ selector: 'app-manage-users', @@ -39,7 +40,7 @@ export class ManageUsersComponent implements OnInit { private readonly dialog: MatDialog, private adminService: AdminService, private _snackBar: MatSnackBar -) {} + ) {} ngOnInit(): void { this.adminService.usersData$.subscribe((res: GetUserResponse) => { @@ -49,7 +50,13 @@ export class ManageUsersComponent implements OnInit { }); this.adminService.notification$.subscribe((data) => { - this._snackBar.open(data.message); + this._snackBar.openFromComponent(UserManageNotificationComponent, { + data: data.message, + panelClass: data.status + ? ['notification-class-success'] + : ['notification-class-danger'], + duration: 2000, + }); }); this.adminService.getUsers(this.pageSize, this.pageIndex); diff --git a/src/app/user/components/dashboard/manage-users/user-manage-notification/user-manage-notification.component.ts b/src/app/user/components/dashboard/manage-users/user-manage-notification/user-manage-notification.component.ts index 40c0ad6..5b48244 100644 --- a/src/app/user/components/dashboard/manage-users/user-manage-notification/user-manage-notification.component.ts +++ b/src/app/user/components/dashboard/manage-users/user-manage-notification/user-manage-notification.component.ts @@ -1,14 +1,17 @@ -import { Component } from '@angular/core'; +import { Component, Inject } from '@angular/core'; +import { MAT_SNACK_BAR_DATA } from '@angular/material/snack-bar'; @Component({ selector: 'app-user-manage-notification', - template: ` - Pizza party!!! - - - - `, + template: ` {{ this.userData }} `, - styles: `:host{display:flex}`, + styles: `:host{display:flex;color:white}`, }) -export class UserManageNotificationComponent {} +export class UserManageNotificationComponent { + constructor( + @Inject(MAT_SNACK_BAR_DATA) + protected userData: string + ) { + console.log(userData); + } +} diff --git a/src/app/user/user.module.ts b/src/app/user/user.module.ts index 7a6f181..b16589e 100644 --- a/src/app/user/user.module.ts +++ b/src/app/user/user.module.ts @@ -30,11 +30,7 @@ import { } from '@angular/material/dialog'; import { EditUserComponent } from './components/dashboard/edit-user/edit-user.component'; import { UserManageNotificationComponent } from './components/dashboard/manage-users/user-manage-notification/user-manage-notification.component'; -import { - MatSnackBarAction, - MatSnackBarActions, - MatSnackBarLabel, -} from '@angular/material/snack-bar'; +import { MatSnackBarLabel } from '@angular/material/snack-bar'; @NgModule({ declarations: [ @@ -70,8 +66,6 @@ import { MatDialogActions, MatDialogClose, MatDialogTitle, - MatSnackBarAction, - MatSnackBarActions, MatSnackBarLabel, ], }) diff --git a/src/styles.scss b/src/styles.scss index 5805916..880ff2c 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -328,3 +328,22 @@ body, .mat-mdc-paginator-container { justify-content: center !important; } + +.notification-class-danger { + background-color: #f44336; + border-radius: 0.25rem; +} + +.notification-class-success { + background-color: #388e3c; + border-radius: 0.25rem; +} + +.info-notification { + background-color: var(--mdc-snackbar-container-color); + border-radius: 0.25rem; +} + +.mat-mdc-snack-bar-container .mat-mdc-snackbar-surface { + background-color: inherit !important; +} From 7d2e98dd4600f40cce5ab7fc2117ce6933cf6d52 Mon Sep 17 00:00:00 2001 From: Zahra Masoumi Date: Wed, 21 Aug 2024 16:32:15 +0330 Subject: [PATCH 11/16] fix(service): fix. --- .../{ => manage-users}/edit-user/edit-user.component.html | 0 .../{ => manage-users}/edit-user/edit-user.component.scss | 0 .../edit-user/edit-user.component.spec.ts | 0 .../{ => manage-users}/edit-user/edit-user.component.ts | 4 ++-- .../dashboard/manage-users/manage-users.component.ts | 4 ++-- src/app/user/services/admin/admin.service.ts | 7 +++++-- src/app/user/user.module.ts | 2 +- 7 files changed, 10 insertions(+), 7 deletions(-) rename src/app/user/components/dashboard/{ => manage-users}/edit-user/edit-user.component.html (100%) rename src/app/user/components/dashboard/{ => manage-users}/edit-user/edit-user.component.scss (100%) rename src/app/user/components/dashboard/{ => manage-users}/edit-user/edit-user.component.spec.ts (100%) rename src/app/user/components/dashboard/{ => manage-users}/edit-user/edit-user.component.ts (90%) diff --git a/src/app/user/components/dashboard/edit-user/edit-user.component.html b/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.html similarity index 100% rename from src/app/user/components/dashboard/edit-user/edit-user.component.html rename to src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.html diff --git a/src/app/user/components/dashboard/edit-user/edit-user.component.scss b/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.scss similarity index 100% rename from src/app/user/components/dashboard/edit-user/edit-user.component.scss rename to src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.scss diff --git a/src/app/user/components/dashboard/edit-user/edit-user.component.spec.ts b/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.spec.ts similarity index 100% rename from src/app/user/components/dashboard/edit-user/edit-user.component.spec.ts rename to src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.spec.ts diff --git a/src/app/user/components/dashboard/edit-user/edit-user.component.ts b/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.ts similarity index 90% rename from src/app/user/components/dashboard/edit-user/edit-user.component.ts rename to src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.ts index 7d5166d..a796fe0 100644 --- a/src/app/user/components/dashboard/edit-user/edit-user.component.ts +++ b/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.ts @@ -1,8 +1,8 @@ import { Component, Inject, OnInit } from '@angular/core'; -import { AdminService } from '../../../services/admin/admin.service'; +import { AdminService } from '../../../../services/admin/admin.service'; import { FormControl, FormGroup, Validators } from '@angular/forms'; import { MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { UserData } from '../../../interfaces/manage-users.interface'; +import { UserData } from '../../../../interfaces/manage-users.interface'; @Component({ selector: 'app-edit-user', diff --git a/src/app/user/components/dashboard/manage-users/manage-users.component.ts b/src/app/user/components/dashboard/manage-users/manage-users.component.ts index a8be968..47dbdf8 100644 --- a/src/app/user/components/dashboard/manage-users/manage-users.component.ts +++ b/src/app/user/components/dashboard/manage-users/manage-users.component.ts @@ -9,7 +9,7 @@ import { PageEvent } from '@angular/material/paginator'; import { UserDeleteConfirmationComponent } from './user-delete-confirmation/user-delete-confirmation.component'; import { AdminService } from '../../../services/admin/admin.service'; import { MatSnackBar } from '@angular/material/snack-bar'; -import { EditUserComponent } from '../edit-user/edit-user.component'; +import { EditUserComponent } from './edit-user/edit-user.component'; import { UserManageNotificationComponent } from './user-manage-notification/user-manage-notification.component'; @Component({ @@ -39,7 +39,7 @@ export class ManageUsersComponent implements OnInit { constructor( private readonly dialog: MatDialog, private adminService: AdminService, - private _snackBar: MatSnackBar + private _snackBar: MatSnackBar, ) {} ngOnInit(): void { diff --git a/src/app/user/services/admin/admin.service.ts b/src/app/user/services/admin/admin.service.ts index a63cc1d..285d03c 100644 --- a/src/app/user/services/admin/admin.service.ts +++ b/src/app/user/services/admin/admin.service.ts @@ -33,7 +33,7 @@ export class AdminService { `${this.apiUrl}/GetUsersPagination?limit=${limit}&page=${page}`, { withCredentials: true, - } + }, ) .subscribe((users) => { this.usersData.next(users); @@ -63,7 +63,10 @@ export class AdminService { } updateUser(id: string, request: UpdateUserRequest) { - return this.http.put(`${this.apiUrl}/UpdateUser?id=${id}`, request); + console.log(22, request, id); + return this.http.put(`${this.apiUrl}/UpdateUser?id=${id}`, request, { + withCredentials: true, + }); } getUserById(id: string) { diff --git a/src/app/user/user.module.ts b/src/app/user/user.module.ts index b16589e..9bce372 100644 --- a/src/app/user/user.module.ts +++ b/src/app/user/user.module.ts @@ -28,7 +28,7 @@ import { MatDialogContent, MatDialogTitle, } from '@angular/material/dialog'; -import { EditUserComponent } from './components/dashboard/edit-user/edit-user.component'; +import { EditUserComponent } from './components/dashboard/manage-users/edit-user/edit-user.component'; import { UserManageNotificationComponent } from './components/dashboard/manage-users/user-manage-notification/user-manage-notification.component'; import { MatSnackBarLabel } from '@angular/material/snack-bar'; From 2b31feed47f6a93b79f6d4f29ec0a03d9c56786d Mon Sep 17 00:00:00 2001 From: Zahra Masoumi Date: Wed, 21 Aug 2024 16:39:16 +0330 Subject: [PATCH 12/16] fix(user-manage): fix notifications --- .../add-user/add-user.component.ts | 4 +- .../edit-user/edit-user.component.ts | 4 +- .../manage-users/manage-users.component.ts | 4 ++ src/app/user/services/admin/admin.service.ts | 46 +++++++++++++++---- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts b/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts index bc7197f..5a61bb5 100644 --- a/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts +++ b/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts @@ -19,7 +19,7 @@ export class AddUserComponent implements OnInit { this.myForm = new FormGroup({ firstName: new FormControl( userData ? userData.firstName : '', - Validators.required + Validators.required, ), lastName: new FormControl('', Validators.required), username: new FormControl('', Validators.required), @@ -36,7 +36,7 @@ export class AddUserComponent implements OnInit { onSubmit() { if (this.myForm.valid) { - this.adminService.createUser(this.myForm.value).subscribe(console.log); + this.adminService.createUser(this.myForm.value); } } } diff --git a/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.ts b/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.ts index a796fe0..f580890 100644 --- a/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.ts +++ b/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.ts @@ -37,9 +37,7 @@ export class EditUserComponent implements OnInit { onSubmit() { if (this.myForm.valid) { - this.adminService - .updateUser(this.userData.guid, this.myForm.value) - .subscribe(console.log); + this.adminService.updateUser(this.userData.guid, this.myForm.value); } } } diff --git a/src/app/user/components/dashboard/manage-users/manage-users.component.ts b/src/app/user/components/dashboard/manage-users/manage-users.component.ts index 47dbdf8..3a2663c 100644 --- a/src/app/user/components/dashboard/manage-users/manage-users.component.ts +++ b/src/app/user/components/dashboard/manage-users/manage-users.component.ts @@ -57,6 +57,10 @@ export class ManageUsersComponent implements OnInit { : ['notification-class-danger'], duration: 2000, }); + + if (data.status) { + this.dialog.closeAll(); + } }); this.adminService.getUsers(this.pageSize, this.pageIndex); diff --git a/src/app/user/services/admin/admin.service.ts b/src/app/user/services/admin/admin.service.ts index 285d03c..4dff5cc 100644 --- a/src/app/user/services/admin/admin.service.ts +++ b/src/app/user/services/admin/admin.service.ts @@ -22,9 +22,25 @@ export class AdminService { constructor(private http: HttpClient) {} createUser(request: RegisterRequest) { - return this.http.post(`${this.apiUrl}/register`, request, { - withCredentials: true, - }); + return this.http + .post(`${this.apiUrl}/register`, request, { + withCredentials: true, + }) + .subscribe({ + next: () => { + // this.getUsers(pageSize, pageIndex); + this.notification.next({ + status: true, + message: 'User added successfully!', + }); + }, + error: (error) => { + this.notification.next({ + status: false, + message: error, + }); + }, + }); } getUsers(limit = 10, page = 0) { @@ -63,14 +79,28 @@ export class AdminService { } updateUser(id: string, request: UpdateUserRequest) { - console.log(22, request, id); - return this.http.put(`${this.apiUrl}/UpdateUser?id=${id}`, request, { - withCredentials: true, - }); + return this.http + .put(`${this.apiUrl}/UpdateUser?id=${id}`, request, { + withCredentials: true, + }) + .subscribe({ + next: () => { + // this.getUsers(pageSize, pageIndex); + this.notification.next({ + status: true, + message: 'User updated successfully!', + }); + }, + error: (error) => { + this.notification.next({ + status: false, + message: error, + }); + }, + }); } getUserById(id: string) { - console.log(id); return {} as UserData; } } From b2dbf42885572ae521c2373b5ea7510b6807e8af Mon Sep 17 00:00:00 2001 From: Mojtaba Erfan Rad Date: Wed, 21 Aug 2024 16:41:07 +0330 Subject: [PATCH 13/16] fix(manage-user): show role in table --- .../dashboard/manage-users/manage-users.component.html | 5 +++++ .../dashboard/manage-users/manage-users.component.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/user/components/dashboard/manage-users/manage-users.component.html b/src/app/user/components/dashboard/manage-users/manage-users.component.html index 9cece50..828a325 100644 --- a/src/app/user/components/dashboard/manage-users/manage-users.component.html +++ b/src/app/user/components/dashboard/manage-users/manage-users.component.html @@ -27,6 +27,11 @@ {{ element.email }} + + Role + {{ element.roleName }} + + edit/delete diff --git a/src/app/user/components/dashboard/manage-users/manage-users.component.ts b/src/app/user/components/dashboard/manage-users/manage-users.component.ts index 3a2663c..d5f7466 100644 --- a/src/app/user/components/dashboard/manage-users/manage-users.component.ts +++ b/src/app/user/components/dashboard/manage-users/manage-users.component.ts @@ -24,6 +24,7 @@ export class ManageUsersComponent implements OnInit { 'fullName', 'phoneNumber', 'email', + 'roleName', 'edit/delete', ]; length!: number; @@ -39,7 +40,7 @@ export class ManageUsersComponent implements OnInit { constructor( private readonly dialog: MatDialog, private adminService: AdminService, - private _snackBar: MatSnackBar, + private _snackBar: MatSnackBar ) {} ngOnInit(): void { From 8bb5edf917e2761d64f6166b062a7bf6ceab25a6 Mon Sep 17 00:00:00 2001 From: Zahra Masoumi Date: Wed, 21 Aug 2024 17:15:17 +0330 Subject: [PATCH 14/16] fix(dashboard): fix real time operations and hover rows --- .../add-user/add-user.component.ts | 26 ++++++++------ .../edit-user/edit-user.component.ts | 34 ++++++++++++++----- .../manage-users/manage-users.component.scss | 4 +++ .../manage-users/manage-users.component.ts | 14 ++++++-- .../user-delete-confirmation.component.ts | 14 ++++---- src/app/user/services/admin/admin.service.ts | 22 ++++++------ src/styles.scss | 5 ++- 7 files changed, 78 insertions(+), 41 deletions(-) diff --git a/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts b/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts index 5a61bb5..5d5dc00 100644 --- a/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts +++ b/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts @@ -1,7 +1,7 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, Inject, OnInit } from '@angular/core'; import { AdminService } from '../../../../services/admin/admin.service'; import { FormControl, FormGroup, Validators } from '@angular/forms'; -import { UserData } from '../../../../interfaces/manage-users.interface'; +import { MAT_DIALOG_DATA } from '@angular/material/dialog'; @Component({ selector: 'app-add-user', @@ -9,18 +9,20 @@ import { UserData } from '../../../../interfaces/manage-users.interface'; styleUrl: './add-user.component.scss', }) export class AddUserComponent implements OnInit { - constructor(private adminService: AdminService) {} + constructor( + private adminService: AdminService, + @Inject(MAT_DIALOG_DATA) + protected page: { + pagSize: number; + pageIndex: number; + }, + ) {} myForm: FormGroup = new FormGroup({}); ngOnInit() { - const userData: UserData = this.adminService.getUserById('some-id'); - this.myForm = new FormGroup({ - firstName: new FormControl( - userData ? userData.firstName : '', - Validators.required, - ), + firstName: new FormControl('', Validators.required), lastName: new FormControl('', Validators.required), username: new FormControl('', Validators.required), password: new FormControl('', Validators.required), @@ -36,7 +38,11 @@ export class AddUserComponent implements OnInit { onSubmit() { if (this.myForm.valid) { - this.adminService.createUser(this.myForm.value); + this.adminService.createUser( + this.myForm.value, + this.page.pagSize, + this.page.pageIndex, + ); } } } diff --git a/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.ts b/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.ts index f580890..9f2c9a8 100644 --- a/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.ts +++ b/src/app/user/components/dashboard/manage-users/edit-user/edit-user.component.ts @@ -13,31 +13,49 @@ export class EditUserComponent implements OnInit { constructor( private adminService: AdminService, @Inject(MAT_DIALOG_DATA) - protected userData: UserData, + protected pageData: { + user: UserData; + pagSize: number; + pageIndex: number; + }, ) {} myForm: FormGroup = new FormGroup({}); ngOnInit() { this.myForm = new FormGroup({ - firstName: new FormControl(this.userData.firstName, Validators.required), - lastName: new FormControl(this.userData.lastName, Validators.required), - username: new FormControl(this.userData.username, Validators.required), - email: new FormControl(this.userData.email, [ + firstName: new FormControl( + this.pageData.user.firstName, + Validators.required, + ), + lastName: new FormControl( + this.pageData.user.lastName, + Validators.required, + ), + username: new FormControl( + this.pageData.user.username, + Validators.required, + ), + email: new FormControl(this.pageData.user.email, [ Validators.required, Validators.email, ]), - phoneNumber: new FormControl(this.userData.phoneNumber, [ + phoneNumber: new FormControl(this.pageData.user.phoneNumber, [ Validators.required, Validators.pattern('^[0-9]*$'), ]), - roleName: new FormControl(this.userData.roleName), + roleName: new FormControl(this.pageData.user.roleName), }); } onSubmit() { if (this.myForm.valid) { - this.adminService.updateUser(this.userData.guid, this.myForm.value); + this.adminService.updateUser( + this.pageData.user.guid, + this.myForm.value, + this.pageData.pagSize, + this.pageData.pageIndex, + ); } } } diff --git a/src/app/user/components/dashboard/manage-users/manage-users.component.scss b/src/app/user/components/dashboard/manage-users/manage-users.component.scss index 4d7836c..cb5fb0d 100644 --- a/src/app/user/components/dashboard/manage-users/manage-users.component.scss +++ b/src/app/user/components/dashboard/manage-users/manage-users.component.scss @@ -8,6 +8,10 @@ margin-block-end: 1rem; } +tr:hover { + background-color: var(--hover-bg-color); +} + .header-container { display: flex; justify-content: space-between; diff --git a/src/app/user/components/dashboard/manage-users/manage-users.component.ts b/src/app/user/components/dashboard/manage-users/manage-users.component.ts index d5f7466..cd14ef6 100644 --- a/src/app/user/components/dashboard/manage-users/manage-users.component.ts +++ b/src/app/user/components/dashboard/manage-users/manage-users.component.ts @@ -40,7 +40,7 @@ export class ManageUsersComponent implements OnInit { constructor( private readonly dialog: MatDialog, private adminService: AdminService, - private _snackBar: MatSnackBar + private _snackBar: MatSnackBar, ) {} ngOnInit(): void { @@ -77,13 +77,21 @@ export class ManageUsersComponent implements OnInit { addUser() { this.dialog.open(AddUserComponent, { width: '105rem', + data: { + pagSize: this.pageSize, + pageIndex: this.pageIndex, + }, }); } editUser(userData: UserData) { this.dialog.open(EditUserComponent, { width: '105rem', - data: userData, + data: { + user: userData, + pagSize: this.pageSize, + pageIndex: this.pageIndex, + }, }); } @@ -91,7 +99,7 @@ export class ManageUsersComponent implements OnInit { this.dialog.open(UserDeleteConfirmationComponent, { width: '22rem', data: { - userData: userData, + user: userData, pagSize: this.pageSize, pageIndex: this.pageIndex, }, diff --git a/src/app/user/components/dashboard/manage-users/user-delete-confirmation/user-delete-confirmation.component.ts b/src/app/user/components/dashboard/manage-users/user-delete-confirmation/user-delete-confirmation.component.ts index cf7aaed..1b1de79 100644 --- a/src/app/user/components/dashboard/manage-users/user-delete-confirmation/user-delete-confirmation.component.ts +++ b/src/app/user/components/dashboard/manage-users/user-delete-confirmation/user-delete-confirmation.component.ts @@ -8,7 +8,7 @@ import { AdminService } from '../../../../services/admin/admin.service'; template: `

Delete User

- Would you like to delete {{ this.userData.userData.username }}{{ this.pageData.user.username }}? @@ -27,19 +27,19 @@ import { AdminService } from '../../../../services/admin/admin.service'; export class UserDeleteConfirmationComponent { constructor( @Inject(MAT_DIALOG_DATA) - protected userData: { - userData: UserData; + protected pageData: { + user: UserData; pagSize: number; pageIndex: number; }, - private adminService: AdminService + private adminService: AdminService, ) {} deleteUser() { this.adminService.deleteUser( - this.userData.userData.guid, - this.userData.pagSize, - this.userData.pageIndex + this.pageData.user.guid, + this.pageData.pagSize, + this.pageData.pageIndex, ); } } diff --git a/src/app/user/services/admin/admin.service.ts b/src/app/user/services/admin/admin.service.ts index 4dff5cc..a453cb4 100644 --- a/src/app/user/services/admin/admin.service.ts +++ b/src/app/user/services/admin/admin.service.ts @@ -1,10 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { RegisterRequest, UpdateUserRequest } from '../../models/User'; -import { - GetUserResponse, - UserData, -} from '../../interfaces/manage-users.interface'; +import { GetUserResponse } from '../../interfaces/manage-users.interface'; import { Subject } from 'rxjs'; import { environment } from '../../../../../api-config/api-url'; @@ -21,14 +18,14 @@ export class AdminService { constructor(private http: HttpClient) {} - createUser(request: RegisterRequest) { + createUser(request: RegisterRequest, pageSize: number, pageIndex: number) { return this.http .post(`${this.apiUrl}/register`, request, { withCredentials: true, }) .subscribe({ next: () => { - // this.getUsers(pageSize, pageIndex); + this.getUsers(pageSize, pageIndex); this.notification.next({ status: true, message: 'User added successfully!', @@ -78,14 +75,19 @@ export class AdminService { }); } - updateUser(id: string, request: UpdateUserRequest) { + updateUser( + id: string, + request: UpdateUserRequest, + pageSize: number, + pageIndex: number, + ) { return this.http .put(`${this.apiUrl}/UpdateUser?id=${id}`, request, { withCredentials: true, }) .subscribe({ next: () => { - // this.getUsers(pageSize, pageIndex); + this.getUsers(pageSize, pageIndex); this.notification.next({ status: true, message: 'User updated successfully!', @@ -99,8 +101,4 @@ export class AdminService { }, }); } - - getUserById(id: string) { - return {} as UserData; - } } diff --git a/src/styles.scss b/src/styles.scss index 880ff2c..38010ed 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -4,7 +4,8 @@ @include mat.core(); @font-face { font-family: "MyCustomFont"; - src: url("../assets/font/Vazir.ttf") format("truetype"), + src: + url("../assets/font/Vazir.ttf") format("truetype"), url("../assets/font/Vazir.woff") format("woff"), url("../assets/font/Vazir.woff2") format("woff2"), url("../assets/font/Vazir.eot") format("embedded-opentype"); @@ -295,6 +296,7 @@ body, --nav-link-text-color-active: rgba(27, 89, 248, 1); --card-background-color: #fefbff; --mat-sidenav-content-background-color: #fbf8fd; + --hover-bg-color: #e0e0e0; --logo-image-filter: invert(20%); --logo-filter: invert(10%); @@ -311,6 +313,7 @@ body, --mat-sidenav-container-background-color: #1f1f23; --mat-table-background-color: #292a2d; --mat-paginator-container-background-color: #292a2d; + --hover-bg-color: #333333; --logo-image-filter: invert(75%); --logo-filter: invert(85%); From fe5e6c3b31b1808a5196725ac8aa996d75f8127b Mon Sep 17 00:00:00 2001 From: Mojtaba Erfan Rad Date: Wed, 21 Aug 2024 18:35:47 +0330 Subject: [PATCH 15/16] fix(bug): some minor fixes --- .../dashboard-header/dashboard-header.component.html | 10 ++++++++-- .../manage-users/add-user/add-user.component.ts | 4 ++-- src/app/user/services/admin/admin.service.ts | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/app/shared/components/dashboard-header/dashboard-header.component.html b/src/app/shared/components/dashboard-header/dashboard-header.component.html index 5addaee..5929b87 100644 --- a/src/app/shared/components/dashboard-header/dashboard-header.component.html +++ b/src/app/shared/components/dashboard-header/dashboard-header.component.html @@ -1,15 +1,21 @@

{{ title }}

- settings routine - info + info
diff --git a/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts b/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts index 5d5dc00..a8312fa 100644 --- a/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts +++ b/src/app/user/components/dashboard/manage-users/add-user/add-user.component.ts @@ -15,7 +15,7 @@ export class AddUserComponent implements OnInit { protected page: { pagSize: number; pageIndex: number; - }, + } ) {} myForm: FormGroup = new FormGroup({}); @@ -41,7 +41,7 @@ export class AddUserComponent implements OnInit { this.adminService.createUser( this.myForm.value, this.page.pagSize, - this.page.pageIndex, + this.page.pageIndex ); } } diff --git a/src/app/user/services/admin/admin.service.ts b/src/app/user/services/admin/admin.service.ts index a453cb4..6bcb04e 100644 --- a/src/app/user/services/admin/admin.service.ts +++ b/src/app/user/services/admin/admin.service.ts @@ -46,7 +46,7 @@ export class AdminService { `${this.apiUrl}/GetUsersPagination?limit=${limit}&page=${page}`, { withCredentials: true, - }, + } ) .subscribe((users) => { this.usersData.next(users); From 7991defd3e8ce1eb7d83fb59d30f4449a77002d5 Mon Sep 17 00:00:00 2001 From: Zahra Masoumi Date: Sat, 24 Aug 2024 09:38:32 +0330 Subject: [PATCH 16/16] fix(config) --- angular.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/angular.json b/angular.json index 74cc76d..dc3b2e2 100644 --- a/angular.json +++ b/angular.json @@ -57,8 +57,8 @@ "outputHashing": "all", "fileReplacements": [ { - "replace": "api-config/api-url.prod.ts", - "with": "api-config/api-url.ts" + "replace": "api-config/api-url.ts", + "with": "api-config/api-url.prod.ts" } ] },