Merge branch 'staging' into 'main'
Staging See merge request frontend/squiz!315
This commit is contained in:
commit
516fd5649d
@ -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",
|
||||
|
||||
@ -283,8 +283,8 @@ export default function App() {
|
||||
path={"/qaz"}
|
||||
element={<LazyLoading children={<InfoPrivilege />} />}
|
||||
/>
|
||||
<Route path={"/image/:srcImage"} element={<ChatImageNewWindow />} />
|
||||
<Route element={<PrivateRoute />}>
|
||||
<Route path={"/image/:srcImage"} element={<ChatImageNewWindow />} />
|
||||
{routeslink.map((e, i) => (
|
||||
<Route
|
||||
key={i}
|
||||
|
||||
@ -122,6 +122,7 @@ export const DesignFilling = ({
|
||||
width: "100%",
|
||||
borderRadius: "12px",
|
||||
height: "calc(100vh - 300px)",
|
||||
mb: "76px"
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { useEffect, useLayoutEffect, useState } from "react";
|
||||
import {useEffect, useLayoutEffect, useRef, useState} from "react";
|
||||
import { Box, Button, Modal, Typography } from "@mui/material";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { mutate } from "swr";
|
||||
@ -6,24 +6,31 @@ import { mutate } from "swr";
|
||||
import makeRequest from "@api/makeRequest";
|
||||
import { getDiscounts } from "@api/discounts";
|
||||
|
||||
import { useUserStore } from "@root/user";
|
||||
import {clearUserData, OriginalUserAccount, setUserAccount, useUserStore} from "@root/user";
|
||||
import { parseAxiosError } from "@utils/parse-error";
|
||||
|
||||
import { useUserAccountFetcher } from "../App";
|
||||
import type { Discount } from "@model/discounts";
|
||||
import {clearAuthToken, createUserAccount, devlog, getMessageFromFetchError} from "@frontend/kitui";
|
||||
import {useNavigate} from "react-router-dom";
|
||||
import {isAxiosError} from "axios";
|
||||
|
||||
export function CheckFastlink() {
|
||||
const user = useUserStore();
|
||||
const userId = useUserStore((state) => state.userId);
|
||||
const navigate = useNavigate();
|
||||
const [discounts, setDiscounts] = useState<Discount[]>([]);
|
||||
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<never, any>({
|
||||
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 (
|
||||
<Modal
|
||||
|
||||
Loading…
Reference in New Issue
Block a user