2023-07-04 12:03:54 +00:00
|
|
|
|
import React from "react";
|
2022-11-17 12:25:23 +00:00
|
|
|
|
import ReactDOM from "react-dom/client";
|
2023-06-24 18:17:43 +00:00
|
|
|
|
import { BrowserRouter, Navigate, Route, Routes, useLocation, useNavigate } 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-07-25 22:31:04 +00:00
|
|
|
|
import History from "./pages/History";
|
2023-08-12 14:55:41 +00:00
|
|
|
|
import Cart from "./pages/Cart/Cart";
|
2023-03-27 12:45:44 +00:00
|
|
|
|
import TariffPage from "./pages/Tariffs/TariffsPage";
|
2023-07-25 22:31:04 +00:00
|
|
|
|
import SavedTariffs from "./pages/SavedTariffs";
|
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";
|
2023-06-24 18:17:43 +00:00
|
|
|
|
import { clearUserData, setUser, setUserAccount, 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-08-08 12:59:54 +00:00
|
|
|
|
import { clearAuthToken, getMessageFromFetchError, usePrivilegeFetcher } from "@frontend/kitui";
|
2023-06-24 18:17:43 +00:00
|
|
|
|
import { useUserAccount } from "./utils/hooks/useUserAccount";
|
2023-07-13 18:59:23 +00:00
|
|
|
|
import { setCustomTariffs } from "@root/stores/customTariffs";
|
2023-07-11 01:33:36 +00:00
|
|
|
|
import { useCustomTariffs } from "@root/utils/hooks/useCustomTariffs";
|
2023-07-13 18:59:23 +00:00
|
|
|
|
import { useDiscounts } from "./utils/hooks/useDiscounts";
|
|
|
|
|
import { setDiscounts } from "./stores/discounts";
|
2023-07-25 22:31:04 +00:00
|
|
|
|
import { pdfjs } from "react-pdf";
|
2023-08-08 12:59:54 +00:00
|
|
|
|
import { setPrivileges } from "./stores/privileges";
|
2023-03-27 12:45:44 +00:00
|
|
|
|
|
2023-07-25 22:31:04 +00:00
|
|
|
|
pdfjs.GlobalWorkerOptions.workerSrc = new URL("pdfjs-dist/build/pdf.worker.min.js", import.meta.url).toString();
|
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-06-24 18:17:43 +00:00
|
|
|
|
const navigate = useNavigate();
|
2023-07-13 18:59:23 +00:00
|
|
|
|
|
2023-07-11 01:33:36 +00:00
|
|
|
|
useCustomTariffs({
|
|
|
|
|
url: "https://admin.pena.digital/strator/privilege/service",
|
|
|
|
|
onNewUser: setCustomTariffs,
|
|
|
|
|
onError: error => {
|
|
|
|
|
const errorMessage = getMessageFromFetchError(error, "Не удалось получить кастомные тарифы");
|
|
|
|
|
if (errorMessage) enqueueSnackbar(errorMessage);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-06-06 13:13:58 +00:00
|
|
|
|
useUser({
|
|
|
|
|
url: `https://hub.pena.digital/user/${userId}`,
|
|
|
|
|
userId,
|
|
|
|
|
onNewUser: setUser,
|
2023-07-04 12:03:54 +00:00
|
|
|
|
onError: 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);
|
2023-06-24 18:17:43 +00:00
|
|
|
|
clearUserData();
|
|
|
|
|
clearAuthToken();
|
2023-06-24 12:00:15 +00:00
|
|
|
|
}
|
2023-07-04 12:03:54 +00:00
|
|
|
|
}
|
2023-06-06 13:13:58 +00:00
|
|
|
|
});
|
2023-05-17 11:20:11 +00:00
|
|
|
|
|
2023-06-24 18:17:43 +00:00
|
|
|
|
useUserAccount({
|
|
|
|
|
url: "https://hub.pena.digital/customer/account",
|
|
|
|
|
userId,
|
|
|
|
|
onNewUserAccount: setUserAccount,
|
2023-07-04 12:03:54 +00:00
|
|
|
|
onError: error => {
|
2023-06-24 18:17:43 +00:00
|
|
|
|
const errorMessage = getMessageFromFetchError(error);
|
|
|
|
|
if (errorMessage) {
|
|
|
|
|
enqueueSnackbar(errorMessage);
|
|
|
|
|
clearUserData();
|
|
|
|
|
clearAuthToken();
|
|
|
|
|
navigate("/signin");
|
|
|
|
|
}
|
2023-07-04 12:03:54 +00:00
|
|
|
|
}
|
2023-06-24 18:17:43 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-07-13 18:59:23 +00:00
|
|
|
|
useDiscounts({
|
|
|
|
|
onNewDiscounts: setDiscounts,
|
|
|
|
|
onError: error => {
|
|
|
|
|
const message = getMessageFromFetchError(error);
|
|
|
|
|
if (message) enqueueSnackbar(message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-08-08 12:59:54 +00:00
|
|
|
|
usePrivilegeFetcher({
|
|
|
|
|
onSuccess: setPrivileges,
|
|
|
|
|
onError: error => {
|
|
|
|
|
console.log("usePrivilegeFetcher error :>> ", error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
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 element={<PrivateRoute />}>
|
2023-07-04 12:03:54 +00:00
|
|
|
|
<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 />} />
|
|
|
|
|
<Route path="/tariffconstructor" element={<TariffConstructor />} />
|
2023-08-12 14:55:41 +00:00
|
|
|
|
<Route path="/cart" element={<Cart />} />
|
2023-05-17 11:20:11 +00:00
|
|
|
|
<Route path="/wallet" element={<Wallet />} />
|
|
|
|
|
<Route path="/payment" element={<Payment />} />
|
2023-06-24 12:03:12 +00:00
|
|
|
|
<Route path="/settings" element={<AccountSettings />} />
|
2023-07-25 22:31:04 +00:00
|
|
|
|
<Route path="/history" element={<History />} />
|
|
|
|
|
<Route path="/tariffconstructor/savedtariffs" element={<SavedTariffs />} />
|
2023-05-17 11:20:11 +00:00
|
|
|
|
</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();
|