обнуление нехватки средств при любых действиях с корзиной и логауте, удалены фастдинки
This commit is contained in:
parent
c57023b9c6
commit
e36247254e
@ -1,96 +0,0 @@
|
||||
import { useLayoutEffect, useState } from "react"
|
||||
import { useUserStore } from "@root/stores/user";
|
||||
import { Box, Button, Modal, Typography } from "@mui/material";
|
||||
import { useDiscounts } from "@root/api/price";
|
||||
import { activatePromocode } from "@root/api/promocode";
|
||||
import { mutate } from "swr";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
|
||||
export function CheckFastlink() {
|
||||
const userId = useUserStore((state) => state.userId);
|
||||
const discounts = useDiscounts(userId);
|
||||
const [askToChange, setAskToChange] = useState(false)
|
||||
const [promocode, setPromocode] = useState("")
|
||||
|
||||
const fetchPromocode = () => {
|
||||
if (promocode.length > 0) {
|
||||
activatePromocode(promocode).then(response => {
|
||||
enqueueSnackbar(response);
|
||||
localStorage.setItem("fl", "")
|
||||
mutate("discounts");
|
||||
}).catch(error => {
|
||||
enqueueSnackbar(error.message);
|
||||
localStorage.setItem("fl", "")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
useLayoutEffect(() => {
|
||||
//Промокод может быть или в урл адресе или в ЛС
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const flURL = params.get("fl");
|
||||
|
||||
if (flURL !== null) {
|
||||
localStorage.setItem("fl", flURL)
|
||||
var url = new URL(window.location.href);
|
||||
url.searchParams.delete('fl');
|
||||
history.pushState(null, document.title, url);
|
||||
}
|
||||
|
||||
const flLS = localStorage.getItem("fl");
|
||||
|
||||
if (flLS !== null && flLS.length > 0) {
|
||||
setPromocode(flLS)
|
||||
|
||||
if (userId !== null) {
|
||||
//У нас есть промокод и юзер авторизован. Проверяем есть ли у него применённый промокод
|
||||
if (discounts?.find(e => e.Condition.User === userId)) {
|
||||
//есть
|
||||
setAskToChange(true)
|
||||
} else {
|
||||
//нет
|
||||
fetchPromocode()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}, [userId, discounts])
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={askToChange}
|
||||
onClose={() => setAskToChange(false)}
|
||||
aria-labelledby="modal-modal-title"
|
||||
aria-describedby="modal-modal-description"
|
||||
>
|
||||
<Box sx={{
|
||||
position: 'absolute' as 'absolute',
|
||||
top: '50%',
|
||||
left: '50%',
|
||||
transform: 'translate(-50%, -50%)',
|
||||
bgcolor: 'background.paper',
|
||||
p: 4,
|
||||
borderRadius: 2
|
||||
}}>
|
||||
<Typography textAlign="center" variant="h6" component="h2">
|
||||
Заменить текущий промокод?
|
||||
</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
mt: "20px",
|
||||
flexWrap: "wrap",
|
||||
justifyContent: "space-evenly"
|
||||
}}
|
||||
>
|
||||
<Button sx={{ margin: "5px", minWidth: " auto" }} variant="pena-contained-dark" onClick={fetchPromocode}>Да</Button>
|
||||
<Button sx={{ margin: "5px", minWidth: " auto" }} variant="pena-contained-dark" onClick={() => {
|
||||
setAskToChange(false)
|
||||
localStorage.setItem("fl", "")
|
||||
}}>Нет</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</Modal>
|
||||
);
|
||||
}
|
@ -173,7 +173,10 @@ function Drawers() {
|
||||
<CartIcon />
|
||||
</Badge>
|
||||
</IconButton>
|
||||
<Drawer anchor={"right"} open={isDrawerOpen} onClose={() => setIsDrawerOpen(false)} sx={{ background: "rgba(0, 0, 0, 0.55)" }}>
|
||||
<Drawer anchor={"right"} open={isDrawerOpen} onClose={() => {
|
||||
setIsDrawerOpen(false)
|
||||
setNotEnoughMoneyAmount(0)
|
||||
}} sx={{ background: "rgba(0, 0, 0, 0.55)" }}>
|
||||
<SectionWrapper
|
||||
maxWidth="lg"
|
||||
sx={{
|
||||
@ -205,7 +208,10 @@ function Drawers() {
|
||||
>
|
||||
Корзина
|
||||
</Typography>
|
||||
<IconButton onClick={() => setIsDrawerOpen(false)} sx={{ p: 0 }}>
|
||||
<IconButton onClick={() => {
|
||||
setIsDrawerOpen(false)
|
||||
setNotEnoughMoneyAmount(0)
|
||||
}} sx={{ p: 0 }}>
|
||||
<CrossIcon />
|
||||
</IconButton>
|
||||
</Box>
|
||||
|
@ -28,6 +28,7 @@ import {
|
||||
import { currencyFormatter } from "@root/utils/currencyFormatter";
|
||||
import { clearCustomTariffs } from "@root/stores/customTariffs";
|
||||
import { clearTickets } from "@root/stores/tickets";
|
||||
import {setNotEnoughMoneyAmount} from "@stores/cart"
|
||||
|
||||
interface Props {
|
||||
isLoggedIn: boolean;
|
||||
@ -47,6 +48,7 @@ export default function NavbarFull({ isLoggedIn }: Props) {
|
||||
clearUserData();
|
||||
clearCustomTariffs();
|
||||
clearTickets();
|
||||
setNotEnoughMoneyAmount(0)
|
||||
navigate("/");
|
||||
|
||||
const [_, logoutError] = await logout();
|
||||
|
@ -17,6 +17,7 @@ import { logout } from "@root/api/auth";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { clearCustomTariffs } from "@root/stores/customTariffs";
|
||||
import { clearTickets } from "@root/stores/tickets";
|
||||
import {setNotEnoughMoneyAmount} from "@stores/cart"
|
||||
|
||||
type MenuItem = {
|
||||
name: string;
|
||||
@ -69,6 +70,7 @@ export default function DialogMenu({ handleClose }: DialogMenuProps) {
|
||||
clearUserData();
|
||||
clearCustomTariffs();
|
||||
clearTickets();
|
||||
setNotEnoughMoneyAmount(0)
|
||||
navigate("/");
|
||||
|
||||
const [_, logoutError] = await logout();
|
||||
|
@ -17,6 +17,7 @@ import { currencyFormatter } from "@root/utils/currencyFormatter";
|
||||
import { clearTickets } from "@root/stores/tickets";
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import {setNotEnoughMoneyAmount} from "@stores/cart"
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
@ -33,6 +34,7 @@ export default function NavbarFull({ children }: Props) {
|
||||
clearUserData();
|
||||
clearCustomTariffs();
|
||||
clearTickets();
|
||||
setNotEnoughMoneyAmount(0)
|
||||
navigate("/");
|
||||
|
||||
const [_, logoutError] = await logout();
|
||||
|
@ -18,6 +18,7 @@ import { clearTickets } from "@root/stores/tickets";
|
||||
import { currencyFormatter } from "@root/utils/currencyFormatter";
|
||||
|
||||
import walletIcon from "@root/assets/Icons/wallet_icon.svg";
|
||||
import {setNotEnoughMoneyAmount} from "@stores/cart"
|
||||
|
||||
export const NavbarPanel = () => {
|
||||
const navigate = useNavigate();
|
||||
@ -31,6 +32,7 @@ export const NavbarPanel = () => {
|
||||
clearUserData();
|
||||
clearCustomTariffs();
|
||||
clearTickets();
|
||||
setNotEnoughMoneyAmount(0)
|
||||
navigate("/");
|
||||
|
||||
const [_, logoutError] = await logout();
|
||||
|
@ -55,7 +55,7 @@ import OutdatedLink from "@root/pages/auth/OutdatedLink";
|
||||
import { verify } from "./pages/AccountSettings/helper";
|
||||
import AfterPay from "./pages/AfterPay";
|
||||
import { PageNotFound } from "./pages/PageNotFound";
|
||||
import { CheckFastlink } from "./components/CheckFastlink";
|
||||
import {setNotEnoughMoneyAmount} from "@stores/cart"
|
||||
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
|
||||
"pdfjs-dist/build/pdf.worker.min.js",
|
||||
@ -67,8 +67,9 @@ const App = () => {
|
||||
const location = useLocation();
|
||||
const userId = useUserStore((state) => state.userId);
|
||||
const navigate = useNavigate();
|
||||
|
||||
console.log(location.pathname === "/cart")
|
||||
console.log(userId);
|
||||
if(location.pathname !== "/cart"){setNotEnoughMoneyAmount(0)}
|
||||
useUserFetcher({
|
||||
url: process.env.REACT_APP_DOMAIN + `/user/${userId}`,
|
||||
userId,
|
||||
@ -212,7 +213,6 @@ root.render(
|
||||
<CssBaseline />
|
||||
<SnackbarProvider />
|
||||
<App />
|
||||
<CheckFastlink />
|
||||
</BrowserRouter>
|
||||
</ThemeProvider>
|
||||
// </React.StrictMode>
|
||||
|
@ -20,6 +20,7 @@ import {
|
||||
import { logout } from "@root/api/auth";
|
||||
import { clearCustomTariffs } from "@root/stores/customTariffs";
|
||||
import { clearTickets } from "@root/stores/tickets";
|
||||
import {setNotEnoughMoneyAmount} from "@stores/cart"
|
||||
|
||||
function refresh(token: string) {
|
||||
return axios<never, AxiosResponse<{ accessToken: string }>>(
|
||||
@ -77,7 +78,7 @@ export default function QuizPayment() {
|
||||
clearUserData();
|
||||
clearCustomTariffs();
|
||||
clearTickets();
|
||||
|
||||
setNotEnoughMoneyAmount(0)
|
||||
await logout();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user