2023-11-05 23:33:40 +00:00
|
|
|
import React from "react"
|
|
|
|
import ReactDOM from "react-dom/client"
|
|
|
|
import { BrowserRouter, Navigate, Route, Routes, useLocation, useNavigate } 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"
|
2024-01-28 08:59:07 +00:00
|
|
|
import QuizPayment from "./pages/QuizPayment/QuizPayment"
|
2023-11-05 23:33:40 +00:00
|
|
|
import Support from "./pages/Support/Support"
|
|
|
|
import AccountSettings from "./pages/AccountSettings/AccountSettings"
|
|
|
|
import Landing from "./pages/Landing/Landing"
|
|
|
|
import Tariffs from "./pages/Tariffs/Tariffs"
|
|
|
|
import SigninDialog from "./pages/auth/Signin"
|
|
|
|
import SignupDialog from "./pages/auth/Signup"
|
2024-01-18 09:23:18 +00:00
|
|
|
import RecoverDialog from "./pages/auth/Recover"
|
2023-11-05 23:33:40 +00:00
|
|
|
import History from "./pages/History"
|
|
|
|
import Cart from "./pages/Cart/Cart"
|
|
|
|
import TariffPage from "./pages/Tariffs/TariffsPage"
|
|
|
|
import SavedTariffs from "./pages/SavedTariffs"
|
|
|
|
import PrivateRoute from "@root/utils/routes/ProtectedRoute"
|
|
|
|
import reportWebVitals from "./reportWebVitals"
|
|
|
|
import { SnackbarProvider, enqueueSnackbar } from "notistack"
|
|
|
|
import "./index.css"
|
|
|
|
import ProtectedLayout from "./components/ProtectedLayout"
|
|
|
|
import { clearUserData, setUser, setUserAccount, useUserStore } from "./stores/user"
|
|
|
|
import TariffConstructor from "./pages/TariffConstructor/TariffConstructor"
|
|
|
|
import { clearAuthToken, getMessageFromFetchError, useUserAccountFetcher, useUserFetcher } from "@frontend/kitui"
|
|
|
|
import { pdfjs } from "react-pdf"
|
|
|
|
import { theme } from "./utils/theme"
|
2024-01-16 16:23:21 +00:00
|
|
|
import PPofData from "@root/docs/PPofData"
|
|
|
|
import Docs from "@root/docs/docs"
|
|
|
|
import Oferta from "@root/docs/content/oferta"
|
|
|
|
import PrivacyPolicy from "@root/docs/content/PrivacyPolicy"
|
2024-01-20 00:37:41 +00:00
|
|
|
import RecoverPassword from "@root/pages/auth/RecoverPassword"
|
|
|
|
import OutdatedLink from "@root/pages/auth/OutdatedLink"
|
2024-02-16 15:27:39 +00:00
|
|
|
import { verify } from "./pages/AccountSettings/helper"
|
2023-03-27 12:45:44 +00:00
|
|
|
|
2023-11-05 23:33:40 +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-11-05 23:33:40 +00:00
|
|
|
console.log("render app")
|
|
|
|
const location = useLocation()
|
|
|
|
const userId = useUserStore((state) => state.userId)
|
|
|
|
const navigate = useNavigate()
|
2023-07-13 18:59:23 +00:00
|
|
|
|
2024-02-16 15:27:39 +00:00
|
|
|
console.log(userId)
|
2023-11-05 23:33:40 +00:00
|
|
|
useUserFetcher({
|
2024-01-17 20:04:39 +00:00
|
|
|
url: process.env.REACT_APP_DOMAIN + `/user/${userId}`,
|
2023-11-05 23:33:40 +00:00
|
|
|
userId,
|
|
|
|
onNewUser: setUser,
|
|
|
|
onError: (error) => {
|
|
|
|
const errorMessage = getMessageFromFetchError(error)
|
|
|
|
if (errorMessage) {
|
|
|
|
enqueueSnackbar(errorMessage)
|
|
|
|
clearUserData()
|
|
|
|
clearAuthToken()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
2023-07-11 01:33:36 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
useUserAccountFetcher({
|
2024-01-17 20:04:39 +00:00
|
|
|
url: process.env.REACT_APP_DOMAIN + "/customer/account",
|
2023-11-05 23:33:40 +00:00
|
|
|
userId,
|
|
|
|
onNewUserAccount: setUserAccount,
|
|
|
|
onError: (error) => {
|
|
|
|
const errorMessage = getMessageFromFetchError(error)
|
|
|
|
if (errorMessage) {
|
|
|
|
enqueueSnackbar(errorMessage)
|
|
|
|
clearUserData()
|
|
|
|
clearAuthToken()
|
|
|
|
navigate("/signin")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
2023-05-17 11:20:11 +00:00
|
|
|
|
2024-02-16 15:27:39 +00:00
|
|
|
verify(userId)
|
|
|
|
|
2024-01-29 09:10:04 +00:00
|
|
|
console.log(location)
|
2023-11-05 23:33:40 +00:00
|
|
|
if (location.state?.redirectTo)
|
|
|
|
return <Navigate to={location.state.redirectTo} replace state={{ backgroundLocation: location }} />
|
2023-08-08 12:59:54 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{location.state?.backgroundLocation && (
|
|
|
|
<Routes>
|
|
|
|
<Route path="/signin" element={<SigninDialog />} />
|
|
|
|
<Route path="/signup" element={<SignupDialog />} />
|
2024-01-18 09:23:18 +00:00
|
|
|
<Route path="/recover" element={<RecoverDialog />} />
|
2024-01-20 19:55:01 +00:00
|
|
|
<Route path="/changepwd" element={<RecoverPassword />} />
|
2024-01-20 00:37:41 +00:00
|
|
|
<Route path="/changepwd/expired" element={<OutdatedLink />} />
|
2023-11-05 23:33:40 +00:00
|
|
|
</Routes>
|
|
|
|
)}
|
|
|
|
<Routes location={location.state?.backgroundLocation || location}>
|
|
|
|
<Route path="/" element={<Landing />} />
|
|
|
|
<Route path="/signin" element={<Navigate to="/" replace state={{ redirectTo: "/signin" }} />} />
|
|
|
|
<Route path="/signup" element={<Navigate to="/" replace state={{ redirectTo: "/signup" }} />} />
|
2024-01-18 09:23:18 +00:00
|
|
|
<Route path="/recover" element={<Navigate to="/" replace state={{ redirectTo: "/recover" }} />} />
|
2024-01-20 19:55:01 +00:00
|
|
|
<Route path="/changepwd" element={<Navigate to="/" replace state={{ redirectTo: window.location.pathname + window.location.search }} />} />
|
2024-01-20 00:37:41 +00:00
|
|
|
<Route path="/changepwd/expired" element={<Navigate to="/" replace state={{ redirectTo: "/changepwd/expired" }} />} />
|
2024-01-29 09:10:04 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
<Route element={<PrivateRoute />}>
|
|
|
|
<Route element={<ProtectedLayout />}>
|
|
|
|
<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 />} />
|
|
|
|
<Route path="/cart" element={<Cart />} />
|
|
|
|
<Route path="/wallet" element={<Wallet />} />
|
|
|
|
<Route path="/payment" element={<Payment />} />
|
|
|
|
<Route path="/settings" element={<AccountSettings />} />
|
|
|
|
<Route path="/history" element={<History />} />
|
|
|
|
<Route path="/tariffconstructor/savedtariffs" element={<SavedTariffs />} />
|
|
|
|
</Route>
|
|
|
|
</Route>
|
2024-01-16 16:23:21 +00:00
|
|
|
<Route path="/ppdd" element={<PPofData/>}/>
|
2024-01-29 09:10:04 +00:00
|
|
|
<Route path="/quizpayment" element={<QuizPayment/>} />
|
2024-01-16 16:23:21 +00:00
|
|
|
<Route element={<Docs />}>
|
|
|
|
<Route path={"/docs/oferta"} element={<Oferta />}/>
|
|
|
|
<Route path={"/docs/privacy"} element={<PrivacyPolicy />}/>
|
|
|
|
</Route>
|
2023-11-05 23:33:40 +00:00
|
|
|
</Routes>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2023-03-19 12:30:40 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement)
|
2022-11-17 12:25:23 +00:00
|
|
|
root.render(
|
2023-11-05 23:33:40 +00:00
|
|
|
// <React.StrictMode>
|
|
|
|
<ThemeProvider theme={theme}>
|
|
|
|
<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
|
2023-11-05 23:33:40 +00:00
|
|
|
reportWebVitals()
|