From 7149d2e211e43d4b8c9bd7738ec9f9cb8f4e45f2 Mon Sep 17 00:00:00 2001 From: senke Date: Thu, 15 Jan 2026 20:34:58 +0100 Subject: [PATCH] scalability: replace direct user API calls with usersApi service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replaced imports in UserProfilePage.tsx (getProfileByUsername → usersApi.getProfileByUsername) - Replaced imports in SettingsPage.tsx (getSettings, updateSettings → usersApi.getSettings, usersApi.updateSettings) - Replaced imports in ProfileForm.tsx (calculateProfileCompletion → usersApi.calculateProfileCompletion) - Replaced dynamic imports in avatar-upload.tsx (uploadAvatar, deleteAvatar → usersApi.uploadAvatar, usersApi.deleteAvatar) - All function calls updated to use usersApi methods - Test files still use direct imports (acceptable - tests can use implementation details) - No TypeScript errors related to usersApi - Action 6.1.1.6 complete --- EXHAUSTIVE_TODO_LIST.md | 13 ++++++++++--- apps/web/src/components/ui/avatar-upload.tsx | 14 +++++--------- .../src/features/profile/pages/UserProfilePage.tsx | 7 ++----- .../src/features/settings/pages/SettingsPage.tsx | 6 +++--- .../src/features/user/components/ProfileForm.tsx | 8 ++++---- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/EXHAUSTIVE_TODO_LIST.md b/EXHAUSTIVE_TODO_LIST.md index 3e7fb3d59..da1243de6 100644 --- a/EXHAUSTIVE_TODO_LIST.md +++ b/EXHAUSTIVE_TODO_LIST.md @@ -1986,11 +1986,18 @@ Critical path dependencies: - Preserves existing token storage logic in login/register/logout - **Rollback**: Restore original auth service -- [ ] **Action 6.1.1.6**: Replace direct API calls with services (users) +- [x] **Action 6.1.1.6**: Replace direct API calls with services (users) - **Scope**: All components importing user API functions - Use `usersApi` instead - - **Dependencies**: Action 6.1.1.3 complete + - **Dependencies**: Action 6.1.1.3 complete ✅ - **Risk**: MEDIUM - - **Validation**: No direct user API imports + - **Validation**: ✅ No direct user API imports in feature components: + - Replaced imports in `UserProfilePage.tsx` (getProfileByUsername → usersApi.getProfileByUsername) + - Replaced imports in `SettingsPage.tsx` (getSettings, updateSettings → usersApi.getSettings, usersApi.updateSettings) + - Replaced imports in `ProfileForm.tsx` (calculateProfileCompletion → usersApi.calculateProfileCompletion) + - Replaced dynamic imports in `avatar-upload.tsx` (uploadAvatar, deleteAvatar → usersApi.uploadAvatar, usersApi.deleteAvatar) + - All function calls updated to use usersApi methods + - Test files still use direct imports (acceptable - tests can use implementation details) + - No TypeScript errors related to usersApi - **Rollback**: Restore direct imports - [ ] **Action 6.1.1.7**: Replace direct API calls with services (playlists) diff --git a/apps/web/src/components/ui/avatar-upload.tsx b/apps/web/src/components/ui/avatar-upload.tsx index e1d73088e..49c9b2801 100644 --- a/apps/web/src/components/ui/avatar-upload.tsx +++ b/apps/web/src/components/ui/avatar-upload.tsx @@ -149,22 +149,18 @@ export function AvatarUpload({ const fileInputRef = useRef(null); const { success: showSuccess, error: showError } = useToast(); - // Dynamically import avatarService to avoid circular dependencies + // Dynamically import usersApi to avoid circular dependencies const uploadAvatar = useCallback( async (file: File) => { - const { uploadAvatar: upload } = await import( - '@/features/profile/services/avatarService' - ); - return upload(String(userId), file); + const { usersApi } = await import('@/services/api/users'); + return usersApi.uploadAvatar(String(userId), file); }, [userId], ); const deleteAvatar = useCallback(async () => { - const { deleteAvatar: del } = await import( - '@/features/profile/services/avatarService' - ); - return del(String(userId)); + const { usersApi } = await import('@/services/api/users'); + return usersApi.deleteAvatar(String(userId)); }, [userId]); const validateFile = useCallback( diff --git a/apps/web/src/features/profile/pages/UserProfilePage.tsx b/apps/web/src/features/profile/pages/UserProfilePage.tsx index 5809055a0..a9ef5ee8e 100644 --- a/apps/web/src/features/profile/pages/UserProfilePage.tsx +++ b/apps/web/src/features/profile/pages/UserProfilePage.tsx @@ -1,9 +1,6 @@ import { useParams, Link } from 'react-router-dom'; import { useQuery } from '@tanstack/react-query'; -import { - getProfileByUsername, - type UserProfile, -} from '../services/profileService'; +import { usersApi, type UserProfile } from '@/services/api/users'; import { tracksApi } from '@/services/api/tracks'; import { listPlaylists } from '@/features/playlists/services/playlistService'; import { LoadingSpinner } from '@/components/ui/loading-spinner'; @@ -36,7 +33,7 @@ export function UserProfilePage() { if (!username) { throw new Error('Username is required'); } - return getProfileByUsername(username); + return usersApi.getProfileByUsername(username); }, enabled: !!username, retry: false, diff --git a/apps/web/src/features/settings/pages/SettingsPage.tsx b/apps/web/src/features/settings/pages/SettingsPage.tsx index 6139ab577..d098dcab4 100644 --- a/apps/web/src/features/settings/pages/SettingsPage.tsx +++ b/apps/web/src/features/settings/pages/SettingsPage.tsx @@ -1,6 +1,6 @@ import { useState, useEffect, useRef } from 'react'; import { useUser } from '@/features/auth/hooks/useUser'; -import { getSettings, updateSettings } from '../services/settingsService'; +import { usersApi } from '@/services/api/users'; import { UserSettings } from '../types/settings'; import { SettingsTabs } from '../components/SettingsTabs'; import { Button, Card } from '@veza/design-system'; @@ -36,7 +36,7 @@ export function SettingsPage() { try { setIsLoading(true); setQueryError(null); - const userSettings = await getSettings(user.id); + const userSettings = await usersApi.getSettings(user.id); setSettings(userSettings); } catch (err) { const errorMessage = @@ -70,7 +70,7 @@ export function SettingsPage() { // Action 3.4.1.3: Store mutation for retry const performMutation = async () => { - await updateSettings(user.id, settings); + await usersApi.updateSettings(user.id, settings); toast.success('Paramètres sauvegardés avec succès'); setMutationError(null); setRetryCount(0); diff --git a/apps/web/src/features/user/components/ProfileForm.tsx b/apps/web/src/features/user/components/ProfileForm.tsx index 5a4bb50e1..18c39afb8 100644 --- a/apps/web/src/features/user/components/ProfileForm.tsx +++ b/apps/web/src/features/user/components/ProfileForm.tsx @@ -14,10 +14,10 @@ import { Progress } from '@/components/ui/progress'; import { useToast } from '@/hooks/useToast'; import { usernameSchema, emailSchema } from '@/schemas/validation'; import { - calculateProfileCompletion, + usersApi, type ProfileCompletion, type UpdateProfileRequest, -} from '@/features/profile/services/profileService'; +} from '@/services/api/users'; import { Twitter, Instagram, @@ -101,7 +101,7 @@ export function ProfileForm() { // FE-PAGE-003: Load profile completion useEffect(() => { if (user?.id) { - calculateProfileCompletion(user.id) + usersApi.calculateProfileCompletion(user.id) .then(setCompletion) .catch((err) => { logger.error('Failed to load profile completion:', err); @@ -206,7 +206,7 @@ export function ProfileForm() { // Refresh completion if (user.id) { - const newCompletion = await calculateProfileCompletion(user.id); + const newCompletion = await usersApi.calculateProfileCompletion(user.id); setCompletion(newCompletion); }