- Added user update modal

- Refactored modal logic
This commit is contained in:
2024-06-01 01:17:28 +02:00
parent e3b1891d11
commit fb4d47b7bf
4 changed files with 125 additions and 0 deletions

View 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;
}
}
}