fix(scheduler): Update Timeline to use apiClient for authenticated resource fetching

The Timeline component was using a raw axios instance with hardcoded URLs, causing it to bypass authentication and tenant context headers. This resulted in empty or failed data fetches. Updated it to use the configured 'apiClient', ensuring that the authentication token and 'X-Business-Subdomain' headers are correctly sent, allowing the backend to return the appropriate tenant-specific resources and appointments.
This commit is contained in:
poduck
2025-12-01 02:32:48 -05:00
parent 5cd689af0a
commit 980b5d36aa

View File

@@ -30,7 +30,7 @@ import { DEFAULT_PIXELS_PER_HOUR, SNAP_MINUTES } from '../../lib/timelineUtils';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { adaptResources, adaptEvents, adaptPending } from '../../lib/uiAdapter'; import { adaptResources, adaptEvents, adaptPending } from '../../lib/uiAdapter';
import axios from 'axios'; import apiClient from '../../api/client';
type ViewMode = 'day' | 'week' | 'month'; type ViewMode = 'day' | 'week' | 'month';
@@ -39,7 +39,7 @@ export const Timeline: React.FC = () => {
const { data: resources = [] } = useQuery({ const { data: resources = [] } = useQuery({
queryKey: ['resources'], queryKey: ['resources'],
queryFn: async () => { queryFn: async () => {
const response = await axios.get('http://api.lvh.me:8000/resources/'); const response = await apiClient.get('/resources/');
return adaptResources(response.data); return adaptResources(response.data);
} }
}); });
@@ -47,7 +47,7 @@ export const Timeline: React.FC = () => {
const { data: backendAppointments = [] } = useQuery({ // Renamed to backendAppointments to avoid conflict with localEvents const { data: backendAppointments = [] } = useQuery({ // Renamed to backendAppointments to avoid conflict with localEvents
queryKey: ['appointments'], queryKey: ['appointments'],
queryFn: async () => { queryFn: async () => {
const response = await axios.get('http://api.lvh.me:8000/appointments/'); const response = await apiClient.get('/appointments/');
return response.data; // Still return raw data, adapt in useEffect return response.data; // Still return raw data, adapt in useEffect
} }
}); });