@@ -30,7 +30,8 @@ export const LowBalanceOfferPlate = () => { const offerIndex = modal.getStoreProperty('offerIndex') ?? 1 const offerUid = modal.getStoreProperty('offerUid'); - + const notEnoughtTokens = modal.getStoreProperty('notEnoughtTokens') + const offerToShow = offerUid ? offers?.find((o) => o.uid === offerUid) : offerIndex @@ -40,7 +41,11 @@ export const LowBalanceOfferPlate = () => { return (
e.stopPropagation()}> -

Осталось
мало токенов...

+ {notEnoughtTokens ? ( +

У вас не осталось
токенов...

+ ) : ( +

Осталось
мало токенов...

+ )}

Подобрали для Вас наиболее подходящий тариф,
взгляните на преимущества! @@ -1,4 +1,5 @@ import { useEffect, useRef } from 'react' +import axios from 'axios' import { useAppSelector } from '#/app/store/store' import { getModalById, LOW_BALANCE_OFFER } from '#/features/modals' @@ -7,6 +8,7 @@ import type { ResponseAllInfo } from '#/entities/user-account/model/user-type-sl import { useFeatureFlag } from '#/shared/lib/hooks/use-feature-flag' import { balanceSelector } from '#/shared/lib/selectors' + export const LowBalanceOfferTrigger = () => { const balance = useAppSelector(balanceSelector) const me = useAppSelector((state) => state.user) as ResponseAllInfo & { status: string; referral: string } @@ -14,6 +16,21 @@ export const LowBalanceOfferTrigger = () => { const prevBalanceRef = useRef(null) const modal = getModalById(LOW_BALANCE_OFFER) + useEffect(() => { + const interceptorId = axios.interceptors.response.use( + (response) => { + if (response.status === 402 && response?.data?.detail?.includes('Баланс')) { + invokeLowBalanceOffer(true) + } + return response + }, + ) + + return () => { + axios.interceptors.response.eject(interceptorId) + } + }, []) + useEffect(() => { if (!isFewTokensModalEnabled) return @@ -31,7 +48,12 @@ export const LowBalanceOfferTrigger = () => { return } - const tokensPerPlan = Number(me.payment_plan?.plan?.tokens_per_plan) + invokeLowBalanceOffer(); + } + }, [balance, me, modal, isFewTokensModalEnabled]) + + const invokeLowBalanceOffer = (notEnoughtTokens: boolean = false) => { + const tokensPerPlan = Number(me.payment_plan?.plan?.tokens_per_plan) const isCorporate = me.payment_plan?.plan?.is_corporate const isFreePlan = tokensPerPlan <= 10 const threshold = tokensPerPlan * 0.15 @@ -42,18 +64,17 @@ export const LowBalanceOfferTrigger = () => { } if (!isFreePlan && balance < threshold) { - modal.setState(true, { offerUid: me.payment_plan?.plan?.uid, me }) + modal.setState(true, { offerUid: me.payment_plan?.plan?.uid, me, notEnoughtTokens }) sessionStorage.setItem('low-balance-offer-shown', 'true') return } if (isFreePlan && balance < freePlanThreshold) { - modal.setState(true, { offerIndex: 1 }) + modal.setState(true, { offerIndex: 1, notEnoughtTokens }) sessionStorage.setItem('low-balance-offer-shown', 'true') return } - } - }, [balance, me, modal, isFewTokensModalEnabled]) + } return }