diff --git a/apps/frontend/app/dashboard/profile/page.tsx b/apps/frontend/app/dashboard/profile/page.tsx index 96b3a25..13249e2 100644 --- a/apps/frontend/app/dashboard/profile/page.tsx +++ b/apps/frontend/app/dashboard/profile/page.tsx @@ -6,7 +6,7 @@ 'use client'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useAuth } from '@/lib/context/auth-context'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { useForm } from 'react-hook-form'; @@ -44,7 +44,7 @@ const profileSchema = z.object({ type ProfileFormData = z.infer; export default function ProfilePage() { - const { user, refreshUser } = useAuth(); + const { user, refreshUser, loading } = useAuth(); const queryClient = useQueryClient(); const [activeTab, setActiveTab] = useState<'profile' | 'password'>('profile'); const [successMessage, setSuccessMessage] = useState(''); @@ -65,6 +65,18 @@ export default function ProfilePage() { resolver: zodResolver(passwordSchema), }); + // Update form values when user data loads + useEffect(() => { + if (user) { + profileForm.reset({ + firstName: user.firstName, + lastName: user.lastName, + email: user.email, + }); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [user]); + // Update profile mutation const updateProfileMutation = useMutation({ mutationFn: (data: ProfileFormData) => { @@ -112,6 +124,35 @@ export default function ProfilePage() { updatePasswordMutation.mutate(data); }; + // Show loading state while user data is being fetched + if (loading) { + return ( +
+
+
+

Loading profile...

+
+
+ ); + } + + // Show error if user is not found after loading + if (!loading && !user) { + return ( +
+
+

Unable to load user profile

+ +
+
+ ); + } + return (
{/* Header */} diff --git a/apps/frontend/lib/api/users.ts b/apps/frontend/lib/api/users.ts index 87f6d80..0ab2ccb 100644 --- a/apps/frontend/lib/api/users.ts +++ b/apps/frontend/lib/api/users.ts @@ -103,7 +103,7 @@ export const usersApi = { /** * Change password */ - async changePassword(data: ChangePasswordRequest): Promise { - return apiClient.post('/api/v1/users/change-password', data); + async changePassword(data: ChangePasswordRequest): Promise<{ message: string }> { + return apiClient.patch<{ message: string }>('/api/v1/users/me/password', data); }, };