onSubmit() { if (this.profileForm.valid) { const userId = JSON.parse(localStorage.getItem('User')!).userId; this.userService.updateUser(userId, this.profileForm.value).subscribe({ next: (result) => { console.log('User to be updated:', result); this.router.navigateByUrl(`/ProfilePage/${userId}`); alert('Successfully updated profile'); }, error: () => { console.error('Error updating user profile:'); alert('Error updating profile'); } }); } } onPhotoChange(event: Event): void { if (!this.isEditMode) return; const input = event.target as HTMLInputElement; if (input.files && input.files[0]) { const reader = new FileReader(); reader.onload = (e: any) => { this.userProfileImage = e.target.result; // Update the image source this.profileForm.patchValue({ photo: e.target.result }); // Update the form control }; reader.readAsDataURL(input.files[0]); } }