Assist_Design/apps/portal/src/lib/providers.tsx
barsa e5ce4e166c Refactor mappers and services for improved type safety and code clarity
- Updated export statements in user and mapping mappers for consistency.
- Enhanced FreebitAuthService to explicitly define response types for better type inference.
- Refactored various services to improve error handling and response structure.
- Cleaned up unused code and comments across multiple files to enhance readability.
- Improved type annotations in invoice and subscription services for better validation and consistency.
2025-10-22 10:58:16 +09:00

47 lines
1.4 KiB
TypeScript

/**
* React Query Provider
* Simple provider setup for TanStack Query
*/
"use client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { useState } from "react";
import { isApiError } from "@/lib/api/runtime/client";
export function QueryProvider({ children }: { children: React.ReactNode }) {
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
queries: {
staleTime: 5 * 60 * 1000, // 5 minutes
gcTime: 10 * 60 * 1000, // 10 minutes
retry: (failureCount, error: unknown) => {
if (isApiError(error)) {
const status = error.response?.status;
if (status && status >= 400 && status < 500) {
return false;
}
const body = error.body as Record<string, unknown> | undefined;
const code = typeof body?.code === "string" ? body.code : undefined;
if (code === "AUTHENTICATION_REQUIRED" || code === "FORBIDDEN") {
return false;
}
}
return failureCount < 3;
},
},
},
})
);
return (
<QueryClientProvider client={queryClient}>
{children}
{process.env.NODE_ENV === "development" && <ReactQueryDevtools />}
</QueryClientProvider>
);
}