mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 17:43:47 +00:00
feat: add gift subscription API client and feature flag
This commit is contained in:
@@ -23,6 +23,10 @@ export interface EmailAuthEnabled {
|
|||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GiftEnabled {
|
||||||
|
enabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface TelegramWidgetConfig {
|
export interface TelegramWidgetConfig {
|
||||||
bot_username: string;
|
bot_username: string;
|
||||||
size: 'large' | 'medium' | 'small';
|
size: 'large' | 'medium' | 'small';
|
||||||
@@ -251,6 +255,16 @@ export const brandingApi = {
|
|||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Get gift enabled (public, no auth required)
|
||||||
|
getGiftEnabled: async (): Promise<GiftEnabled> => {
|
||||||
|
try {
|
||||||
|
const response = await apiClient.get<GiftEnabled>('/cabinet/branding/gift-enabled');
|
||||||
|
return response.data;
|
||||||
|
} catch {
|
||||||
|
return { enabled: false };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Get analytics counters (public, no auth required)
|
// Get analytics counters (public, no auth required)
|
||||||
getAnalyticsCounters: async (): Promise<AnalyticsCounters> => {
|
getAnalyticsCounters: async (): Promise<AnalyticsCounters> => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
87
src/api/gift.ts
Normal file
87
src/api/gift.ts
Normal file
@@ -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<GiftConfig> => {
|
||||||
|
const { data } = await apiClient.get<GiftConfig>('/cabinet/gift/config');
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
createPurchase: async (request: GiftPurchaseRequest): Promise<GiftPurchaseResponse> => {
|
||||||
|
const { data } = await apiClient.post<GiftPurchaseResponse>('/cabinet/gift/purchase', request);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
getPurchaseStatus: async (token: string): Promise<GiftPurchaseStatus> => {
|
||||||
|
const { data } = await apiClient.get<GiftPurchaseStatus>(`/cabinet/gift/purchase/${token}`);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useAuthStore } from '@/store/auth';
|
import { useAuthStore } from '@/store/auth';
|
||||||
|
import { brandingApi } from '@/api/branding';
|
||||||
import { referralApi } from '@/api/referral';
|
import { referralApi } from '@/api/referral';
|
||||||
import { wheelApi } from '@/api/wheel';
|
import { wheelApi } from '@/api/wheel';
|
||||||
import { contestsApi } from '@/api/contests';
|
import { contestsApi } from '@/api/contests';
|
||||||
@@ -40,10 +41,19 @@ export function useFeatureFlags() {
|
|||||||
retry: false,
|
retry: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { data: giftConfig } = useQuery({
|
||||||
|
queryKey: ['gift-enabled'],
|
||||||
|
queryFn: brandingApi.getGiftEnabled,
|
||||||
|
enabled: isAuthenticated,
|
||||||
|
staleTime: 60000,
|
||||||
|
retry: false,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
referralEnabled: referralTerms?.is_enabled,
|
referralEnabled: referralTerms?.is_enabled,
|
||||||
wheelEnabled: wheelConfig?.is_enabled,
|
wheelEnabled: wheelConfig?.is_enabled,
|
||||||
hasContests: (contestsCount?.count ?? 0) > 0,
|
hasContests: (contestsCount?.count ?? 0) > 0,
|
||||||
hasPolls: (pollsCount?.count ?? 0) > 0,
|
hasPolls: (pollsCount?.count ?? 0) > 0,
|
||||||
|
giftEnabled: giftConfig?.enabled,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user