- Added user update modal
- Refactored modal logic
This commit is contained in:
60
frontend/src/app/adminui/edituser/edituser.component.ts
Normal file
60
frontend/src/app/adminui/edituser/edituser.component.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import {Component, Input, SimpleChanges} from '@angular/core';
|
||||
import {FormsModule} from "@angular/forms";
|
||||
import axios from "axios";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
import {DevelopmentStore} from "../../../store/DevelopmentStore";
|
||||
import {AuthStore} from "../../../store/authStore";
|
||||
|
||||
@Component({
|
||||
selector: 'app-edituser',
|
||||
standalone: true,
|
||||
imports: [
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './edituser.component.html',
|
||||
styleUrl: './edituser.component.scss'
|
||||
})
|
||||
export class EdituserComponent {
|
||||
@Input("username") parsedUsername: string = "";
|
||||
username: string = "";
|
||||
originalPassword: string = "";
|
||||
newPassword: string = "";
|
||||
confirmPassword: string = "";
|
||||
|
||||
constructor(private developmentStore: DevelopmentStore, private authStore: AuthStore) {}
|
||||
|
||||
async saveUser() {
|
||||
|
||||
if(this.newPassword !== this.confirmPassword) {
|
||||
alert("New password and confirm password do not match");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios({
|
||||
method: 'post',
|
||||
url: this.developmentStore.getBaseUrl() + 'api/v1/secure/user/update',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + await firstValueFrom(this.authStore.token$)
|
||||
},
|
||||
data: {
|
||||
username: this.username,
|
||||
originalPassword: this.originalPassword,
|
||||
newPassword: this.newPassword,
|
||||
confirmPassword: this.confirmPassword
|
||||
}
|
||||
});
|
||||
// TODO: Implement backend logic for this
|
||||
console.log("User updated successfully");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes['parsedUsername'] && !this.username) {
|
||||
this.username = changes['parsedUsername'].currentValue;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user