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";
|
|
|
|
|
import { clearAuthToken, makeRequest, useToken } from "@frontend/kitui";
|
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-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-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();
|
|
|
|
|
const [discounts, setDiscounts] = useState();
|
|
|
|
|
const [openModal, setOpenModal] = useState({});
|
2024-01-05 08:43:42 +00:00
|
|
|
|
const [cash, setCash] = useState("0");
|
2024-04-05 16:29:20 +00:00
|
|
|
|
const [selectedItem, setSelectedItem] = useState<"count" | "day" | "dop">(
|
|
|
|
|
"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[] = [];
|
|
|
|
|
const { tariffs, totalPages } = await makeRequest<
|
|
|
|
|
never,
|
|
|
|
|
GetTariffsResponse
|
|
|
|
|
>({
|
|
|
|
|
method: "GET",
|
2024-01-18 01:56:15 +00:00
|
|
|
|
url: process.env.REACT_APP_DOMAIN + "/strator/tariff?page=1&limit=100",
|
2024-01-09 12:00:42 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tariffsList.push(...tariffs);
|
|
|
|
|
|
|
|
|
|
for (let page = 2; page <= totalPages; page += 1) {
|
|
|
|
|
const tariffsResult = await makeRequest<never, GetTariffsResponse>({
|
|
|
|
|
method: "GET",
|
2024-01-19 14:24:35 +00:00
|
|
|
|
url:
|
|
|
|
|
process.env.REACT_APP_DOMAIN +
|
|
|
|
|
`/strator/tariff?page=${page}&limit=100`,
|
2024-01-09 12:00:42 +00:00
|
|
|
|
});
|
|
|
|
|
|
2024-01-15 20:42:30 +00:00
|
|
|
|
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 () => {
|
|
|
|
|
const user = await makeRequest({
|
|
|
|
|
method: "GET",
|
2024-01-18 01:56:15 +00:00
|
|
|
|
url: process.env.REACT_APP_DOMAIN + "/customer/account",
|
2024-01-03 22:55:01 +00:00
|
|
|
|
});
|
2024-01-09 12:00:42 +00:00
|
|
|
|
const tariffsList = await getTariffsList();
|
2024-01-03 22:55:01 +00:00
|
|
|
|
const discounts = await makeRequest({
|
|
|
|
|
method: "GET",
|
2024-04-04 00:10:08 +00:00
|
|
|
|
url: `${process.env.REACT_APP_DOMAIN}/price/discount/user/${userId}`,
|
2024-01-03 22:55:01 +00:00
|
|
|
|
});
|
|
|
|
|
setUser(user);
|
2024-01-09 12:00:42 +00:00
|
|
|
|
setTariffs(tariffsList);
|
2024-01-03 22:55:01 +00:00
|
|
|
|
setDiscounts(discounts.Discounts);
|
2024-01-05 11:51:05 +00:00
|
|
|
|
let c = currencyFormatter.format(Number(user.wallet.cash) / 100);
|
|
|
|
|
setCash(c);
|
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 }) => {
|
2024-04-05 21:42:02 +00:00
|
|
|
|
console.log("цена", price)
|
|
|
|
|
console.log("мои деньги", (user.wallet.cash / 100))
|
2024-01-03 22:55:01 +00:00
|
|
|
|
openModalHC({});
|
|
|
|
|
//Если в корзине что-то было - выкладываем содержимое и запоминаем чо там лежало
|
|
|
|
|
if (user.cart.length > 0) {
|
|
|
|
|
outCart(user.cart);
|
|
|
|
|
}
|
2024-01-04 01:15:39 +00:00
|
|
|
|
//Добавляем желаемый тариф в корзину
|
|
|
|
|
await makeRequest({
|
|
|
|
|
method: "PATCH",
|
2024-01-19 14:24:35 +00:00
|
|
|
|
url: process.env.REACT_APP_DOMAIN + `/customer/cart?id=${id}`,
|
2024-01-03 19:41:41 +00:00
|
|
|
|
});
|
2024-01-03 22:55:01 +00:00
|
|
|
|
//Если нам хватает денежек - покупаем тариф
|
2024-04-05 21:42:02 +00:00
|
|
|
|
if ((price * 100) <= user.wallet.cash) {
|
2024-01-03 22:55:01 +00:00
|
|
|
|
try {
|
2024-01-05 08:43:42 +00:00
|
|
|
|
const data = await makeRequest({
|
2024-01-03 22:55:01 +00:00
|
|
|
|
method: "POST",
|
2024-01-18 01:56:15 +00:00
|
|
|
|
url: process.env.REACT_APP_DOMAIN + "/customer/cart/pay",
|
2024-01-03 22:55:01 +00:00
|
|
|
|
});
|
2024-01-05 11:51:05 +00:00
|
|
|
|
setCash(currencyFormatter.format(Number(data.wallet.cash) / 100));
|
2024-01-05 08:43:42 +00:00
|
|
|
|
enqueueSnackbar("Тариф успешно приобретён");
|
2024-01-03 22:55:01 +00:00
|
|
|
|
} catch (e) {
|
|
|
|
|
enqueueSnackbar("Произошла ошибка. Попробуйте позже");
|
|
|
|
|
}
|
|
|
|
|
//Развращаем товары в корзину
|
|
|
|
|
inCart();
|
|
|
|
|
} else {
|
|
|
|
|
//Деняк не хватило
|
2024-01-04 01:15:39 +00:00
|
|
|
|
// history.pushState({}, null, "https://hub.pena.digital/wallet?action=squizpay");
|
|
|
|
|
|
|
|
|
|
var link = document.createElement("a");
|
2024-03-19 13:52:33 +00:00
|
|
|
|
link.href = `https://${isTestServer ? "s" : ""}hub.pena.digital/quizpayment?action=squizpay&dif=${
|
2024-04-05 22:47:40 +00:00
|
|
|
|
Math.floor((price * 100) - Math.floor(Number(user.wallet.cash)))
|
2024-04-01 14:49:00 +00:00
|
|
|
|
}&data=${token}&userid=${userId}`;
|
2024-01-04 01:15:39 +00:00
|
|
|
|
document.body.appendChild(link);
|
2024-01-27 16:51:28 +00:00
|
|
|
|
link.click();
|
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-03-30 18:54:28 +00:00
|
|
|
|
const filteredBadgeTariffs = tariffs.filter((tariff) => {
|
|
|
|
|
return (
|
|
|
|
|
tariff.privileges[0].serviceKey === "squiz" &&
|
|
|
|
|
!tariff.isDeleted &&
|
|
|
|
|
!tariff.isCustom &&
|
|
|
|
|
tariff.privileges[0].privilegeId === "squizHideBadge" &&
|
|
|
|
|
tariff.privileges[0]?.type === "day"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
const filteredBaseTariffs = filteredTariffs.filter((tariff) => {
|
|
|
|
|
return tariff.privileges[0].privilegeId !== "squizHideBadge";
|
|
|
|
|
});
|
|
|
|
|
|
2024-01-05 08:43:42 +00:00
|
|
|
|
async function handleLogoutClick() {
|
|
|
|
|
const [, logoutError] = await logout();
|
|
|
|
|
|
|
|
|
|
if (logoutError) {
|
|
|
|
|
return enqueueSnackbar(logoutError);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-09 21:01:57 +00:00
|
|
|
|
cleanAuthTicketData();
|
2024-01-05 08:43:42 +00:00
|
|
|
|
clearAuthToken();
|
|
|
|
|
clearUserData();
|
2024-04-01 06:34:06 +00:00
|
|
|
|
clearQuizData();
|
2024-01-05 08:43:42 +00:00
|
|
|
|
navigate("/");
|
|
|
|
|
}
|
2024-03-22 19:01:48 +00:00
|
|
|
|
|
|
|
|
|
function handleApplyPromocode() {
|
|
|
|
|
if (!promocodeField) return;
|
|
|
|
|
|
|
|
|
|
activatePromocode(promocodeField)
|
|
|
|
|
.then((response) => {
|
|
|
|
|
enqueueSnackbar(response);
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
enqueueSnackbar(error.message);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
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"}
|
|
|
|
|
fontSize={isMobile ? (cash.length > 9 ? "13px" : "16px") : "16px"}
|
|
|
|
|
>
|
2024-01-05 08:43:42 +00:00
|
|
|
|
{cash}
|
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
<LogoutButton
|
|
|
|
|
onClick={handleLogoutClick}
|
|
|
|
|
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-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-01-05 11:51:05 +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,
|
|
|
|
|
)}
|
|
|
|
|
{selectedItem === "dop" && (
|
|
|
|
|
<>
|
|
|
|
|
<Typography fontWeight={500}>Убрать логотип "PenaQuiz"</Typography>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
justifyContent: "left",
|
|
|
|
|
display: "grid",
|
|
|
|
|
gap: "40px",
|
|
|
|
|
gridTemplateColumns: `repeat(auto-fit, minmax(300px, ${
|
|
|
|
|
isTablet ? "436px" : "360px"
|
|
|
|
|
}))`,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{createTariffElements(
|
|
|
|
|
filteredBadgeTariffs,
|
|
|
|
|
false,
|
|
|
|
|
user,
|
|
|
|
|
discounts,
|
|
|
|
|
openModalHC,
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
</>
|
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-05 23:02:58 +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-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-01-05 11:51:05 +00:00
|
|
|
|
onError: () => {},
|
2024-01-03 19:41:41 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const LoadingPage = () => (
|
2024-01-03 22:55:01 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
height: "100%",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography sx={{ textAlign: "center" }}>
|
|
|
|
|
{"Подождите, пожалуйста, идёт загрузка :)"}
|
|
|
|
|
</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) => {
|
|
|
|
|
try {
|
|
|
|
|
await makeRequest({
|
|
|
|
|
method: "PATCH",
|
2024-01-19 14:24:35 +00:00
|
|
|
|
url: process.env.REACT_APP_DOMAIN + `/customer/cart?id=${id}`,
|
2024-01-05 08:43:42 +00:00
|
|
|
|
});
|
2024-01-03 19:41:41 +00:00
|
|
|
|
|
2024-01-05 08:43:42 +00:00
|
|
|
|
let index = saveCart.indexOf("green");
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
saveCart.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
localStorage.setItem("saveCart", JSON.stringify(saveCart));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("Я не смог добавить тариф в корзину :( " + id);
|
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
|
|
|
|
//Сделаем муторно и подольше, зато при прерывании сессии данные потеряются минимально
|
|
|
|
|
cart.forEach(async (id: string) => {
|
|
|
|
|
try {
|
|
|
|
|
await makeRequest({
|
|
|
|
|
method: "DELETE",
|
2024-01-18 01:56:15 +00:00
|
|
|
|
url: process.env.REACT_APP_DOMAIN + `/customer/cart?id=${id}`,
|
2024-01-03 22:55:01 +00:00
|
|
|
|
});
|
|
|
|
|
let saveCart = JSON.parse(localStorage.getItem("saveCart") || "[]");
|
|
|
|
|
saveCart = saveCart.push(id);
|
|
|
|
|
localStorage.setItem("saveCart", JSON.stringify(saveCart));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("Я не смог удалить из корзины тариф :(");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|