применение промокода из fastlink
This commit is contained in:
parent
9c65e6fc0f
commit
e19e234c1c
15
reportWebVitals.ts
Normal file
15
reportWebVitals.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { ReportHandler } from "web-vitals"
|
||||||
|
|
||||||
|
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
|
||||||
|
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||||
|
import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||||
|
getCLS(onPerfEntry)
|
||||||
|
getFID(onPerfEntry)
|
||||||
|
getFCP(onPerfEntry)
|
||||||
|
getLCP(onPerfEntry)
|
||||||
|
getTTFB(onPerfEntry)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default reportWebVitals
|
1
setupTests.ts
Normal file
1
setupTests.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
import "@testing-library/jest-dom"
|
96
src/components/CheckFastlink.tsx
Normal file
96
src/components/CheckFastlink.tsx
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
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();
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
@ -54,6 +54,7 @@ import OutdatedLink from "@root/pages/auth/OutdatedLink";
|
|||||||
import { verify } from "./pages/AccountSettings/helper";
|
import { verify } from "./pages/AccountSettings/helper";
|
||||||
import AfterPay from "./pages/AfterPay";
|
import AfterPay from "./pages/AfterPay";
|
||||||
import { PageNotFound } from "./pages/PageNotFound";
|
import { PageNotFound } from "./pages/PageNotFound";
|
||||||
|
import { CheckFastlink } from "./components/CheckFastlink";
|
||||||
|
|
||||||
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
|
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
|
||||||
"pdfjs-dist/build/pdf.worker.min.js",
|
"pdfjs-dist/build/pdf.worker.min.js",
|
||||||
@ -206,6 +207,7 @@ root.render(
|
|||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<SnackbarProvider />
|
<SnackbarProvider />
|
||||||
<App />
|
<App />
|
||||||
|
<CheckFastlink/>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
// </React.StrictMode>
|
// </React.StrictMode>
|
||||||
|
2852
src/utils/calcCart/TESTdata.ts
Normal file
2852
src/utils/calcCart/TESTdata.ts
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user