Remove profile component
This commit is contained in:
@@ -5,7 +5,6 @@ import {AppLayoutComponent} from './layout/component/layout-main/app.layout.comp
|
||||
import {LoginComponent} from './core/component/login/login.component';
|
||||
import {AuthGuard} from './auth.guard';
|
||||
import {SettingsComponent} from './settings/settings.component';
|
||||
import {ProfileComponent} from './profile/profile.component';
|
||||
import {PdfViewerComponent} from './book/components/pdf-viewer/pdf-viewer.component';
|
||||
import {EpubViewerComponent} from './book/components/epub-viewer/component/epub-viewer.component';
|
||||
import {ChangePasswordComponent} from './core/component/change-password/change-password.component';
|
||||
@@ -23,7 +22,6 @@ export const routes: Routes = [
|
||||
children: [
|
||||
{path: 'dashboard', component: MainDashboardComponent, canActivate: [AuthGuard]},
|
||||
{path: 'all-books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
||||
{path: 'profile', component: ProfileComponent, canActivate: [AuthGuard]},
|
||||
{path: 'settings', component: SettingsComponent, canActivate: [AuthGuard]},
|
||||
{path: 'library/:libraryId/books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
||||
{path: 'shelf/:shelfId/books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<div class="card mx-auto max-w-2xl" *ngIf="currentUser">
|
||||
<div class="p-6 space-y-8">
|
||||
|
||||
<!-- Profile Info -->
|
||||
<section class="space-y-6">
|
||||
<div class="flex justify-between items-center">
|
||||
<h2 class="text-2xl font-semibold">Profile Information</h2>
|
||||
<div class="flex gap-2">
|
||||
<p-button *ngIf="!isEditing" label="Edit Profile" icon="pi pi-pencil" (onClick)="toggleEdit()" styleClass="p-button-sm p-button-secondary"></p-button>
|
||||
<div *ngIf="isEditing" class="flex gap-2">
|
||||
<p-button label="Cancel" icon="pi pi-times" (onClick)="toggleEdit()" styleClass="p-button-sm p-button-secondary"></p-button>
|
||||
<p-button label="Save" icon="pi pi-check" (onClick)="saveChanges()" styleClass="p-button-sm p-button-success"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-1">Username</label>
|
||||
<p *ngIf="!isEditing" class="text-lg">{{ currentUser.username }}</p>
|
||||
<input *ngIf="isEditing" id="username" type="text" pInputText [(ngModel)]="currentUser.username" class="w-full" disabled />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-1">Full Name</label>
|
||||
<p *ngIf="!isEditing" class="text-lg">{{ currentUser.name }}</p>
|
||||
<input *ngIf="isEditing" id="fullname" type="text" pInputText [(ngModel)]="editUserData.name" class="w-full" />
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="block text-sm font-medium mb-1">Email</label>
|
||||
<p *ngIf="!isEditing" class="text-lg">{{ currentUser.email }}</p>
|
||||
<input *ngIf="isEditing" id="email" type="email" pInputText [(ngModel)]="editUserData.email" class="w-full" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<!-- Change Password -->
|
||||
<section class="space-y-6">
|
||||
<h2 class="text-2xl font-semibold">Change Password</h2>
|
||||
<form #changePasswordForm="ngForm" (ngSubmit)="submitPasswordChange()" class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-1" for="currentPassword">Current Password</label>
|
||||
<p-password id="currentPassword" [(ngModel)]="currentPassword" name="currentPassword" [feedback]="false" class="w-full" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-1" for="newPassword">New Password</label>
|
||||
<p-password id="newPassword" [(ngModel)]="newPassword" name="newPassword" [feedback]="false" class="w-full" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-1" for="confirmNewPassword">Confirm New Password</label>
|
||||
<p-password id="confirmNewPassword" [(ngModel)]="confirmNewPassword" name="confirmNewPassword" [feedback]="false" class="w-full" />
|
||||
</div>
|
||||
<div class="flex justify-end">
|
||||
<p-button type="submit" label="Change Password" icon="pi pi-key" class="p-button-sm p-button-primary" />
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="!currentUser" class="flex items-center justify-center min-h-[50vh] text-lg">
|
||||
Loading user data...
|
||||
</div>
|
||||
@@ -1,135 +0,0 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {NgIf} from '@angular/common';
|
||||
import {User, UserService} from '../user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Password} from 'primeng/password';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
import {Divider} from 'primeng/divider';
|
||||
|
||||
@Component({
|
||||
selector: 'app-profile',
|
||||
standalone: true,
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
NgIf,
|
||||
Password,
|
||||
InputTextModule,
|
||||
ToastModule,
|
||||
Divider,
|
||||
],
|
||||
templateUrl: './profile.component.html',
|
||||
styleUrl: './profile.component.scss',
|
||||
})
|
||||
export class ProfileComponent implements OnInit, OnDestroy {
|
||||
protected userService = inject(UserService);
|
||||
private messageService = inject(MessageService);
|
||||
|
||||
currentPassword: string = '';
|
||||
newPassword: string = '';
|
||||
confirmNewPassword: string = '';
|
||||
|
||||
isEditing = false;
|
||||
currentUser: User | null = null;
|
||||
editUserData: Partial<User> = {};
|
||||
private userSubscription: Subscription | null = null;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userSubscription = this.userService.userData$.subscribe(user => {
|
||||
this.currentUser = user;
|
||||
this.resetEditForm();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.userSubscription?.unsubscribe();
|
||||
}
|
||||
|
||||
toggleEdit(): void {
|
||||
this.isEditing = !this.isEditing;
|
||||
if (this.isEditing) {
|
||||
this.resetEditForm();
|
||||
}
|
||||
}
|
||||
|
||||
resetEditForm(): void {
|
||||
if (this.currentUser) {
|
||||
this.editUserData = {
|
||||
username: this.currentUser.username,
|
||||
name: this.currentUser.name,
|
||||
email: this.currentUser.email,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
saveChanges(): void {
|
||||
if (!this.currentUser) {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'User data not available.'});
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.editUserData.name === this.currentUser.name && this.editUserData.email === this.currentUser.email) {
|
||||
this.messageService.add({severity: 'info', summary: 'Info', detail: 'No changes detected.'});
|
||||
this.isEditing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.userService.updateUser(this.currentUser.id, this.editUserData).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'success', summary: 'Success', detail: 'Profile updated successfully'});
|
||||
this.isEditing = false;
|
||||
this.resetEditForm();
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: err.error?.message || 'Failed to update profile'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
resetPasswordForm(): void {
|
||||
this.currentPassword = '';
|
||||
this.newPassword = '';
|
||||
this.confirmNewPassword = '';
|
||||
}
|
||||
|
||||
submitPasswordChange() {
|
||||
if (!this.currentUser) {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'User data not available.'});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.currentPassword || !this.newPassword || !this.confirmNewPassword) {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'All fields are required'});
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.newPassword !== this.confirmNewPassword) {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Passwords do not match'});
|
||||
this.newPassword = '';
|
||||
this.confirmNewPassword = '';
|
||||
return;
|
||||
}
|
||||
|
||||
this.userService.changePassword(this.currentPassword, this.newPassword).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'success', summary: 'Success', detail: 'Password changed successfully'});
|
||||
this.resetPasswordForm();
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: err?.message || 'Failed to change password'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user