refactor(frontend): Remove '/api' prefix from all API calls to align with backend URL convention

- Updated all API endpoint strings in 'frontend/src' (via sed and manual fixes) to remove the '/api/' prefix.
- Manually fixed 'Timeline.tsx' absolute URLs to use the 'api' subdomain and correct path.
- Manually fixed 'useAuth.ts' logout fetch URLs.
- Updated 'HelpApiDocs.tsx' sandbox URL.
- This change, combined with the backend URL update, fully transitions the application to use subdomain-based routing (e.g., 'http://api.lvh.me:8000/resource/') instead of path-prefix routing (e.g., 'http://api.lvh.me:8000/api/resource/').
This commit is contained in:
poduck
2025-12-01 02:14:17 -05:00
parent 92724d03b6
commit b3e2c1f324
19 changed files with 92 additions and 82 deletions

View File

@@ -95,8 +95,11 @@ export const useLogout = () => {
queryClient.removeQueries({ queryKey: ['currentUser'] });
queryClient.clear();
// Redirect to login page
window.location.href = '/login';
// Redirect to login page on root domain
const protocol = window.location.protocol;
const baseDomain = getBaseDomain();
const port = window.location.port ? `:${window.location.port}` : '';
window.location.href = `${protocol}//${baseDomain}${port}/login`;
},
});
};
@@ -150,7 +153,7 @@ export const useMasquerade = () => {
// Call logout API to clear HttpOnly sessionid cookie
try {
const apiUrl = import.meta.env.VITE_API_URL || `${window.location.protocol}//${baseDomain}`;
await fetch(`${apiUrl}/api/auth/logout/`, {
await fetch(`${apiUrl}/auth/logout/`, {
method: 'POST',
credentials: 'include',
});
@@ -222,7 +225,7 @@ export const useStopMasquerade = () => {
// CRITICAL: Clear the session cookie BEFORE redirect
try {
const apiUrl = import.meta.env.VITE_API_URL || `${window.location.protocol}//${baseDomain}`;
await fetch(`${apiUrl}/api/auth/logout/`, {
await fetch(`${apiUrl}/auth/logout/`, {
method: 'POST',
credentials: 'include',
});

View File

@@ -23,7 +23,7 @@ export const useCurrentBusiness = () => {
return null; // No token, return null instead of making request
}
const { data } = await apiClient.get('/api/business/current/');
const { data } = await apiClient.get('/business/current/');
// Transform backend format to frontend format
return {
@@ -96,7 +96,7 @@ export const useUpdateBusiness = () => {
backendData.customer_dashboard_content = updates.customerDashboardContent;
}
const { data } = await apiClient.patch('/api/business/current/update/', backendData);
const { data } = await apiClient.patch('/business/current/update/', backendData);
return data;
},
onSuccess: () => {
@@ -112,7 +112,7 @@ export const useResources = () => {
return useQuery({
queryKey: ['resources'],
queryFn: async () => {
const { data } = await apiClient.get('/api/resources/');
const { data } = await apiClient.get('/resources/');
return data;
},
staleTime: 5 * 60 * 1000, // 5 minutes
@@ -127,7 +127,7 @@ export const useCreateResource = () => {
return useMutation({
mutationFn: async (resourceData: { name: string; type: string; user_id?: string }) => {
const { data } = await apiClient.post('/api/resources/', resourceData);
const { data } = await apiClient.post('/resources/', resourceData);
return data;
},
onSuccess: () => {
@@ -143,7 +143,7 @@ export const useBusinessUsers = () => {
return useQuery({
queryKey: ['businessUsers'],
queryFn: async () => {
const { data } = await apiClient.get('/api/staff/');
const { data } = await apiClient.get('/staff/');
return data;
},
staleTime: 5 * 60 * 1000, // 5 minutes

View File

@@ -36,7 +36,7 @@ export const useStaff = (filters?: StaffFilters) => {
if (filters?.search) params.append('search', filters.search);
params.append('show_inactive', 'true'); // Always fetch inactive staff too
const { data } = await apiClient.get(`/api/staff/?${params}`);
const { data } = await apiClient.get(`/staff/?${params}`);
// Transform backend format to frontend format
return data.map((s: any) => ({
@@ -68,7 +68,7 @@ export const useUpdateStaff = () => {
id: string;
updates: { is_active?: boolean; permissions?: StaffPermissions };
}) => {
const { data } = await apiClient.patch(`/api/staff/${id}/`, updates);
const { data } = await apiClient.patch(`/staff/${id}/`, updates);
return data;
},
onSuccess: () => {
@@ -86,7 +86,7 @@ export const useToggleStaffActive = () => {
return useMutation({
mutationFn: async (id: string) => {
const { data } = await apiClient.post(`/api/staff/${id}/toggle_active/`);
const { data } = await apiClient.post(`/staff/${id}/toggle_active/`);
return data;
},
onSuccess: () => {