diff --git a/src/hooks/useApiOnMount.ts b/src/hooks/useApiOnMount.ts index 14f03f04..7f0181b5 100644 --- a/src/hooks/useApiOnMount.ts +++ b/src/hooks/useApiOnMount.ts @@ -15,16 +15,20 @@ import { useApi } from './useApi'; // Correctly import from the same directory * - `error`: An `Error` object if the request fails, otherwise `null`. * - `data`: The data returned from the API, or `null` initially. */ -export function useApiOnMount( - apiFunction: (...args: any[]) => Promise, +export function useApiOnMount( + apiFunction: (...args: TArgs) => Promise, deps: React.DependencyList = [], - ...args: Parameters + ...args: TArgs ) { - const { execute, ...rest } = useApi(apiFunction); + // Pass the generic types through to the underlying useApi hook for full type safety. + const { execute, ...rest } = useApi(apiFunction); useEffect(() => { execute(...args); - }, deps); + // The `deps` array is passed in by the consumer of the hook. + // We disable the exhaustive-deps rule here because `execute` and `args` are intentionally excluded. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, deps); return rest; } \ No newline at end of file diff --git a/src/pages/admin/components/ProfileManager.tsx b/src/pages/admin/components/ProfileManager.tsx index 24fd78c5..91a581b3 100644 --- a/src/pages/admin/components/ProfileManager.tsx +++ b/src/pages/admin/components/ProfileManager.tsx @@ -36,20 +36,20 @@ export const ProfileManager: React.FC = ({ isOpen, onClose, // Profile state const [fullName, setFullName] = useState(profile?.full_name || ''); const [avatarUrl, setAvatarUrl] = useState(profile?.avatar_url || ''); - const { execute: updateProfile, loading: profileLoading } = useApi(apiClient.updateUserProfile); + const { execute: updateProfile, loading: profileLoading } = useApi]>(apiClient.updateUserProfile); // Password state const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); - const { execute: updatePassword, loading: passwordLoading } = useApi(apiClient.updateUserPassword); + const { execute: updatePassword, loading: passwordLoading } = useApi(apiClient.updateUserPassword); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); // Data & Privacy state - const { execute: exportData, loading: exportLoading } = useApi(apiClient.exportUserData); - const { execute: deleteAccount, loading: deleteLoading } = useApi(apiClient.deleteUserAccount); + const { execute: exportData, loading: exportLoading } = useApi(apiClient.exportUserData); + const { execute: deleteAccount, loading: deleteLoading } = useApi(apiClient.deleteUserAccount); // Preferences state - const { execute: updatePreferences } = useApi(apiClient.updateUserPreferences); + const { execute: updatePreferences } = useApi]>(apiClient.updateUserPreferences); const [isConfirmingDelete, setIsConfirmingDelete] = useState(false); const [passwordForDelete, setPasswordForDelete] = useState(''); @@ -62,9 +62,9 @@ export const ProfileManager: React.FC = ({ isOpen, onClose, const [authAvatarUrl, setAuthAvatarUrl] = useState(''); // State for avatar URL const [isForgotPassword, setIsForgotPassword] = useState(false); const [rememberMe, setRememberMe] = useState(false); - const { execute: executeLogin, loading: loginLoading } = useApi(apiClient.loginUser); - const { execute: executeRegister, loading: registerLoading } = useApi(apiClient.registerUser); - const { execute: executePasswordReset, loading: passwordResetLoading } = useApi<{ message: string }>(apiClient.requestPasswordReset); + const { execute: executeLogin, loading: loginLoading } = useApi(apiClient.loginUser); + const { execute: executeRegister, loading: registerLoading } = useApi(apiClient.registerUser); + const { execute: executePasswordReset, loading: passwordResetLoading } = useApi<{ message: string }, [string]>(apiClient.requestPasswordReset); useEffect(() => { diff --git a/src/services/apiClient.ts b/src/services/apiClient.ts index 37dcdb64..da9c261e 100644 --- a/src/services/apiClient.ts +++ b/src/services/apiClient.ts @@ -747,7 +747,7 @@ export async function updateUserPreferences(preferences: Partial { +export async function updateUserProfile(profileData: Partial, tokenOverride?: string): Promise { return apiFetch(`${API_BASE_URL}/users/profile`, { method: 'PUT', headers: { 'Content-Type': 'application/json' },