Merge branch 'tariff' into dev
This commit is contained in:
commit
55a91a6dda
@ -23,7 +23,7 @@ import { ResultSettings } from "./pages/ResultPage/ResultSettings";
|
||||
import MyQuizzesFull from "./pages/createQuize/MyQuizzesFull";
|
||||
import Main from "./pages/main";
|
||||
import EditPage from "./pages/startPage/EditPage";
|
||||
import Tariffs from "./pages/Tariffs/Tariffs";
|
||||
import { Tariffs } from "./pages/Tariffs/Tariffs";
|
||||
import {
|
||||
clearAuthToken,
|
||||
getMessageFromFetchError,
|
||||
|
@ -64,6 +64,11 @@ function TariffPage() {
|
||||
if (user.cart.length > 0) {
|
||||
outCart(user.cart);
|
||||
}
|
||||
//Добавляем желаемый тариф в корзину
|
||||
await makeRequest({
|
||||
method: "PATCH",
|
||||
url: `https://hub.pena.digital/customer/cart?id=${id}`,
|
||||
});
|
||||
//Если нам хватает денежек - покупаем тариф
|
||||
if (price <= user.wallet.cash) {
|
||||
try {
|
||||
@ -78,7 +83,14 @@ function TariffPage() {
|
||||
inCart();
|
||||
} else {
|
||||
//Деняк не хватило
|
||||
navigate("https://hub.pena.digital/wallet?action=squizpay");
|
||||
// history.pushState({}, null, "https://hub.pena.digital/wallet?action=squizpay");
|
||||
|
||||
var link = document.createElement("a");
|
||||
link.href = `https://hub.pena.digital/payment?action=squizpay&dif=${
|
||||
(price - Number(user.wallet.cash)) * 100
|
||||
}`;
|
||||
document.body.appendChild(link);
|
||||
// link.click();
|
||||
}
|
||||
};
|
||||
|
||||
@ -149,7 +161,7 @@ function TariffPage() {
|
||||
);
|
||||
}
|
||||
|
||||
export default withErrorBoundary(TariffPage, {
|
||||
export const Tariffs = withErrorBoundary(TariffPage, {
|
||||
fallback: (
|
||||
<Typography mt="8px" textAlign="center">
|
||||
Ошибка загрузки тарифов
|
||||
@ -173,7 +185,7 @@ const LoadingPage = () => (
|
||||
</Box>
|
||||
);
|
||||
|
||||
const inCart = () => {
|
||||
export const inCart = () => {
|
||||
let saveCart = JSON.parse(localStorage.getItem("saveCart") || "[]");
|
||||
saveCart.forEach(async (id: string) => {
|
||||
try {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { useState, useRef } from "react";
|
||||
import { useState, useRef, useLayoutEffect } from "react";
|
||||
import ChartIcon from "@icons/ChartIcon";
|
||||
import LinkIcon from "@icons/LinkIcon";
|
||||
import PencilIcon from "@icons/PencilIcon";
|
||||
@ -15,6 +15,9 @@ import {
|
||||
} from "@mui/material";
|
||||
import { deleteQuiz, setEditQuizId } from "@root/quizes/actions";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { inCart } from "../../pages/Tariffs/Tariffs";
|
||||
import { makeRequest } from "@frontend/kitui";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
|
||||
interface Props {
|
||||
quiz: Quiz;
|
||||
@ -42,6 +45,28 @@ export default function QuizCard({
|
||||
|
||||
const questionCount = useRef(quiz.questions_count.toString() || "");
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const pay = async () => {
|
||||
try {
|
||||
await makeRequest({
|
||||
method: "POST",
|
||||
url: "https://suiz.pena.digital/customer/cart/pay",
|
||||
});
|
||||
inCart();
|
||||
} catch (e) {
|
||||
enqueueSnackbar(
|
||||
"Попробуйте снова купить тариф после зачисления средств",
|
||||
);
|
||||
}
|
||||
};
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const fromSquiz = params.get("action");
|
||||
if (fromSquiz === "fromhub") {
|
||||
window.history.replaceState(null, '', "/list")
|
||||
pay();
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
|
Loading…
Reference in New Issue
Block a user