2024-04-04 08:27:06 +00:00
|
|
|
|
import { logout } from "@api/auth";
|
|
|
|
|
import { activatePromocode } from "@api/promocode";
|
2024-04-01 06:34:06 +00:00
|
|
|
|
import type { Tariff } from "@frontend/kitui";
|
2024-04-16 20:20:46 +00:00
|
|
|
|
import { useToken } from "@frontend/kitui";
|
2024-05-13 13:24:41 +00:00
|
|
|
|
import { makeRequest } from "@api/makeRequest";
|
2024-04-04 08:27:06 +00:00
|
|
|
|
import ArrowLeft from "@icons/questionsPage/arrowLeft";
|
2024-01-03 19:41:41 +00:00
|
|
|
|
import type { GetTariffsResponse } from "@model/tariff";
|
|
|
|
|
import {
|
2024-01-03 22:55:01 +00:00
|
|
|
|
Box,
|
|
|
|
|
Button,
|
2024-01-05 08:43:42 +00:00
|
|
|
|
Container,
|
2024-04-01 06:34:06 +00:00
|
|
|
|
IconButton,
|
2024-01-03 22:55:01 +00:00
|
|
|
|
Modal,
|
|
|
|
|
Paper,
|
|
|
|
|
Typography,
|
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme,
|
2024-01-03 19:41:41 +00:00
|
|
|
|
} from "@mui/material";
|
2024-04-04 08:27:06 +00:00
|
|
|
|
import { clearQuizData } from "@root/quizes/store";
|
|
|
|
|
import { cleanAuthTicketData } from "@root/ticket";
|
|
|
|
|
import { clearUserData, useUserStore } from "@root/user";
|
|
|
|
|
import { LogoutButton } from "@ui_kit/LogoutButton";
|
|
|
|
|
import { useDomainDefine } from "@utils/hooks/useDomainDefine";
|
2024-01-03 19:41:41 +00:00
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
2024-04-04 08:27:06 +00:00
|
|
|
|
import { useEffect, useState } from "react";
|
2024-01-03 19:41:41 +00:00
|
|
|
|
import { withErrorBoundary } from "react-error-boundary";
|
2024-04-04 08:27:06 +00:00
|
|
|
|
import { Link, useNavigate } from "react-router-dom";
|
2024-01-05 08:43:42 +00:00
|
|
|
|
import Logotip from "../../pages/Landing/images/icons/QuizLogo";
|
2024-03-22 19:01:48 +00:00
|
|
|
|
import CollapsiblePromocodeField from "./CollapsiblePromocodeField";
|
2024-04-04 08:27:06 +00:00
|
|
|
|
import { Tabs } from "./Tabs";
|
|
|
|
|
import { createTariffElements } from "./tariffsUtils/createTariffElements";
|
|
|
|
|
import { currencyFormatter } from "./tariffsUtils/currencyFormatter";
|
2024-04-06 09:07:30 +00:00
|
|
|
|
import { useWallet, setCash } from "@root/cash";
|
2024-04-08 23:11:19 +00:00
|
|
|
|
import { handleLogoutClick } from "@utils/HandleLogoutClick";
|
2024-05-02 08:38:57 +00:00
|
|
|
|
import { getDiscounts } from "@api/discounts";
|
2024-05-15 11:44:10 +00:00
|
|
|
|
import { cartApi } from "@api/cart";
|
|
|
|
|
import { getUser } from "@api/user";
|
|
|
|
|
import { getTariffs } from "@api/tariff";
|
2024-05-02 08:38:57 +00:00
|
|
|
|
|
|
|
|
|
import type { Discount } from "@model/discounts";
|
2024-08-18 04:18:59 +00:00
|
|
|
|
import { Other } from "./pages/Other";
|
|
|
|
|
import { ModalRequestCreate } from "./ModalRequestCreate";
|
2024-01-15 20:42:30 +00:00
|
|
|
|
|
|
|
|
|
const StepperText: Record<string, string> = {
|
|
|
|
|
day: "Тарифы на время",
|
2024-04-05 16:29:20 +00:00
|
|
|
|
count: "Тарифы на объём",
|
2024-03-30 18:54:28 +00:00
|
|
|
|
dop: "Доп. услуги",
|
2024-01-15 20:42:30 +00:00
|
|
|
|
};
|
2024-01-09 12:00:42 +00:00
|
|
|
|
|
2024-01-03 19:41:41 +00:00
|
|
|
|
function TariffPage() {
|
2024-08-18 04:18:59 +00:00
|
|
|
|
const userPrivilegies = useUserStore(store => store.userAccount?.privileges);
|
2024-01-03 22:55:01 +00:00
|
|
|
|
const theme = useTheme();
|
2024-01-28 20:45:13 +00:00
|
|
|
|
const token = useToken();
|
2024-01-03 22:55:01 +00:00
|
|
|
|
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
2024-03-14 21:49:14 +00:00
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
2024-01-28 20:08:06 +00:00
|
|
|
|
const userId = useUserStore((state) => state.userId);
|
2024-01-03 22:55:01 +00:00
|
|
|
|
const navigate = useNavigate();
|
2024-01-09 12:00:42 +00:00
|
|
|
|
const [tariffs, setTariffs] = useState<Tariff[]>([]);
|
2024-01-03 22:55:01 +00:00
|
|
|
|
const [user, setUser] = useState();
|
2024-05-02 08:38:57 +00:00
|
|
|
|
const [discounts, setDiscounts] = useState<Discount[]>([]);
|
2024-08-18 04:18:59 +00:00
|
|
|
|
const [isRequestCreate, setIsRequestCreate] = useState(false);
|
2024-01-03 22:55:01 +00:00
|
|
|
|
const [openModal, setOpenModal] = useState({});
|
2024-04-07 16:19:49 +00:00
|
|
|
|
const { cashString, cashCop, cashRub } = useWallet();
|
2024-08-18 04:18:59 +00:00
|
|
|
|
const [selectedItem, setSelectedItem] = useState<TypePages>("day");
|
2024-03-16 12:14:25 +00:00
|
|
|
|
const { isTestServer } = useDomainDefine();
|
2024-03-22 19:01:48 +00:00
|
|
|
|
const [promocodeField, setPromocodeField] = useState<string>("");
|
2024-01-03 19:41:41 +00:00
|
|
|
|
|
2024-01-09 12:00:42 +00:00
|
|
|
|
const getTariffsList = async (): Promise<Tariff[]> => {
|
|
|
|
|
const tariffsList: Tariff[] = [];
|
2024-07-16 22:18:52 +00:00
|
|
|
|
let page = 2
|
|
|
|
|
const [tariffsResponse, tariffsResponseError] = await getTariffs(page - 1);
|
2024-05-15 11:44:10 +00:00
|
|
|
|
|
|
|
|
|
if (tariffsResponseError || !tariffsResponse) {
|
|
|
|
|
return tariffsList;
|
|
|
|
|
}
|
2024-01-09 12:00:42 +00:00
|
|
|
|
|
2024-05-15 11:44:10 +00:00
|
|
|
|
tariffsList.push(...tariffsResponse.tariffs);
|
2024-01-09 12:00:42 +00:00
|
|
|
|
|
2024-07-16 22:18:52 +00:00
|
|
|
|
for (page; page <= tariffsResponse.totalPages; page += 1) {
|
2024-07-10 20:56:32 +00:00
|
|
|
|
const [tariffsResult] = await getTariffs(page);
|
2024-01-09 12:00:42 +00:00
|
|
|
|
|
2024-05-15 11:44:10 +00:00
|
|
|
|
if (tariffsResult) {
|
|
|
|
|
tariffsList.push(...tariffsResult.tariffs);
|
|
|
|
|
}
|
2024-01-09 12:00:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tariffsList;
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-03 22:55:01 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
const get = async () => {
|
2024-05-15 11:44:10 +00:00
|
|
|
|
const [user, userError] = await getUser();
|
|
|
|
|
|
|
|
|
|
if (userError) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 12:00:42 +00:00
|
|
|
|
const tariffsList = await getTariffsList();
|
2024-05-02 08:38:57 +00:00
|
|
|
|
|
|
|
|
|
if (userId) {
|
|
|
|
|
const [discounts] = await getDiscounts(userId);
|
|
|
|
|
|
|
|
|
|
if (discounts?.length) {
|
|
|
|
|
setDiscounts(discounts);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 22:55:01 +00:00
|
|
|
|
setUser(user);
|
2024-01-09 12:00:42 +00:00
|
|
|
|
setTariffs(tariffsList);
|
2024-05-02 08:38:57 +00:00
|
|
|
|
|
2024-04-07 16:19:49 +00:00
|
|
|
|
let cs = currencyFormatter.format(Number(user.wallet.cash) / 100);
|
|
|
|
|
let cc = Number(user.wallet.cash);
|
|
|
|
|
let cr = Number(user.wallet.cash) / 100;
|
|
|
|
|
setCash(cs, cc, cr);
|
2024-01-03 22:55:01 +00:00
|
|
|
|
};
|
|
|
|
|
get();
|
|
|
|
|
}, []);
|
2024-01-03 19:41:41 +00:00
|
|
|
|
|
2024-01-03 22:55:01 +00:00
|
|
|
|
if (!user || !tariffs || !discounts) return <LoadingPage />;
|
2024-01-03 19:41:41 +00:00
|
|
|
|
|
2024-01-03 22:55:01 +00:00
|
|
|
|
const openModalHC = (tariffInfo: any) => setOpenModal(tariffInfo);
|
|
|
|
|
const tryBuy = async ({ id, price }: { id: string; price: number }) => {
|
|
|
|
|
openModalHC({});
|
|
|
|
|
//Если в корзине что-то было - выкладываем содержимое и запоминаем чо там лежало
|
|
|
|
|
if (user.cart.length > 0) {
|
|
|
|
|
outCart(user.cart);
|
|
|
|
|
}
|
2024-01-04 01:15:39 +00:00
|
|
|
|
//Добавляем желаемый тариф в корзину
|
2024-05-15 11:44:10 +00:00
|
|
|
|
const [_, addError] = await cartApi.add(id);
|
|
|
|
|
|
|
|
|
|
if (addError) {
|
|
|
|
|
//Развращаем товары в корзину
|
|
|
|
|
inCart();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 22:55:01 +00:00
|
|
|
|
//Если нам хватает денежек - покупаем тариф
|
2024-05-15 11:44:10 +00:00
|
|
|
|
const [data, payError] = await cartApi.pay();
|
2024-01-04 01:15:39 +00:00
|
|
|
|
|
2024-05-15 11:44:10 +00:00
|
|
|
|
if (payError || !data) {
|
2024-04-13 23:48:51 +00:00
|
|
|
|
//если денег не хватило
|
2024-07-05 16:30:02 +00:00
|
|
|
|
if (payError?.includes("insufficient funds") || payError?.includes("Payment Required")) {
|
2024-05-15 13:51:41 +00:00
|
|
|
|
let cashDif = Number(payError.split(":")[1]);
|
2024-04-13 23:48:51 +00:00
|
|
|
|
var link = document.createElement("a");
|
|
|
|
|
link.href = `https://${isTestServer ? "s" : ""}hub.pena.digital/quizpayment?action=squizpay&dif=${cashDif}&data=${token}&userid=${userId}`;
|
|
|
|
|
document.body.appendChild(link);
|
2024-07-09 12:41:18 +00:00
|
|
|
|
link.click();
|
2024-04-17 14:16:49 +00:00
|
|
|
|
return;
|
2024-01-03 22:55:01 +00:00
|
|
|
|
}
|
2024-05-15 13:51:41 +00:00
|
|
|
|
|
2024-04-13 23:48:51 +00:00
|
|
|
|
//другая ошибка
|
|
|
|
|
enqueueSnackbar("Произошла ошибка. Попробуйте позже");
|
2024-05-15 11:44:10 +00:00
|
|
|
|
|
|
|
|
|
return;
|
2024-01-03 22:55:01 +00:00
|
|
|
|
}
|
2024-05-15 11:44:10 +00:00
|
|
|
|
|
|
|
|
|
setCash(
|
|
|
|
|
currencyFormatter.format(Number(data.wallet.cash) / 100),
|
|
|
|
|
Number(data.wallet.cash),
|
|
|
|
|
Number(data.wallet.cash) / 100,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
enqueueSnackbar("Тариф успешно приобретён");
|
|
|
|
|
|
2024-04-13 23:48:51 +00:00
|
|
|
|
//Развращаем товары в корзину
|
|
|
|
|
inCart();
|
2024-01-03 22:55:01 +00:00
|
|
|
|
};
|
2024-01-03 19:41:41 +00:00
|
|
|
|
|
2024-01-09 12:00:42 +00:00
|
|
|
|
const filteredTariffs = tariffs.filter((tariff) => {
|
2024-01-03 19:41:41 +00:00
|
|
|
|
return (
|
2024-01-03 22:55:01 +00:00
|
|
|
|
tariff.privileges[0].serviceKey === "squiz" &&
|
|
|
|
|
!tariff.isDeleted &&
|
2024-01-15 20:42:30 +00:00
|
|
|
|
!tariff.isCustom &&
|
|
|
|
|
tariff.privileges[0]?.type === selectedItem
|
2024-01-03 19:41:41 +00:00
|
|
|
|
);
|
2024-01-03 22:55:01 +00:00
|
|
|
|
});
|
|
|
|
|
|
2024-08-18 04:18:59 +00:00
|
|
|
|
|
2024-03-30 18:54:28 +00:00
|
|
|
|
const filteredBaseTariffs = filteredTariffs.filter((tariff) => {
|
|
|
|
|
return tariff.privileges[0].privilegeId !== "squizHideBadge";
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-15 11:44:10 +00:00
|
|
|
|
async function handleApplyPromocode() {
|
2024-03-22 19:01:48 +00:00
|
|
|
|
if (!promocodeField) return;
|
|
|
|
|
|
2024-05-15 11:44:10 +00:00
|
|
|
|
const [greetings, error] = await activatePromocode(promocodeField);
|
2024-04-13 22:29:58 +00:00
|
|
|
|
|
2024-05-15 11:44:10 +00:00
|
|
|
|
if (error) {
|
|
|
|
|
enqueueSnackbar(error);
|
2024-05-02 08:38:57 +00:00
|
|
|
|
|
2024-05-15 11:44:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-02 08:43:10 +00:00
|
|
|
|
|
2024-05-15 11:44:10 +00:00
|
|
|
|
enqueueSnackbar(greetings);
|
2024-05-02 08:38:57 +00:00
|
|
|
|
|
2024-05-15 11:44:10 +00:00
|
|
|
|
if (!userId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const [discounts, discountsError] = await getDiscounts(userId);
|
|
|
|
|
|
|
|
|
|
if (discountsError) {
|
|
|
|
|
throw new Error(discountsError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (discounts?.length) {
|
|
|
|
|
setDiscounts(discounts);
|
|
|
|
|
}
|
2024-03-22 19:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-18 04:18:59 +00:00
|
|
|
|
const startRequestCreate = () => {
|
|
|
|
|
setIsRequestCreate(true)
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 22:55:01 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
2024-01-05 08:43:42 +00:00
|
|
|
|
<Container
|
|
|
|
|
component="nav"
|
|
|
|
|
disableGutters
|
|
|
|
|
maxWidth={false}
|
|
|
|
|
sx={{
|
|
|
|
|
px: "16px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
height: "80px",
|
|
|
|
|
alignItems: "center",
|
2024-03-14 21:49:14 +00:00
|
|
|
|
gap: isMobile ? "7px" : isTablet ? "20px" : "60px",
|
2024-01-05 08:43:42 +00:00
|
|
|
|
flexDirection: "row",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
bgcolor: "white",
|
|
|
|
|
borderBottom: "1px solid #E3E3E3",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Link to="/">
|
|
|
|
|
<Logotip width={124} />
|
|
|
|
|
</Link>
|
|
|
|
|
<IconButton onClick={() => navigate("/list")}>
|
|
|
|
|
<ArrowLeft color="black" />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<Box sx={{ display: "flex", ml: "auto" }}>
|
2024-03-19 06:56:21 +00:00
|
|
|
|
<Box sx={{ whiteSpace: "nowrap" }}>
|
2024-01-05 08:43:42 +00:00
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "12px",
|
|
|
|
|
lineHeight: "14px",
|
|
|
|
|
color: "gray",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Мой баланс
|
|
|
|
|
</Typography>
|
2024-03-14 21:49:14 +00:00
|
|
|
|
<Typography
|
|
|
|
|
variant="body2"
|
|
|
|
|
color={"#7e2aea"}
|
2024-04-07 16:19:49 +00:00
|
|
|
|
fontSize={
|
|
|
|
|
isMobile ? (cashString.length > 9 ? "13px" : "16px") : "16px"
|
|
|
|
|
}
|
2024-03-14 21:49:14 +00:00
|
|
|
|
>
|
2024-04-07 16:19:49 +00:00
|
|
|
|
{cashString}
|
2024-01-05 08:43:42 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
<LogoutButton
|
2024-04-08 23:11:19 +00:00
|
|
|
|
onClick={() => {
|
|
|
|
|
navigate("/");
|
|
|
|
|
handleLogoutClick();
|
|
|
|
|
}}
|
2024-01-05 08:43:42 +00:00
|
|
|
|
sx={{
|
|
|
|
|
ml: "20px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</Container>
|
2024-03-22 19:01:48 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
p: "25px",
|
|
|
|
|
pb: 0,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<CollapsiblePromocodeField
|
|
|
|
|
fieldValue={promocodeField}
|
|
|
|
|
onFieldChange={setPromocodeField}
|
|
|
|
|
onPromocodeApply={handleApplyPromocode}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
2024-01-16 12:28:30 +00:00
|
|
|
|
<Tabs
|
|
|
|
|
names={Object.values(StepperText)}
|
|
|
|
|
items={Object.keys(StepperText)}
|
|
|
|
|
selectedItem={selectedItem}
|
|
|
|
|
setSelectedItem={setSelectedItem}
|
2024-08-18 04:18:59 +00:00
|
|
|
|
toDop={() => setSelectedItem("dop")}
|
2024-01-16 12:28:30 +00:00
|
|
|
|
/>
|
|
|
|
|
|
2024-01-03 22:55:01 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
justifyContent: "left",
|
2024-03-30 18:54:28 +00:00
|
|
|
|
display: selectedItem === "dop" ? "flex" : "grid",
|
2024-01-03 22:55:01 +00:00
|
|
|
|
gap: "40px",
|
2024-01-05 08:43:42 +00:00
|
|
|
|
p: "20px",
|
2024-08-18 04:18:59 +00:00
|
|
|
|
gridTemplateColumns: `repeat(auto-fit, minmax(300px, ${isTablet ? "436px" : "360px"
|
|
|
|
|
}))`,
|
2024-03-30 18:54:28 +00:00
|
|
|
|
flexDirection: selectedItem === "dop" ? "column" : undefined,
|
2024-01-03 22:55:01 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2024-03-30 18:54:28 +00:00
|
|
|
|
{selectedItem === "day" &&
|
|
|
|
|
createTariffElements(
|
|
|
|
|
filteredBaseTariffs,
|
|
|
|
|
true,
|
|
|
|
|
user,
|
|
|
|
|
discounts,
|
|
|
|
|
openModalHC,
|
|
|
|
|
)}
|
|
|
|
|
{selectedItem === "count" &&
|
|
|
|
|
createTariffElements(
|
|
|
|
|
filteredTariffs,
|
|
|
|
|
true,
|
|
|
|
|
user,
|
|
|
|
|
discounts,
|
|
|
|
|
openModalHC,
|
|
|
|
|
)}
|
2024-08-18 04:18:59 +00:00
|
|
|
|
{(selectedItem === "dop" || selectedItem === "hide" || selectedItem === "create")
|
|
|
|
|
&& (
|
|
|
|
|
<Other
|
|
|
|
|
selectedItem={selectedItem}
|
|
|
|
|
content={[
|
|
|
|
|
{
|
|
|
|
|
title: `Убрать логотип “PenaQuiz”`,
|
|
|
|
|
onClick: () => setSelectedItem("hide")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: "Создать квиз на заказ",
|
|
|
|
|
onClick: () => setSelectedItem("create")
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
|
|
|
|
|
tariffs={tariffs}
|
|
|
|
|
user={user}
|
|
|
|
|
discounts={discounts}
|
|
|
|
|
openModalHC={openModalHC}
|
|
|
|
|
userPrivilegies={userPrivilegies}
|
|
|
|
|
startRequestCreate={startRequestCreate}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2024-01-03 22:55:01 +00:00
|
|
|
|
</Box>
|
|
|
|
|
<Modal
|
|
|
|
|
open={Object.values(openModal).length > 0}
|
|
|
|
|
onClose={() => setOpenModal({})}
|
|
|
|
|
>
|
|
|
|
|
<Paper
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute" as "absolute",
|
|
|
|
|
top: "50%",
|
|
|
|
|
left: "50%",
|
|
|
|
|
transform: "translate(-50%, -50%)",
|
|
|
|
|
boxShadow: 24,
|
|
|
|
|
p: 4,
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography
|
|
|
|
|
id="modal-modal-title"
|
|
|
|
|
variant="h6"
|
|
|
|
|
component="h2"
|
|
|
|
|
mb="20px"
|
|
|
|
|
>
|
2024-04-07 16:19:49 +00:00
|
|
|
|
Вы подтверждаете платёж в сумму{" "}
|
|
|
|
|
{openModal.price ? openModal.price.toFixed(2) : 0} ₽
|
2024-01-03 22:55:01 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
<Button variant="contained" onClick={() => tryBuy(openModal)}>
|
|
|
|
|
купить
|
|
|
|
|
</Button>
|
|
|
|
|
</Paper>
|
|
|
|
|
</Modal>
|
2024-08-18 04:18:59 +00:00
|
|
|
|
<ModalRequestCreate open={isRequestCreate} onClose={() => setIsRequestCreate(false)} />
|
2024-01-03 22:55:01 +00:00
|
|
|
|
</>
|
|
|
|
|
);
|
2024-01-03 19:41:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-04 01:15:39 +00:00
|
|
|
|
export const Tariffs = withErrorBoundary(TariffPage, {
|
2024-01-03 22:55:01 +00:00
|
|
|
|
fallback: (
|
|
|
|
|
<Typography mt="8px" textAlign="center">
|
|
|
|
|
Ошибка загрузки тарифов
|
|
|
|
|
</Typography>
|
|
|
|
|
),
|
2024-08-18 04:18:59 +00:00
|
|
|
|
onError: () => { },
|
2024-01-03 19:41:41 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const LoadingPage = () => (
|
2024-01-03 22:55:01 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
2024-07-05 16:30:02 +00:00
|
|
|
|
height: "100vh",
|
2024-01-03 22:55:01 +00:00
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography sx={{ textAlign: "center" }}>
|
2024-07-05 16:30:02 +00:00
|
|
|
|
{"Подождите, пожалуйста, идёт загрузка"}
|
2024-01-03 22:55:01 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
2024-01-03 19:41:41 +00:00
|
|
|
|
);
|
|
|
|
|
|
2024-01-04 01:15:39 +00:00
|
|
|
|
export const inCart = () => {
|
2024-01-03 22:55:01 +00:00
|
|
|
|
let saveCart = JSON.parse(localStorage.getItem("saveCart") || "[]");
|
2024-01-05 08:43:42 +00:00
|
|
|
|
if (Array.isArray(saveCart)) {
|
|
|
|
|
saveCart.forEach(async (id: string) => {
|
2024-05-15 11:44:10 +00:00
|
|
|
|
const [_, addError] = await cartApi.add(id);
|
2024-01-03 19:41:41 +00:00
|
|
|
|
|
2024-05-15 11:44:10 +00:00
|
|
|
|
if (addError) {
|
|
|
|
|
console.error(addError);
|
|
|
|
|
} else {
|
2024-01-05 08:43:42 +00:00
|
|
|
|
let index = saveCart.indexOf("green");
|
2024-05-15 11:44:10 +00:00
|
|
|
|
|
2024-01-05 08:43:42 +00:00
|
|
|
|
if (index !== -1) {
|
|
|
|
|
saveCart.splice(index, 1);
|
|
|
|
|
}
|
2024-05-15 11:44:10 +00:00
|
|
|
|
|
2024-01-05 08:43:42 +00:00
|
|
|
|
localStorage.setItem("saveCart", JSON.stringify(saveCart));
|
2024-01-03 22:55:01 +00:00
|
|
|
|
}
|
2024-01-05 08:43:42 +00:00
|
|
|
|
});
|
|
|
|
|
} else {
|
2024-01-05 11:51:05 +00:00
|
|
|
|
localStorage.setItem("saveCart", "[]");
|
2024-01-05 08:43:42 +00:00
|
|
|
|
}
|
2024-01-03 22:55:01 +00:00
|
|
|
|
};
|
2024-01-03 19:41:41 +00:00
|
|
|
|
const outCart = (cart: string[]) => {
|
2024-01-03 22:55:01 +00:00
|
|
|
|
//Сделаем муторно и подольше, зато при прерывании сессии данные потеряются минимально
|
2024-07-10 16:13:37 +00:00
|
|
|
|
if (cart.length > 0) {
|
2024-08-18 04:18:59 +00:00
|
|
|
|
cart.forEach(async (id: string) => {
|
|
|
|
|
const [_, deleteError] = await cartApi.delete(id);
|
2024-05-15 11:44:10 +00:00
|
|
|
|
|
2024-08-18 04:18:59 +00:00
|
|
|
|
if (deleteError) {
|
|
|
|
|
console.error(deleteError);
|
2024-05-15 11:44:10 +00:00
|
|
|
|
|
2024-08-18 04:18:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-15 11:44:10 +00:00
|
|
|
|
|
2024-08-18 04:18:59 +00:00
|
|
|
|
let saveCart = JSON.parse(localStorage.getItem("saveCart") || "[]") || [];
|
|
|
|
|
if (!Array.isArray(saveCart)) saveCart = []
|
|
|
|
|
saveCart = saveCart.push(id);
|
|
|
|
|
localStorage.setItem("saveCart", JSON.stringify(saveCart));
|
|
|
|
|
});
|
2024-07-10 16:13:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 22:55:01 +00:00
|
|
|
|
};
|