import { Alert, Box, Typography, useMediaQuery, useTheme } from "@mui/material"; import CustomButton from "./CustomButton"; import { currencyFormatter } from "@root/utils/currencyFormatter"; import { payCart } from "@root/api/cart"; import { setUserAccount } from "@root/stores/user"; import { isAxiosError } from "axios"; import { getMessageFromFetchError } from "@frontend/kitui"; import { enqueueSnackbar } from "notistack"; import { useNavigate } from "react-router-dom"; import { useState } from "react"; interface Props { priceBeforeDiscounts: number; priceAfterDiscounts: number; } export default function TotalPrice({ priceAfterDiscounts, priceBeforeDiscounts }: Props) { const theme = useTheme(); const upMd = useMediaQuery(theme.breakpoints.up("md")); const [notEnoughMoneyAmount, setNotEnoughMoneyAmount] = useState(0); const navigate = useNavigate(); function handlePayClick() { payCart() .then((result) => { setUserAccount(result); }) .catch((error) => { if (isAxiosError(error) && error.response?.status === 500) { enqueueSnackbar("В корзине нет товаров"); } if (isAxiosError(error) && error.response?.status === 402) { const notEnoughMoneyAmount = parseInt( (error.response.data.message as string).replace("insufficient funds: ", "") ); setNotEnoughMoneyAmount(notEnoughMoneyAmount); } if (!isAxiosError(error)) { enqueueSnackbar(error.response.data.message); } }); } function handleReplenishWallet() { navigate("/payment", { state: { notEnoughMoneyAmount } }); } return ( Итоговая цена Текст-заполнитель — это текст, который имеет Текст-заполнитель — это текст, который имеет Текст-заполнитель — это текст, который имеет Текст-заполнитель — это текст, который имеет Текст-заполнитель {currencyFormatter.format(priceBeforeDiscounts / 100)} {currencyFormatter.format(priceAfterDiscounts / 100)} {notEnoughMoneyAmount > 0 && ( Нехватает {currencyFormatter.format(notEnoughMoneyAmount / 100)} )} {notEnoughMoneyAmount === 0 ? "Оплатить" : "Пополнить"} ); }