2024-06-10 10:57:57 +00:00
|
|
|
import { clearAuthToken, getMessageFromFetchError, UserAccount, useUserFetcher } from "@frontend/kitui";
|
2024-03-28 13:43:41 +00:00
|
|
|
import type { OriginalUserAccount } from "@root/user";
|
2024-06-10 10:57:57 +00:00
|
|
|
import { clearUserData, setCustomerAccount, setUser, setUserAccount, useUserStore } from "@root/user";
|
2024-06-24 17:40:13 +00:00
|
|
|
import ContactFormModal from "@ui_kit/ContactForm";
|
2024-03-06 11:13:28 +00:00
|
|
|
import FloatingSupportChat from "@ui_kit/FloatingSupportChat";
|
2024-06-24 17:40:13 +00:00
|
|
|
import PrivateRoute from "@ui_kit/PrivateRoute";
|
2024-08-11 04:42:49 +00:00
|
|
|
import { useAfterPay } from "@utils/hooks/useAutoPay";
|
2024-05-15 11:44:10 +00:00
|
|
|
import { useUserAccountFetcher } from "@utils/hooks/useUserAccountFetcher";
|
2024-06-24 17:40:13 +00:00
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
import type { SuspenseProps } from "react";
|
|
|
|
import { lazy, Suspense } from "react";
|
|
|
|
import { lazily } from "react-lazily";
|
|
|
|
import { Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom";
|
|
|
|
import { useAmoAccount } from "./api/integration";
|
2024-05-28 20:39:21 +00:00
|
|
|
import ListPageDummy from "./components/Dummys/pageDummys/listPageDummy";
|
2024-06-24 17:40:13 +00:00
|
|
|
import "./index.css";
|
|
|
|
import OutdatedLink from "./pages/auth/OutdatedLink";
|
|
|
|
import RecoverPassword from "./pages/auth/RecoverPassword";
|
|
|
|
import { Restore } from "./pages/auth/Restore";
|
|
|
|
import SigninDialog from "./pages/auth/Signin";
|
|
|
|
import SignupDialog from "./pages/auth/Signup";
|
|
|
|
import { InfoPrivilege } from "./pages/InfoPrivilege";
|
2024-07-22 23:55:58 +00:00
|
|
|
import AmoTokenExpiredDialog from "./pages/IntegrationsPage/IntegrationsModal/Amo/AmoTokenExpiredDialog";
|
2024-06-24 17:40:13 +00:00
|
|
|
import Landing from "./pages/Landing/Landing";
|
|
|
|
import Main from "./pages/main";
|
2025-01-18 13:07:22 +00:00
|
|
|
import { ErrorBoundary } from "react-error-boundary";
|
2024-02-20 11:54:08 +00:00
|
|
|
|
2024-03-20 12:16:21 +00:00
|
|
|
const MyQuizzesFull = lazy(() => import("./pages/createQuize/MyQuizzesFull"));
|
2024-05-17 14:13:05 +00:00
|
|
|
const QuizGallery = lazy(() => import("./pages/createQuize/QuizGallery"));
|
2024-03-20 12:16:21 +00:00
|
|
|
const ViewPage = lazy(() => import("./pages/ViewPublicationPage"));
|
|
|
|
const Analytics = lazy(() => import("./pages/Analytics/Analytics"));
|
|
|
|
const EditPage = lazy(() => import("./pages/startPage/EditPage"));
|
|
|
|
const { Tariffs } = lazily(() => import("./pages/Tariffs/Tariffs"));
|
|
|
|
const { DesignPage } = lazily(() => import("./pages/DesignPage/DesignPage"));
|
2024-06-10 10:57:57 +00:00
|
|
|
const { IntegrationsPage } = lazily(() => import("./pages/IntegrationsPage/IntegrationsPage"));
|
|
|
|
const { QuizAnswersPage } = lazily(() => import("./pages/QuizAnswersPage/QuizAnswersPage"));
|
|
|
|
const ChatImageNewWindow = lazy(() => import("@ui_kit/FloatingSupportChat/ChatImageNewWindow"));
|
2025-01-03 17:54:57 +00:00
|
|
|
let params = new URLSearchParams(document.location.search);
|
|
|
|
const isTest = Boolean(params.get("test"))
|
2024-03-20 12:16:21 +00:00
|
|
|
|
|
|
|
const routeslink = [
|
|
|
|
{
|
|
|
|
path: "/edit",
|
|
|
|
page: EditPage,
|
|
|
|
header: true,
|
|
|
|
sidebar: true,
|
|
|
|
footer: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/design",
|
|
|
|
page: DesignPage,
|
|
|
|
header: true,
|
|
|
|
sidebar: true,
|
|
|
|
footer: true,
|
|
|
|
},
|
2024-04-04 13:48:45 +00:00
|
|
|
{
|
|
|
|
path: "/integrations",
|
|
|
|
page: IntegrationsPage,
|
|
|
|
header: true,
|
|
|
|
sidebar: true,
|
|
|
|
footer: true,
|
|
|
|
},
|
2024-03-20 12:16:21 +00:00
|
|
|
] as const;
|
|
|
|
|
|
|
|
const LazyLoading = ({ children, fallback }: SuspenseProps) => (
|
|
|
|
<Suspense fallback={fallback ?? <></>}>{children}</Suspense>
|
|
|
|
);
|
|
|
|
|
2023-11-08 12:51:40 +00:00
|
|
|
export default function App() {
|
2025-01-22 14:03:00 +00:00
|
|
|
window.LoadingObserver = false;
|
2023-12-31 02:53:25 +00:00
|
|
|
const userId = useUserStore((state) => state.userId);
|
|
|
|
const location = useLocation();
|
|
|
|
const navigate = useNavigate();
|
2024-06-24 17:40:13 +00:00
|
|
|
const { data: amoAccount } = useAmoAccount();
|
2023-11-08 12:51:40 +00:00
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
useUserFetcher({
|
2024-05-15 11:44:10 +00:00
|
|
|
url: `${process.env.REACT_APP_DOMAIN}/user/${userId}`,
|
2023-12-31 02:53:25 +00:00
|
|
|
userId,
|
|
|
|
onNewUser: setUser,
|
|
|
|
onError: (error) => {
|
|
|
|
const errorMessage = getMessageFromFetchError(error);
|
|
|
|
if (errorMessage) {
|
|
|
|
enqueueSnackbar(errorMessage);
|
|
|
|
clearUserData();
|
|
|
|
clearAuthToken();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2023-11-08 12:51:40 +00:00
|
|
|
|
2024-02-20 11:54:08 +00:00
|
|
|
useUserAccountFetcher<UserAccount>({
|
2024-07-23 10:57:16 +00:00
|
|
|
url: `${process.env.REACT_APP_DOMAIN}/customer/v1.0.1/account`,
|
2024-01-17 07:49:45 +00:00
|
|
|
userId,
|
|
|
|
onNewUserAccount: setCustomerAccount,
|
|
|
|
onError: (error) => {
|
|
|
|
const errorMessage = getMessageFromFetchError(error);
|
|
|
|
if (errorMessage) {
|
|
|
|
enqueueSnackbar(errorMessage);
|
|
|
|
clearUserData();
|
|
|
|
clearAuthToken();
|
|
|
|
navigate("/signin");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-02-20 11:54:08 +00:00
|
|
|
useUserAccountFetcher<OriginalUserAccount>({
|
2024-05-15 11:44:10 +00:00
|
|
|
url: `${process.env.REACT_APP_DOMAIN}/squiz/account/get`,
|
2023-12-31 02:53:25 +00:00
|
|
|
userId,
|
|
|
|
onNewUserAccount: setUserAccount,
|
|
|
|
onError: (error) => {
|
|
|
|
const errorMessage = getMessageFromFetchError(error);
|
|
|
|
if (errorMessage) {
|
|
|
|
enqueueSnackbar(errorMessage);
|
|
|
|
clearUserData();
|
|
|
|
clearAuthToken();
|
|
|
|
navigate("/signin");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2023-12-19 16:06:09 +00:00
|
|
|
|
2024-08-11 04:42:49 +00:00
|
|
|
useAfterPay();
|
2024-06-10 10:57:57 +00:00
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
if (location.state?.redirectTo)
|
2023-12-19 16:06:09 +00:00
|
|
|
return (
|
2023-12-31 02:53:25 +00:00
|
|
|
<Navigate
|
|
|
|
to={location.state.redirectTo}
|
|
|
|
replace
|
|
|
|
state={{ backgroundLocation: location }}
|
|
|
|
/>
|
2023-12-19 16:06:09 +00:00
|
|
|
);
|
2023-12-31 02:53:25 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-06-24 17:40:13 +00:00
|
|
|
{amoAccount && <AmoTokenExpiredDialog isAmoTokenExpired={amoAccount.stale} />}
|
2024-08-11 05:22:33 +00:00
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
<ContactFormModal />
|
2025-01-03 17:54:57 +00:00
|
|
|
{!isTest && <FloatingSupportChat />}
|
2023-12-31 02:53:25 +00:00
|
|
|
{location.state?.backgroundLocation && (
|
|
|
|
<Routes>
|
2024-06-10 10:57:57 +00:00
|
|
|
<Route
|
|
|
|
path="/signin"
|
|
|
|
element={<SigninDialog />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="/signup"
|
|
|
|
element={<SignupDialog />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="/recover"
|
|
|
|
element={<Restore />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="/changepwd"
|
|
|
|
element={<RecoverPassword />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="/changepwd/expired"
|
|
|
|
element={<OutdatedLink />}
|
|
|
|
/>
|
2023-12-31 02:53:25 +00:00
|
|
|
</Routes>
|
|
|
|
)}
|
|
|
|
<Routes location={location.state?.backgroundLocation || location}>
|
2024-06-10 10:57:57 +00:00
|
|
|
<Route
|
|
|
|
path="/"
|
|
|
|
element={<Landing />}
|
|
|
|
/>
|
2024-01-15 18:42:59 +00:00
|
|
|
<Route
|
2023-12-31 02:53:25 +00:00
|
|
|
path="/signin"
|
|
|
|
element={
|
2024-06-10 10:57:57 +00:00
|
|
|
<Navigate
|
|
|
|
to="/"
|
|
|
|
replace
|
|
|
|
state={{ redirectTo: "/signin" }}
|
|
|
|
/>
|
2023-12-31 02:53:25 +00:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="/signup"
|
|
|
|
element={
|
2024-06-10 10:57:57 +00:00
|
|
|
<Navigate
|
|
|
|
to="/"
|
|
|
|
replace
|
|
|
|
state={{ redirectTo: "/signup" }}
|
|
|
|
/>
|
2023-12-31 02:53:25 +00:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Route
|
2024-01-21 01:13:11 +00:00
|
|
|
path="/recover"
|
2023-12-31 02:53:25 +00:00
|
|
|
element={
|
2024-06-10 10:57:57 +00:00
|
|
|
<Navigate
|
|
|
|
to="/"
|
|
|
|
replace
|
|
|
|
state={{ redirectTo: "/recover" }}
|
|
|
|
/>
|
2024-01-21 01:13:11 +00:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="/changepwd"
|
|
|
|
element={
|
|
|
|
<Navigate
|
|
|
|
to="/"
|
|
|
|
replace
|
|
|
|
state={{
|
|
|
|
redirectTo: window.location.pathname + window.location.search,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="/changepwd/expired"
|
|
|
|
element={
|
|
|
|
<Navigate
|
|
|
|
to="/"
|
|
|
|
replace
|
|
|
|
state={{ redirectTo: "/changepwd/expired" }}
|
|
|
|
/>
|
2023-12-31 02:53:25 +00:00
|
|
|
}
|
|
|
|
/>
|
2024-05-17 14:13:05 +00:00
|
|
|
<Route
|
|
|
|
path="/gallery"
|
|
|
|
element={<LazyLoading children={<QuizGallery />} />}
|
|
|
|
/>
|
2024-03-20 12:16:21 +00:00
|
|
|
<Route
|
|
|
|
path="/list"
|
2024-06-10 10:57:57 +00:00
|
|
|
element={
|
|
|
|
<LazyLoading
|
|
|
|
children={<MyQuizzesFull />}
|
|
|
|
fallback={<ListPageDummy />}
|
|
|
|
/>
|
|
|
|
}
|
2024-03-20 12:16:21 +00:00
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path={"/view/:quizId"}
|
|
|
|
element={<LazyLoading children={<ViewPage />} />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path={"/tariffs"}
|
|
|
|
element={<LazyLoading children={<Tariffs />} />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path={"/analytics"}
|
|
|
|
element={<LazyLoading children={<Analytics />} />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path={"/results/:quizId"}
|
|
|
|
element={<LazyLoading children={<QuizAnswersPage />} />}
|
|
|
|
/>
|
2024-04-12 15:54:23 +00:00
|
|
|
<Route
|
|
|
|
path={"/qaz"}
|
|
|
|
element={<LazyLoading children={<InfoPrivilege />} />}
|
|
|
|
/>
|
2024-06-10 10:57:57 +00:00
|
|
|
<Route
|
|
|
|
path={"/image/:srcImage"}
|
|
|
|
element={<ChatImageNewWindow />}
|
|
|
|
/>
|
2023-12-31 02:53:25 +00:00
|
|
|
<Route element={<PrivateRoute />}>
|
|
|
|
{routeslink.map((e, i) => (
|
|
|
|
<Route
|
|
|
|
key={i}
|
|
|
|
path={e.path}
|
|
|
|
element={
|
2024-03-20 12:16:21 +00:00
|
|
|
<LazyLoading
|
|
|
|
children={
|
|
|
|
<Main
|
|
|
|
Page={e.page}
|
|
|
|
header={e.header}
|
|
|
|
sidebar={e.sidebar}
|
|
|
|
footer={e.footer}
|
|
|
|
/>
|
|
|
|
}
|
2024-01-04 00:12:12 +00:00
|
|
|
/>
|
2023-12-31 02:53:25 +00:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
))}
|
2024-01-15 18:42:59 +00:00
|
|
|
</Route>
|
2023-12-31 02:53:25 +00:00
|
|
|
</Routes>
|
|
|
|
</>
|
|
|
|
);
|
2023-12-16 13:02:27 +00:00
|
|
|
}
|