diff --git a/src/api/branding.ts b/src/api/branding.ts index 235d511..5136814 100644 --- a/src/api/branding.ts +++ b/src/api/branding.ts @@ -23,6 +23,10 @@ export interface EmailAuthEnabled { enabled: boolean; } +export interface GiftEnabled { + enabled: boolean; +} + export interface TelegramWidgetConfig { bot_username: string; size: 'large' | 'medium' | 'small'; @@ -251,6 +255,16 @@ export const brandingApi = { return response.data; }, + // Get gift enabled (public, no auth required) + getGiftEnabled: async (): Promise => { + try { + const response = await apiClient.get('/cabinet/branding/gift-enabled'); + return response.data; + } catch { + return { enabled: false }; + } + }, + // Get analytics counters (public, no auth required) getAnalyticsCounters: async (): Promise => { try { diff --git a/src/api/gift.ts b/src/api/gift.ts new file mode 100644 index 0000000..35b3046 --- /dev/null +++ b/src/api/gift.ts @@ -0,0 +1,87 @@ +import apiClient from './client'; + +// Types + +export interface GiftTariffPeriod { + days: number; + price_kopeks: number; + price_label: string; + original_price_kopeks: number | null; + discount_percent: number | null; +} + +export interface GiftTariff { + id: number; + name: string; + description: string | null; + traffic_limit_gb: number; + device_limit: number; + periods: GiftTariffPeriod[]; +} + +export interface GiftPaymentMethodSubOption { + id: string; + name: string; +} + +export interface GiftPaymentMethod { + method_id: string; + display_name: string; + description: string | null; + icon_url: string | null; + min_amount_kopeks: number | null; + max_amount_kopeks: number | null; + sub_options: GiftPaymentMethodSubOption[] | null; +} + +export interface GiftConfig { + is_enabled: boolean; + tariffs: GiftTariff[]; + payment_methods: GiftPaymentMethod[]; + balance_kopeks: number; + currency_symbol: string; +} + +export interface GiftPurchaseRequest { + tariff_id: number; + period_days: number; + recipient_type: 'email' | 'telegram'; + recipient_value: string; + gift_message?: string; + payment_mode: 'balance' | 'gateway'; + payment_method?: string; +} + +export interface GiftPurchaseResponse { + status: string; + purchase_token: string; + payment_url: string | null; +} + +export interface GiftPurchaseStatus { + status: string; + is_gift: boolean; + recipient_contact_value: string | null; + gift_message: string | null; + tariff_name: string | null; + period_days: number | null; +} + +// API + +export const giftApi = { + getConfig: async (): Promise => { + const { data } = await apiClient.get('/cabinet/gift/config'); + return data; + }, + + createPurchase: async (request: GiftPurchaseRequest): Promise => { + const { data } = await apiClient.post('/cabinet/gift/purchase', request); + return data; + }, + + getPurchaseStatus: async (token: string): Promise => { + const { data } = await apiClient.get(`/cabinet/gift/purchase/${token}`); + return data; + }, +}; diff --git a/src/hooks/useFeatureFlags.ts b/src/hooks/useFeatureFlags.ts index 356d357..8da43e4 100644 --- a/src/hooks/useFeatureFlags.ts +++ b/src/hooks/useFeatureFlags.ts @@ -1,5 +1,6 @@ import { useQuery } from '@tanstack/react-query'; import { useAuthStore } from '@/store/auth'; +import { brandingApi } from '@/api/branding'; import { referralApi } from '@/api/referral'; import { wheelApi } from '@/api/wheel'; import { contestsApi } from '@/api/contests'; @@ -40,10 +41,19 @@ export function useFeatureFlags() { retry: false, }); + const { data: giftConfig } = useQuery({ + queryKey: ['gift-enabled'], + queryFn: brandingApi.getGiftEnabled, + enabled: isAuthenticated, + staleTime: 60000, + retry: false, + }); + return { referralEnabled: referralTerms?.is_enabled, wheelEnabled: wheelConfig?.is_enabled, hasContests: (contestsCount?.count ?? 0) > 0, hasPolls: (pollsCount?.count ?? 0) > 0, + giftEnabled: giftConfig?.enabled, }; }