diff --git a/app/src/api/axios.ts b/app/src/api/axios.ts index b300d16..688f13b 100644 --- a/app/src/api/axios.ts +++ b/app/src/api/axios.ts @@ -103,6 +103,10 @@ export const createApiClient = async (): Promise => { redirecting = true; clearSession(); window.location.href = "/login"; + // Reset flag after redirect attempt + setTimeout(() => { + redirecting = false; + }, 0); } } diff --git a/app/src/api/queryClient.ts b/app/src/api/queryClient.ts index 9776492..c486c90 100644 --- a/app/src/api/queryClient.ts +++ b/app/src/api/queryClient.ts @@ -2,7 +2,14 @@ import { useQuery, useMutation, useQueryClient, QueryKey } from "@tanstack/react import { createApiClient } from "./axios"; // import { ApiResponse } from "@/types"; -const apiClient = await createApiClient(); +let apiClient: Awaited> | null = null; + +const getApiClient = async () => { + if (!apiClient) { + apiClient = await createApiClient(); + } + return apiClient; +}; /* ========================= GENERIC GET @@ -20,7 +27,8 @@ export function useGet( return useQuery({ queryKey, queryFn: async () => { - const res = await apiClient.get(endpoint); + const client = await getApiClient(); + const res = await client.get(endpoint); return res.data; // 🔑 FIX: return data, not AxiosResponse }, enabled: options?.enabled ?? true, @@ -45,7 +53,8 @@ export function usePost( return useMutation({ mutationFn: async (variables) => { - const res = await apiClient.post(endpoint, variables); + const client = await getApiClient(); + const res = await client.post(endpoint, variables); return res.data; }, onSuccess: (data, variables) => { @@ -77,7 +86,8 @@ export function usePut( return useMutation({ mutationFn: async (variables) => { - const res = await apiClient.put(endpoint, variables); + const client = await getApiClient(); + const res = await client.put(endpoint, variables); return res.data; }, onSuccess: (data) => { @@ -109,7 +119,8 @@ export function usePatch( return useMutation({ mutationFn: async (variables) => { - const res = await apiClient.patch(endpoint, variables); + const client = await getApiClient(); + const res = await client.patch(endpoint, variables); return res.data; }, onSuccess: (data) => { @@ -141,7 +152,8 @@ export function useDelete( return useMutation({ mutationFn: async () => { - const res = await apiClient.delete(endpoint); + const client = await getApiClient(); + const res = await client.delete(endpoint); return res.data; }, onSuccess: (data) => { diff --git a/app/src/components/EarningsRoyalties.tsx b/app/src/components/EarningsRoyalties.tsx index a1f5656..d60ceb7 100644 --- a/app/src/components/EarningsRoyalties.tsx +++ b/app/src/components/EarningsRoyalties.tsx @@ -53,7 +53,17 @@ function createEarningsCsv(data: EarningsDataPoint[]): string { return [CSV_HEADERS.join(","), ...rows].join("\r\n"); } -const CustomTooltip = ({ active, payload, coordinate }: TooltipProps) => { +type CustomTooltipProps = TooltipProps & { + active?: boolean; + payload?: Array<{ payload: EarningsDataPoint }>; + coordinate?: { x: number; y: number }; +}; + +function highlightedMonth(payload: EarningsDataPoint): string { + return payload.month; +} + +const CustomTooltip = ({ active, payload, coordinate }: CustomTooltipProps) => { if (active && payload && payload.length && coordinate) { const data: EarningsDataPoint = payload[0].payload as EarningsDataPoint; const isHighlighted = data.month === highlightedMonth(payload[0].payload as EarningsDataPoint); @@ -85,10 +95,6 @@ const CustomTooltip = ({ active, payload, coordinate }: TooltipProps setDeleteId(null) }); + deleteMutation.mutate(void 0, { onSuccess: () => setDeleteId(null) }); }; return (