diff --git a/package.json b/package.json index 87493c39..af12ffe6 100755 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "@emotion/react": "^11.10.5", "@emotion/styled": "^11.10.5", "@frontend/kitui": "^1.0.82", - "@frontend/squzanswerer": "^1.0.37", + "@frontend/squzanswerer": "^1.0.38", "@mui/icons-material": "^5.10.14", "@mui/material": "^5.10.14", "@mui/x-charts": "^6.19.5", diff --git a/src/App.tsx b/src/App.tsx index 9b451632..1ce92906 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -283,8 +283,8 @@ export default function App() { path={"/qaz"} element={} />} /> + } /> }> - } /> {routeslink.map((e, i) => ( state.userId); + const navigate = useNavigate(); const [discounts, setDiscounts] = useState([]); const [askToChange, setAskToChange] = useState(false); const [promocode, setPromocode] = useState(""); - + console.log( + user.userAccount, + user.customerAccount) useEffect(() => { const get = async () => { - if (!userId) { + if (!user.userId) { return; } - const [discounts] = await getDiscounts(userId); + const [discounts] = await getDiscounts(user.userId); if (discounts?.length) { setDiscounts(discounts); @@ -48,6 +55,16 @@ export function CheckFastlink() { }); enqueueSnackbar("Промокод успешно применён"); localStorage.setItem("fl", ""); + const controller = new AbortController(); + const responseAccount = await makeRequest({ + url: process.env.REACT_APP_DOMAIN + "/squiz/account/get", + contentType: true, + method: "GET", + useToken: true, + withCredentials: false, + signal: controller.signal, + }) + setUserAccount(responseAccount) mutate("discounts"); return response.greetings; } catch (nativeError) { @@ -75,16 +92,20 @@ export function CheckFastlink() { if (flLS !== null && flLS.length > 0) { setPromocode(flLS); - if (userId !== null) { + if (user.userId !== null) { //У нас есть промокод и юзер авторизован. Проверяем есть ли у него применённый промокод - if (discounts?.find((e) => e.Condition.User === userId)) { - setAskToChange(true); - } else { - fetchPromocode(); + //Проверяем были ли запросы на аккаунт и кастомер аккаунт + if (user.userAccount !== null && user.customerAccount !== null) { + if (discounts?.find((e) => e.Condition.User === user.userId)) { + setAskToChange(true); + } else { + fetchPromocode(); + } } } } - }, [userId, discounts]); + }, [user.userId, discounts, user.customerAccount?.createdAt, user.userAccount?.created_at]); + return (