diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/forms/rep-create-form/rep-create-form.component.html b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/forms/rep-create-form/rep-create-form.component.html
index 1cf2d01..03f69d2 100644
--- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/forms/rep-create-form/rep-create-form.component.html
+++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/forms/rep-create-form/rep-create-form.component.html
@@ -1 +1 @@
-
rep-create-form works!
+
\ No newline at end of file
diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/forms/rep-create-form/rep-create-form.component.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/forms/rep-create-form/rep-create-form.component.ts
index aacf930..0d459f4 100644
--- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/forms/rep-create-form/rep-create-form.component.ts
+++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/forms/rep-create-form/rep-create-form.component.ts
@@ -1,6 +1,8 @@
import { Component, inject } from '@angular/core';
import { UserRep } from '../../../models/user-management.api.models';
-import { MAT_DIALOG_DATA } from '@angular/material/dialog';
+import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
+import { UserRepService } from '../../../services/api/user-representation.service';
+import { GroupUpdateFormComponent } from '../group-update-form/group-update-form.component';
@Component({
selector: 'app-rep-create-form',
@@ -11,6 +13,26 @@ import { MAT_DIALOG_DATA } from '@angular/material/dialog';
})
export class RepCreateFormComponent {
- readonly userRep: UserRep = inject(MAT_DIALOG_DATA)
+ readonly userRep: UserRep;
+ readonly afterCreation: (any: any) => any;
+ readonly userRepService: UserRepService = inject(UserRepService);
+ readonly dialogRef: MatDialogRef = inject(MatDialogRef);
+ constructor() {
+ const dialogData: { userRep: UserRep, afterCreation: (any: any) => any } = inject(MAT_DIALOG_DATA)
+ this.userRep = dialogData.userRep;
+ this.afterCreation = dialogData.afterCreation;
+ }
+
+ create() {
+ this.userRepService.create(this.userRep).subscribe({
+ next: (res) => {
+ this.afterCreation({ successful: res });
+ this.dialogRef.close();
+ },
+ error: (error) => {
+ this.afterCreation({ error: error });
+ }
+ });
+ }
}
\ No newline at end of file
diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.ts
index 60b4110..3d02507 100644
--- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.ts
+++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.ts
@@ -105,10 +105,11 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
groupId: this.slGroupId,
repUserId: this.slRepUserId,
validFrom: new Date(),
- validTo: new Date(new Date().setDate(new Date().getDate() + 7)) //after one week
+ validTo: new Date(new Date().setDate(new Date().getDate() + 7))
}
- this.userRepService.create(newUserRep).subscribe({
- next: (response) => {
+
+ this.openCreateSheet(newUserRep, res => {
+ if (res.successful) {
this.slRepUserId = undefined;
this.repUsers.safelyUnselectAll()
@@ -117,8 +118,8 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
this.userReps.fetchByUser(this.slUserId)
if (this.slGroupId)
this.userReps.fetchByGroup(this.slGroupId)
- },
- error: (error) => {
+ }
+ else if (res.error) {
Swal.fire({
icon: "error",
title: "Oops...",
@@ -157,8 +158,9 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
groupId: this.slGroupId,
repGroupId: this.slRepGroupId,
}
- this.userRepService.create(newUserRep).subscribe({
- next: (res) => {
+
+ this.openCreateSheet(newUserRep, res => {
+ if (res.successful) {
this.slRepGroupId = undefined;
this.repUsers.safelyUnselectAll()
this.groups.safelyUnselectAll()
@@ -166,8 +168,8 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
this.userReps.fetchByUser(this.slUserId)
if (this.slGroupId)
this.userReps.fetchByGroup(this.slGroupId)
- },
- error: (error) => {
+ }
+ else if (res.error) {
Swal.fire({
icon: "error",
title: "Oops...",
@@ -211,10 +213,11 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
}
}
- openUpdateSheet(userRep: UserRep): void {
+ openCreateSheet(userRep: UserRep, afterCreation: (any: any) => any): void {
+
this.dialog.open(RepCreateFormComponent, {
width: "50rem",
- data: userRep
+ data: { userRep: userRep, afterCreation: afterCreation }
});
}
-}
\ No newline at end of file
+}