2025-11-16 19:06:11 +00:00
|
|
|
import { createAxiosDataSource, createAxiosInstance } from "@erp/core/client";
|
|
|
|
|
import { DataSourceProvider } from "@erp/core/hooks";
|
2026-07-05 11:43:13 +00:00
|
|
|
import { IdentityAuthSessionProvider, authTokenStorage } from "@erp/identity/client";
|
2026-04-12 10:07:15 +00:00
|
|
|
import { i18n } from "@repo/i18next";
|
2025-11-16 19:06:11 +00:00
|
|
|
import { LoadingOverlay } from "@repo/rdx-ui/components";
|
2025-05-17 19:12:01 +00:00
|
|
|
import { Toaster, TooltipProvider } from "@repo/shadcn-ui/components";
|
|
|
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
|
|
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
2025-11-16 19:06:11 +00:00
|
|
|
import DineroFactory from "dinero.js";
|
|
|
|
|
import { Suspense } from "react";
|
2025-05-17 19:12:01 +00:00
|
|
|
import { I18nextProvider } from "react-i18next";
|
2025-11-16 19:06:11 +00:00
|
|
|
import { RouterProvider } from "react-router-dom";
|
2025-05-02 21:43:51 +00:00
|
|
|
|
2025-08-24 10:14:20 +00:00
|
|
|
import { getAppRouter } from "./routes";
|
|
|
|
|
|
2025-05-18 11:53:00 +00:00
|
|
|
export const App = () => {
|
2025-07-02 08:57:09 +00:00
|
|
|
DineroFactory.globalLocale = "es-ES";
|
|
|
|
|
|
2025-05-17 19:12:01 +00:00
|
|
|
const queryClient = new QueryClient({
|
|
|
|
|
defaultOptions: {
|
|
|
|
|
queries: {
|
|
|
|
|
retry: false,
|
|
|
|
|
staleTime: 10000, // Specify a staleTime to only fetch when the data is older than a certain amount of time
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
2025-05-02 21:43:51 +00:00
|
|
|
|
2025-11-28 15:00:18 +00:00
|
|
|
console.log("import.meta.env.VITE_API_SERVER_URL => ", import.meta.env.VITE_API_SERVER_URL);
|
|
|
|
|
|
2025-05-29 11:15:28 +00:00
|
|
|
const axiosInstance = createAxiosInstance({
|
2025-06-17 16:18:25 +00:00
|
|
|
baseURL: import.meta.env.VITE_API_SERVER_URL,
|
2026-07-05 11:43:13 +00:00
|
|
|
getAccessToken: () => authTokenStorage.getAccessToken(),
|
2025-05-29 11:15:28 +00:00
|
|
|
onAuthError: () => {
|
2026-07-05 11:43:13 +00:00
|
|
|
// TODO(identity-auth): siguiente incremento
|
|
|
|
|
// 1. detectar 401 recuperable
|
|
|
|
|
// 2. llamar refresh()
|
|
|
|
|
// 3. reintentar la request original
|
|
|
|
|
// 4. limpiar sesión si refresh falla
|
2025-05-29 11:15:28 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const dataSource = createAxiosDataSource(axiosInstance);
|
2025-08-24 10:14:20 +00:00
|
|
|
const appRouter = getAppRouter();
|
2025-05-27 17:47:03 +00:00
|
|
|
|
2025-05-02 21:43:51 +00:00
|
|
|
return (
|
2025-05-17 19:12:01 +00:00
|
|
|
<I18nextProvider i18n={i18n}>
|
|
|
|
|
<QueryClientProvider client={queryClient}>
|
2025-05-27 17:47:03 +00:00
|
|
|
<DataSourceProvider dataSource={dataSource}>
|
2026-07-05 11:43:13 +00:00
|
|
|
<IdentityAuthSessionProvider>
|
2026-04-12 10:07:15 +00:00
|
|
|
<TooltipProvider>
|
2025-09-23 08:59:15 +00:00
|
|
|
{/* Fallback Route */}
|
|
|
|
|
<Suspense fallback={<LoadingOverlay />}>
|
|
|
|
|
<RouterProvider router={appRouter} />
|
|
|
|
|
</Suspense>
|
2025-05-29 11:15:28 +00:00
|
|
|
</TooltipProvider>
|
2026-04-28 09:34:22 +00:00
|
|
|
<Toaster expand={true} position="top-center" richColors />
|
2025-05-29 11:15:28 +00:00
|
|
|
{import.meta.env.DEV && <ReactQueryDevtools initialIsOpen={false} />}
|
2026-07-05 11:43:13 +00:00
|
|
|
</IdentityAuthSessionProvider>
|
2025-05-17 19:12:01 +00:00
|
|
|
</DataSourceProvider>
|
|
|
|
|
</QueryClientProvider>
|
|
|
|
|
</I18nextProvider>
|
2025-05-02 21:43:51 +00:00
|
|
|
);
|
2025-05-18 11:53:00 +00:00
|
|
|
};
|