@@ -1 +0,0 @@ -npm run build \ No newline at end of file Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-Black.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-BlackItalic.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-Bold.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-BoldItalic.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-ExtraBold.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-ExtraBoldItalic.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-ExtraLight.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-ExtraLightItalic.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-Italic.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-Light.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-LightItalic.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-Medium.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-MediumItalic.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-Regular.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-SemiBold.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-SemiBoldItalic.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-Thin.ttf differ Binary files /dev/null and b/public/fonts/Raleway/static/Raleway-ThinItalic.ttf differ Binary files /dev/null and b/public/fonts/Raleway/Raleway-Italic-VariableFont_wght.ttf differ Binary files /dev/null and b/public/fonts/Raleway/Raleway-VariableFont_wght.ttf differ @@ -9,11 +9,14 @@ import { signOut } from 'next-auth/react' import styles from '#/app/layout/styles/styles.module.css' import { useAppSelector } from '#/app/store/store' -import { TooltipCustom } from '#/shared' import { SvgIcon } from '#/shared/ui/svg' import { declineToken } from '#/shared/lib/helpers/get-token' import { IProps } from '#/shared/lib/types/entities' -import { NavigationSearch } from '#/widgets/navigation-search' +import { getDaysLeft } from '#/shared/lib/helpers/date-helper' +import { useFeatureFlag } from '#/shared/lib/hooks/use-feature-flag' +import { SubscriptionDaysBadge } from '#/shared/ui/subscription-days-badge/subscription-days-badge' + +const RECURRENT_PAYMENTS_FLAG = 'recurrent-payments-enabled' interface InfoBarProps extends IProps {} @@ -39,6 +42,9 @@ const convertLang = (toShort: T, lang: LangParam): LangRet } const InfoBar: React.FC = ({ device }) => { + const recurrentPaymentsEnabled = useFeatureFlag(RECURRENT_PAYMENTS_FLAG) + const nextPaymentAt = useAppSelector((state) => state.user.payment_plan.next_payment_at) + const daysLeft = getDaysLeft(nextPaymentAt) const balance = useAppSelector((state) => state.balance.balance) const { email, first_name, last_name, profile_picture_link, account_type, show_balance } = useAppSelector((state) => state.user) @@ -68,8 +74,7 @@ const InfoBar: React.FC = ({ device }) => { return ( - - + = ({ device }) => { marginRight: '80px', }} > + {recurrentPaymentsEnabled && daysLeft != null && daysLeft <= 3 ? ( + + ) : null} { + const modal = getModalById(LOW_BALANCE_OFFER) + + useEffect(() => { + modal.setState(true) + }, []) + + return +} @@ -0,0 +1,47 @@ +.container { + width: 100%; + max-width: 570px; + padding: 32px 0 0 0; + display: flex; + flex-direction: column; + background-color: #151518; + align-items: flex-start; +} + +.text { + color: #8B8B8B; + font-size: 17px; + line-height: 1.5; + margin: 16px 0 24px; +} + +.text_heading { + font-weight: 800; + font-size: 48px; + line-height: 42px; +} + +.offersWrapper { + display: flex; + flex-direction: row; + justify-content: center; + flex-wrap: wrap; + gap: 20px; + width: 100%; + margin-bottom: 24px; + border-radius: 30px; + box-shadow: + 0 0 20px rgba(100, 180, 255, 0.12), + 0 0 40px rgba(80, 150, 255, 0.08), +} + +.link { + font-weight: 600; + font-style: SemiBold; + font-size: 16px; + align-self: center; + + p { + color:#80808E; + } +} @@ -0,0 +1,72 @@ +import React, { useEffect, useState } from 'react' +import Link from 'next/link' +import { useSession } from 'next-auth/react' + +import { LOW_BALANCE_OFFER, getModalById, PlateTemplate } from '#/features/modals' +import { c } from '#/shared' +import { accountApi } from '#/shared/api/account-endpoints' +import { getDeviceType } from '#/shared/lib/helpers' +import { IOffer } from '#/views/subscription' +import Offer from '#/views/subscription/ui/offer' + +import styles from './low-balance-offer-plate.module.scss' + +export const LowBalanceOfferPlate = () => { + const modal = getModalById(LOW_BALANCE_OFFER) + const { data } = useSession() + const [offers, setOffers] = useState(null) + + useEffect(() => { + if (data?.access) { + accountApi.getPaymentsPlans(data.access).then((res) => { + if (res) setOffers(res) + }) + } + }, [data?.access]) + + const handleClose = () => { + modal.setState(false) + } + + 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 + ? offers?.[offerIndex] + : offers?.[1] + + return ( + +
e.stopPropagation()}> + {notEnoughtTokens ? ( +

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

+ ) : ( +

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

+ )} +

+ Подобрали для Вас наиболее подходящий тариф,
+ взгляните на преимущества! +

+
+ {offers === null ? ( +

Загрузка тарифов...

+ ) : offerToShow ? ( + + ) : null} +
+ +

Нет, я хочу посмотреть все тарифы

+ +
+
+ ) +} @@ -0,0 +1,80 @@ +import { useEffect, useRef } from 'react' +import axios from 'axios' + +import { useAppSelector } from '#/app/store/store' +import { getModalById, LOW_BALANCE_OFFER } from '#/features/modals' +import { LowBalanceOfferPlate } from './low-balance-offer-plate' +import type { ResponseAllInfo } from '#/entities/user-account/model/user-type-slice' +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 } + const isFewTokensModalEnabled = useFeatureFlag('few-tokens-modal-enabled') + 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 + + // Пропускаем первый рендер (начальная загрузка баланса) + if (prevBalanceRef.current === null) { + prevBalanceRef.current = balance + return + } + + if (prevBalanceRef.current !== balance) { + prevBalanceRef.current = balance + + if (typeof window !== 'undefined' && sessionStorage.getItem('low-balance-offer-shown') === 'true') { + return + } + + 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 + const freePlanThreshold = tokensPerPlan * 0.3 + + if (isCorporate) { + return + } + + if (!isFreePlan && balance < threshold) { + 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, notEnoughtTokens }) + sessionStorage.setItem('low-balance-offer-shown', 'true') + return + } + } + + return +} @@ -0,0 +1,3 @@ +export { LowBalanceOfferPlate } from './ui/low-balance-offer-plate' +export { LowBalanceOfferOnStart } from './ui/low-balance-offer-on-start' +export { LowBalanceOfferTrigger } from './ui/low-balance-offer-trigger' @@ -3,5 +3,4 @@ export const RESEND_INVATION_PASSWORD = 'resend-invation-password' export const ERROR_REPORT = 'error-report' export const BUSINESS_ERROR_REPORT = 'business-error-report' export const LOW_BALANCE_OFFER = 'low-balance-offer' -export const SUBSCRIPTION_CHANGE_NOTIFICATION = 'subscription-change-notification' export const PLATE_ADD_VOICE = 'plate-add-voice' @@ -13,11 +13,12 @@ function makeModalInstance(set: Set, get: Get, key: string) { store: {}, setState(state, store) { const modals = get().modals; + const currentModal = modals[key]; - store = store ?? {}; + const newStore = store !== undefined ? store : (currentModal?.store ?? {}); set(() => ({ - modals: { ...modals, [this.id]: { ...modals[key], state, store } }, + modals: { ...modals, [this.id]: { ...modals[key], state, store: newStore } }, })); }, setStoreProperty(key, value) { @@ -73,3 +73,8 @@ .generationIcon { margin-top: 3px; } + +.settingsIcon { + flex-shrink: 0; + cursor: pointer; +} @@ -2,14 +2,11 @@ import React, { FC, useCallback, useEffect, useRef } from 'react' import { TextFieldProps } from '@mui/material/TextField/TextField' import classes from './model-input.module.scss' +import { PredictPrice } from './predict-price' import { LoadImage } from '#/app/components/input_components/load_image' import { SendBtn } from '#/app/components/input_components/send_button' import { IModelInputs } from '#/shared/api/models/models' -import { TooltipCustom } from '#/shared' -import { SvgIcon } from '#/shared/ui/svg' -import { Typography } from '@mui/material' -import { ThreePOutlined } from '@mui/icons-material' function buildTypeVersionsMap(inputs: IModelInputs[]): Record { const byType = new Map() @@ -220,16 +217,7 @@ export const ModelInput: FC = ({ >
- {typeof predictedPrice === 'string' && ( - -
- - - {Math.ceil(Number(predictedPrice))} - -
-
- )} + {hasAttachInput && ( <> {!blocked && ( @@ -0,0 +1,41 @@ +.predictPrice { + display: flex; + align-items: center; + justify-content: center; + padding: 4px 14px; + border-radius: 16px; + margin-right: 8px; + gap: 4px; + color: #7f7df3; + background-color: #7f7df31a; + + :global(svg path) { + fill: currentColor; + } + + &--low { + color: #10b981; + background-color: rgba(16, 185, 129, 0.12); + } + + &--mid { + color: #f59e0b; + background-color: rgba(245, 158, 11, 0.12); + } + + &--high { + color: #f15179; + background-color: rgba(241, 81, 121, 0.12); + } +} + +.generationIcon { + margin-top: 3px; + color: inherit; +} + +.value { + font-size: 14px; + font-weight: 600; + line-height: 1; +} @@ -0,0 +1,31 @@ +import { TooltipCustom } from '#/shared' +import { SvgIcon } from '#/shared/ui/svg' + +import classes from './predict-price.module.scss' + +const HIGH_COST_TOOLTIP = + 'Генерация может выйти очень дорогой, т.к вы ввели очень большой запрос или в чате накопились большие сообщения. Если хотите снизить стоимость генерации, создайте новый чат или уменьшите количество запросов' + +function tierModifierClass(token: number): string { + if (token < 75) return classes['predictPrice--low'] + if (token < 150) return classes['predictPrice--mid'] + return classes['predictPrice--high'] +} + +export function PredictPrice({ token }: { token: number }) { + const modifier = tierModifierClass(token) + const isHighCost = token >= 150 + + return ( + +
+ + {token} +
+
+ ) +} @@ -3,7 +3,6 @@ import { Provider } from 'react-redux' import { StyledEngineProvider, ThemeProvider } from '@mui/material' import { NextPage } from 'next' import type { AppProps } from 'next/app' -import { Raleway } from 'next/font/google' import { SessionProvider } from 'next-auth/react' import { appWithTranslation } from 'next-i18next' import { NextStep, NextStepProvider } from 'nextstepjs' @@ -11,6 +10,7 @@ import { FlagProvider, UnleashClient } from '@unleash/proxy-client-react' import { store } from '#/app/store/store' import { Error } from '#/shared' +import { LowBalanceOfferTrigger } from '#/features/low-balance-offer' import { TourManager, getTourSteps, TourCard, setTourCompleted } from '#/features/nextstep-tour' import { pingFangFont } from '#/shared/lib/constants/font/font' import { getDeviceType } from '#/shared/lib/helpers' @@ -27,8 +27,6 @@ import '#/app/styles/styles-pages/system.scss' setupAxios() -const inter = Raleway({ subsets: ['latin'] }) - export type NextPageWithLayout

= NextPage & { getLayout?: (page: ReactElement) => ReactNode dynamicProps?: DP @@ -74,7 +72,8 @@ function AppContent({ {Component.getLayout ? Component.getLayout() : } - + + @@ -118,7 +117,6 @@ function App({ Component, pageProps: { session, ...pageProps } }: AppPropsWithLa return ( <> - {unleashClient ? ( @@ -74,7 +74,7 @@ export const accountApi = { password_2: string, current_password: string ): Promise<{status:number,data:{detail:string}}>{ - + const response= await axios.put( getApiUrl() + '/auth/reset-pass', { @@ -90,7 +90,7 @@ export const accountApi = { ) return response - + }, async getApiKeys(token: string | null): Promise { @@ -146,4 +146,12 @@ export const accountApi = { return null } }, + + revokeRecurringPayment(token: string) { + return axios.post(getApiUrl() + '/payments/revoke-recurring-payment', {}, { + headers: { + Authorization: `Bearer ${token}`, + }, + }) + }, } @@ -22,7 +22,7 @@ export function setupAxios() { const session = await getSession() - if (!session || session.error) { + if (session?.error) { await signOut({ callbackUrl: '/login' }) } @@ -1,4 +1,4 @@ export const baseColor = '#7F7DF3' -export const errorColor = '#F15179;' +export const errorColor = '#F15179' export const colorLight = '#5E5E5E' export const colorDark = '#A6A5A5' @@ -34,3 +34,13 @@ export function formatDate( const formatter = Intl.DateTimeFormat("ru", options) return formatter.format(date) } + +export function getDaysLeft(iso: string | null | undefined): number | null { + if (!iso?.trim()) return null + const target = new Date(iso) + if (Number.isNaN(target.getTime())) return null + + const now = new Date() + const msDiff = target.getTime() - now.getTime() + return Math.max(0, Math.ceil(msDiff / (1000 * 60 * 60 * 24))) +} @@ -1,6 +1,5 @@ import React, { forwardRef } from 'react' import { FieldError } from 'react-hook-form' -import { Raleway } from 'next/font/google' import styles from './common-textarea.module.scss' @@ -18,8 +17,6 @@ export interface CommonTextAreaProps extends React.TextareaHTMLAttributes { return { @@ -63,10 +60,7 @@ export const CommonTextArea = forwardRef