2023-06-06 13:13:58 +00:00
|
|
|
import React, { useCallback } from "react";
|
2022-11-17 12:25:23 +00:00
|
|
|
import ReactDOM from "react-dom/client";
|
2023-05-19 09:44:18 +00:00
|
|
|
import { BrowserRouter, Navigate, Route, Routes, useLocation } from "react-router-dom";
|
2023-05-17 11:20:11 +00:00
|
|
|
import { CssBaseline, ThemeProvider } from "@mui/material";
|
2023-03-19 12:30:40 +00:00
|
|
|
import Faq from "./pages/Faq/Faq";
|
|
|
|
import Wallet from "./pages/Wallet";
|
|
|
|
import Payment from "./pages/Payment/Payment";
|
|
|
|
import Support from "./pages/Support/Support";
|
2023-06-24 12:04:06 +00:00
|
|
|
import AccountSettings from "./pages/AccountSettings/AccountSettings";
|
2023-03-19 12:30:40 +00:00
|
|
|
import Landing from "./pages/Landing/Landing";
|
|
|
|
import Tariffs from "./pages/Tariffs/Tariffs";
|
2023-05-13 14:13:57 +00:00
|
|
|
import SigninDialog from "./pages/auth/Signin";
|
|
|
|
import SignupDialog from "./pages/auth/Signup";
|
2023-03-20 13:30:48 +00:00
|
|
|
import PaymentHistory from "./pages/PaymentHistory/PaymentHistory";
|
2023-03-27 12:45:44 +00:00
|
|
|
import Basket from "./pages/Basket/Basket";
|
|
|
|
import TariffPage from "./pages/Tariffs/TariffsPage";
|
2023-03-19 12:30:40 +00:00
|
|
|
import lightTheme from "@utils/themes/light";
|
2023-03-27 12:45:44 +00:00
|
|
|
import PrivateRoute from "@utils/routes/privateRoute";
|
|
|
|
import reportWebVitals from "./reportWebVitals";
|
2023-05-17 11:20:11 +00:00
|
|
|
import { SnackbarProvider, enqueueSnackbar } from "notistack";
|
2023-03-27 12:45:44 +00:00
|
|
|
import "./index.css";
|
2023-05-17 11:20:11 +00:00
|
|
|
import Layout from "./components/Layout";
|
|
|
|
import { setUser, useUserStore } from "./stores/user";
|
2023-05-27 11:50:21 +00:00
|
|
|
import TariffConstructor from "./pages/TariffConstructor/TariffConstructor";
|
2023-06-06 13:13:58 +00:00
|
|
|
import { useUser } from "./utils/hooks/useUser";
|
2023-06-20 10:23:30 +00:00
|
|
|
import { getMessageFromFetchError } from "@frontend/kitui";
|
2023-03-27 12:45:44 +00:00
|
|
|
|
2023-05-13 14:13:57 +00:00
|
|
|
|
2023-03-19 12:32:23 +00:00
|
|
|
const App = () => {
|
2023-05-13 14:13:57 +00:00
|
|
|
const location = useLocation();
|
2023-05-17 11:20:11 +00:00
|
|
|
const userId = useUserStore(state => state.userId);
|
2023-03-19 12:30:40 +00:00
|
|
|
|
2023-06-06 13:13:58 +00:00
|
|
|
useUser({
|
|
|
|
url: `https://hub.pena.digital/user/${userId}`,
|
|
|
|
userId,
|
|
|
|
onNewUser: setUser,
|
|
|
|
onError: useCallback(error => {
|
2023-06-20 10:23:30 +00:00
|
|
|
const errorMessage = getMessageFromFetchError(error);
|
2023-06-24 12:00:15 +00:00
|
|
|
if (errorMessage) {
|
|
|
|
enqueueSnackbar(errorMessage);
|
|
|
|
setUser(null);
|
|
|
|
}
|
2023-06-06 13:13:58 +00:00
|
|
|
}, [])
|
|
|
|
});
|
2023-05-17 11:20:11 +00:00
|
|
|
|
2023-06-17 14:31:32 +00:00
|
|
|
if (location.state?.redirectTo) return <Navigate to={location.state.redirectTo} replace state={{ backgroundLocation: location }} />;
|
2023-03-19 12:30:40 +00:00
|
|
|
|
2023-05-13 14:13:57 +00:00
|
|
|
return (
|
|
|
|
<>
|
2023-05-19 09:44:18 +00:00
|
|
|
{location.state?.backgroundLocation &&
|
2023-05-13 14:13:57 +00:00
|
|
|
<Routes>
|
|
|
|
<Route path="/signin" element={<SigninDialog />} />
|
|
|
|
<Route path="/signup" element={<SignupDialog />} />
|
|
|
|
</Routes>
|
|
|
|
}
|
2023-05-19 09:44:18 +00:00
|
|
|
<Routes location={location.state?.backgroundLocation || location}>
|
2023-05-17 11:20:11 +00:00
|
|
|
<Route path="/" element={<Landing />} />
|
2023-05-19 09:44:18 +00:00
|
|
|
<Route path="/signin" element={<Navigate to="/" replace state={{ redirectTo: "/signin" }} />} />
|
|
|
|
<Route path="/signup" element={<Navigate to="/" replace state={{ redirectTo: "/signup" }} />} />
|
2023-05-17 11:20:11 +00:00
|
|
|
<Route element={<Layout />}>
|
|
|
|
<Route path="/tariffs" element={<Tariffs />} />
|
|
|
|
<Route path="/tariffs/time" element={<TariffPage />} />
|
|
|
|
<Route path="/tariffs/volume" element={<TariffPage />} />
|
|
|
|
<Route path="/faq" element={<Faq />} />
|
|
|
|
<Route path="/support" element={<Support />} />
|
|
|
|
<Route path="/support/:ticketId" element={<Support />} />
|
2023-05-27 11:50:21 +00:00
|
|
|
<Route path="/tariffconstructor" element={<TariffConstructor />} />
|
2023-05-17 11:20:11 +00:00
|
|
|
<Route path="/basket" element={<Basket />} />
|
|
|
|
<Route element={<PrivateRoute />}>
|
|
|
|
<Route path="/wallet" element={<Wallet />} />
|
|
|
|
<Route path="/payment" element={<Payment />} />
|
2023-06-24 12:03:12 +00:00
|
|
|
<Route path="/settings" element={<AccountSettings />} />
|
2023-05-17 11:20:11 +00:00
|
|
|
<Route path="/paymenthistory" element={<PaymentHistory />} />
|
|
|
|
</Route>
|
|
|
|
</Route>
|
2023-05-13 14:13:57 +00:00
|
|
|
</Routes>
|
|
|
|
</>
|
|
|
|
);
|
2023-03-19 12:30:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
|
2022-11-17 12:25:23 +00:00
|
|
|
root.render(
|
2023-05-13 14:13:57 +00:00
|
|
|
<React.StrictMode>
|
|
|
|
<ThemeProvider theme={lightTheme}>
|
|
|
|
<BrowserRouter>
|
|
|
|
<CssBaseline />
|
|
|
|
<SnackbarProvider />
|
|
|
|
<App />
|
|
|
|
</BrowserRouter>
|
|
|
|
</ThemeProvider>
|
|
|
|
</React.StrictMode>
|
2022-11-17 12:25:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// 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();
|