import React, { useEffect } from "react";
import ReactDOM from "react-dom/client";
import { BrowserRouter, Navigate, Route, Routes, useLocation } from "react-router-dom";
import { CssBaseline, ThemeProvider } from "@mui/material";
import Faq from "./pages/Faq/Faq";
import Wallet from "./pages/Wallet";
import Payment from "./pages/Payment/Payment";
import Support from "./pages/Support/Support";
import AccountSetup from "./pages/AccountSetup/AccountSetup";
import Landing from "./pages/Landing/Landing";
import Tariffs from "./pages/Tariffs/Tariffs";
import SigninDialog from "./pages/auth/Signin";
import SignupDialog from "./pages/auth/Signup";
import PaymentHistory from "./pages/PaymentHistory/PaymentHistory";
import Basket from "./pages/Basket/Basket";
import TariffPage from "./pages/Tariffs/TariffsPage";
import lightTheme from "@utils/themes/light";
import PrivateRoute from "@utils/routes/privateRoute";
import reportWebVitals from "./reportWebVitals";
import { SnackbarProvider, enqueueSnackbar } from "notistack";
import "./index.css";
import Layout from "./components/Layout";
import { getUser } from "./api/user";
import { setUser, useUserStore } from "./stores/user";
import TariffConstructor from "./pages/TariffConstructor/TariffConstructor";
const App = () => {
const location = useLocation();
const userId = useUserStore(state => state.userId);
useEffect(function fetchUserData() {
if (!userId) return;
getUser(userId).then(result => {
setUser(result);
}).catch(error => {
console.log("Error fetching user", error);
enqueueSnackbar(error.response?.data?.message ?? error.message ?? "Error fetching user");
setUser(null);
});
}, [userId]);
if (location.state?.redirectTo === "/signin") return ;
if (location.state?.redirectTo === "/signup") return ;
return (
<>
{location.state?.backgroundLocation &&
} />
} />
}
} />
} />
} />
}>
} />
} />
} />
} />
} />
} />
} />
} />
}>
} />
} />
} />
} />
>
);
};
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
root.render(
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();