mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-30 10:27:49 +00:00
feat: add external squad selection to tariff admin form
- Add ExternalSquadInfo type and getAvailableExternalSquads API method - Add external_squad_uuid field to TariffDetail, TariffCreateRequest, TariffUpdateRequest - Add radio-button external squad picker in Servers tab of tariff create/edit - Add translations for external squad UI in all 4 locales (en, ru, zh, fa)
This commit is contained in:
@@ -85,6 +85,8 @@ export interface TariffDetail {
|
|||||||
daily_price_kopeks: number;
|
daily_price_kopeks: number;
|
||||||
// Режим сброса трафика
|
// Режим сброса трафика
|
||||||
traffic_reset_mode: string | null; // 'DAY', 'WEEK', 'MONTH', 'NO_RESET', null = глобальная настройка
|
traffic_reset_mode: string | null; // 'DAY', 'WEEK', 'MONTH', 'NO_RESET', null = глобальная настройка
|
||||||
|
// Внешний сквад RemnaWave
|
||||||
|
external_squad_uuid: string | null;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string | null;
|
updated_at: string | null;
|
||||||
}
|
}
|
||||||
@@ -121,6 +123,14 @@ export interface TariffCreateRequest {
|
|||||||
daily_price_kopeks?: number;
|
daily_price_kopeks?: number;
|
||||||
// Режим сброса трафика
|
// Режим сброса трафика
|
||||||
traffic_reset_mode?: string | null;
|
traffic_reset_mode?: string | null;
|
||||||
|
// Внешний сквад RemnaWave
|
||||||
|
external_squad_uuid?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ExternalSquadInfo {
|
||||||
|
uuid: string;
|
||||||
|
name: string;
|
||||||
|
members_count: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TariffUpdateRequest {
|
export interface TariffUpdateRequest {
|
||||||
@@ -156,6 +166,8 @@ export interface TariffUpdateRequest {
|
|||||||
daily_price_kopeks?: number;
|
daily_price_kopeks?: number;
|
||||||
// Режим сброса трафика
|
// Режим сброса трафика
|
||||||
traffic_reset_mode?: string | null;
|
traffic_reset_mode?: string | null;
|
||||||
|
// Внешний сквад RemnaWave
|
||||||
|
external_squad_uuid?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TariffToggleResponse {
|
export interface TariffToggleResponse {
|
||||||
@@ -249,4 +261,10 @@ export const tariffsApi = {
|
|||||||
const response = await apiClient.get('/cabinet/admin/payment-methods/promo-groups');
|
const response = await apiClient.get('/cabinet/admin/payment-methods/promo-groups');
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Get available external squads from RemnaWave
|
||||||
|
getAvailableExternalSquads: async (): Promise<ExternalSquadInfo[]> => {
|
||||||
|
const response = await apiClient.get('/cabinet/admin/tariffs/available-external-squads');
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1923,6 +1923,10 @@
|
|||||||
"noPeriodsHint": "No added periods. Add at least one period.",
|
"noPeriodsHint": "No added periods. Add at least one period.",
|
||||||
"daysShort": "d.",
|
"daysShort": "d.",
|
||||||
"serversTitle": "Servers",
|
"serversTitle": "Servers",
|
||||||
|
"externalSquadTitle": "External Squad",
|
||||||
|
"externalSquadHint": "Assign a RemnaWave external squad for users on this tariff. When a subscription is created, the user will be automatically added to the selected squad.",
|
||||||
|
"noExternalSquad": "No external squad",
|
||||||
|
"externalSquadUsers": "users",
|
||||||
"serversTabHint": "Select servers available on this tariff.",
|
"serversTabHint": "Select servers available on this tariff.",
|
||||||
"noServersAvailable": "No servers available",
|
"noServersAvailable": "No servers available",
|
||||||
"promoGroupsTitle": "Promo Groups",
|
"promoGroupsTitle": "Promo Groups",
|
||||||
|
|||||||
@@ -1567,6 +1567,10 @@
|
|||||||
"noPeriodsHint": "هیچ دورهای اضافه نشده. حداقل یک دوره اضافه کنید.",
|
"noPeriodsHint": "هیچ دورهای اضافه نشده. حداقل یک دوره اضافه کنید.",
|
||||||
"daysShort": "روز",
|
"daysShort": "روز",
|
||||||
"serversTitle": "سرورها",
|
"serversTitle": "سرورها",
|
||||||
|
"externalSquadTitle": "گروه خارجی",
|
||||||
|
"externalSquadHint": "یک گروه خارجی RemnaWave برای کاربران این تعرفه تعیین کنید. هنگام ایجاد اشتراک، کاربر به طور خودکار به گروه انتخاب شده اضافه میشود.",
|
||||||
|
"noExternalSquad": "بدون گروه خارجی",
|
||||||
|
"externalSquadUsers": "کاربران",
|
||||||
"serversTabHint": "سرورهای موجود در این تعرفه را انتخاب کنید.",
|
"serversTabHint": "سرورهای موجود در این تعرفه را انتخاب کنید.",
|
||||||
"noServersAvailable": "هیچ سروری در دسترس نیست",
|
"noServersAvailable": "هیچ سروری در دسترس نیست",
|
||||||
"promoGroupsTitle": "گروههای تبلیغاتی",
|
"promoGroupsTitle": "گروههای تبلیغاتی",
|
||||||
|
|||||||
@@ -2437,6 +2437,10 @@
|
|||||||
"noPeriodsHint": "Нет добавленных периодов. Добавьте хотя бы один период.",
|
"noPeriodsHint": "Нет добавленных периодов. Добавьте хотя бы один период.",
|
||||||
"daysShort": "дн.",
|
"daysShort": "дн.",
|
||||||
"serversTitle": "Серверы",
|
"serversTitle": "Серверы",
|
||||||
|
"externalSquadTitle": "Внешний сквад",
|
||||||
|
"externalSquadHint": "Назначьте внешний сквад RemnaWave для пользователей этого тарифа. При создании подписки пользователь будет автоматически добавлен в выбранный сквад.",
|
||||||
|
"noExternalSquad": "Без внешнего сквада",
|
||||||
|
"externalSquadUsers": "пользователей",
|
||||||
"serversTabHint": "Выберите серверы, доступные на этом тарифе.",
|
"serversTabHint": "Выберите серверы, доступные на этом тарифе.",
|
||||||
"noServersAvailable": "Нет доступных серверов",
|
"noServersAvailable": "Нет доступных серверов",
|
||||||
"promoGroupsTitle": "Промо-группы",
|
"promoGroupsTitle": "Промо-группы",
|
||||||
|
|||||||
@@ -1604,6 +1604,10 @@
|
|||||||
"noPeriodsHint": "没有添加的周期。请至少添加一个周期。",
|
"noPeriodsHint": "没有添加的周期。请至少添加一个周期。",
|
||||||
"daysShort": "天",
|
"daysShort": "天",
|
||||||
"serversTitle": "服务器",
|
"serversTitle": "服务器",
|
||||||
|
"externalSquadTitle": "外部小组",
|
||||||
|
"externalSquadHint": "为此套餐的用户分配RemnaWave外部小组。创建订阅时,用户将自动添加到所选小组。",
|
||||||
|
"noExternalSquad": "无外部小组",
|
||||||
|
"externalSquadUsers": "用户",
|
||||||
"serversTabHint": "选择此套餐上可用的服务器。",
|
"serversTabHint": "选择此套餐上可用的服务器。",
|
||||||
"noServersAvailable": "没有可用的服务器",
|
"noServersAvailable": "没有可用的服务器",
|
||||||
"promoGroupsTitle": "促销组",
|
"promoGroupsTitle": "促销组",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
TariffUpdateRequest,
|
TariffUpdateRequest,
|
||||||
PeriodPrice,
|
PeriodPrice,
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
|
ExternalSquadInfo,
|
||||||
} from '../api/tariffs';
|
} from '../api/tariffs';
|
||||||
import { AdminBackButton } from '../components/admin';
|
import { AdminBackButton } from '../components/admin';
|
||||||
import { createNumberInputHandler, toNumber } from '../utils/inputHelpers';
|
import { createNumberInputHandler, toNumber } from '../utils/inputHelpers';
|
||||||
@@ -105,6 +106,7 @@ export default function AdminTariffCreate() {
|
|||||||
const [tierLevel, setTierLevel] = useState<number | ''>(1);
|
const [tierLevel, setTierLevel] = useState<number | ''>(1);
|
||||||
const [periodPrices, setPeriodPrices] = useState<PeriodPrice[]>([]);
|
const [periodPrices, setPeriodPrices] = useState<PeriodPrice[]>([]);
|
||||||
const [selectedSquads, setSelectedSquads] = useState<string[]>([]);
|
const [selectedSquads, setSelectedSquads] = useState<string[]>([]);
|
||||||
|
const [selectedExternalSquad, setSelectedExternalSquad] = useState<string | null>(null);
|
||||||
const [selectedPromoGroups, setSelectedPromoGroups] = useState<number[]>([]);
|
const [selectedPromoGroups, setSelectedPromoGroups] = useState<number[]>([]);
|
||||||
const [dailyPriceKopeks, setDailyPriceKopeks] = useState<number | ''>(0);
|
const [dailyPriceKopeks, setDailyPriceKopeks] = useState<number | ''>(0);
|
||||||
|
|
||||||
@@ -138,6 +140,12 @@ export default function AdminTariffCreate() {
|
|||||||
queryFn: () => tariffsApi.getAvailableServers(),
|
queryFn: () => tariffsApi.getAvailableServers(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Fetch external squads
|
||||||
|
const { data: externalSquads = [] } = useQuery({
|
||||||
|
queryKey: ['admin-tariffs-external-squads'],
|
||||||
|
queryFn: () => tariffsApi.getAvailableExternalSquads(),
|
||||||
|
});
|
||||||
|
|
||||||
// Fetch promo groups
|
// Fetch promo groups
|
||||||
const { data: promoGroups = [] } = useQuery({
|
const { data: promoGroups = [] } = useQuery({
|
||||||
queryKey: ['admin-tariffs-promo-groups'],
|
queryKey: ['admin-tariffs-promo-groups'],
|
||||||
@@ -165,6 +173,7 @@ export default function AdminTariffCreate() {
|
|||||||
setTierLevel(data.tier_level || 1);
|
setTierLevel(data.tier_level || 1);
|
||||||
setPeriodPrices(data.period_prices?.length ? data.period_prices : []);
|
setPeriodPrices(data.period_prices?.length ? data.period_prices : []);
|
||||||
setSelectedSquads(data.allowed_squads || []);
|
setSelectedSquads(data.allowed_squads || []);
|
||||||
|
setSelectedExternalSquad(data.external_squad_uuid || null);
|
||||||
setSelectedPromoGroups(
|
setSelectedPromoGroups(
|
||||||
data.promo_groups?.filter((pg) => pg.is_selected).map((pg) => pg.id) || [],
|
data.promo_groups?.filter((pg) => pg.is_selected).map((pg) => pg.id) || [],
|
||||||
);
|
);
|
||||||
@@ -211,6 +220,7 @@ export default function AdminTariffCreate() {
|
|||||||
tier_level: toNumber(tierLevel, 1),
|
tier_level: toNumber(tierLevel, 1),
|
||||||
period_prices: isDaily ? [] : periodPrices.filter((p) => p.price_kopeks >= 0),
|
period_prices: isDaily ? [] : periodPrices.filter((p) => p.price_kopeks >= 0),
|
||||||
allowed_squads: selectedSquads,
|
allowed_squads: selectedSquads,
|
||||||
|
external_squad_uuid: selectedExternalSquad || null,
|
||||||
promo_group_ids: selectedPromoGroups.length > 0 ? selectedPromoGroups : undefined,
|
promo_group_ids: selectedPromoGroups.length > 0 ? selectedPromoGroups : undefined,
|
||||||
traffic_topup_enabled: trafficTopupEnabled,
|
traffic_topup_enabled: trafficTopupEnabled,
|
||||||
traffic_topup_packages: trafficTopupPackages,
|
traffic_topup_packages: trafficTopupPackages,
|
||||||
@@ -660,6 +670,77 @@ export default function AdminTariffCreate() {
|
|||||||
|
|
||||||
{activeTab === 'servers' && (
|
{activeTab === 'servers' && (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
|
{/* External Squad */}
|
||||||
|
{externalSquads.length > 0 && (
|
||||||
|
<div className="card space-y-4">
|
||||||
|
<h4 className="text-sm font-medium text-dark-200">
|
||||||
|
{t('admin.tariffs.externalSquadTitle')}
|
||||||
|
</h4>
|
||||||
|
<p className="text-sm text-dark-400">{t('admin.tariffs.externalSquadHint')}</p>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setSelectedExternalSquad(null)}
|
||||||
|
className={`flex w-full items-center gap-3 rounded-lg p-3 text-left transition-colors ${
|
||||||
|
!selectedExternalSquad
|
||||||
|
? isDaily
|
||||||
|
? 'bg-warning-500/20 text-warning-300'
|
||||||
|
: 'bg-accent-500/20 text-accent-300'
|
||||||
|
: 'bg-dark-800 text-dark-300 hover:bg-dark-700'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={`flex h-5 w-5 items-center justify-center rounded-full ${
|
||||||
|
!selectedExternalSquad
|
||||||
|
? isDaily
|
||||||
|
? 'bg-warning-500 text-white'
|
||||||
|
: 'bg-accent-500 text-white'
|
||||||
|
: 'bg-dark-600'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{!selectedExternalSquad && <CheckIcon />}
|
||||||
|
</div>
|
||||||
|
<span className="flex-1 text-sm font-medium">
|
||||||
|
{t('admin.tariffs.noExternalSquad')}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
{externalSquads.map((squad: ExternalSquadInfo) => {
|
||||||
|
const isSelected = selectedExternalSquad === squad.uuid;
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={squad.uuid}
|
||||||
|
type="button"
|
||||||
|
onClick={() => setSelectedExternalSquad(squad.uuid)}
|
||||||
|
className={`flex w-full items-center gap-3 rounded-lg p-3 text-left transition-colors ${
|
||||||
|
isSelected
|
||||||
|
? isDaily
|
||||||
|
? 'bg-warning-500/20 text-warning-300'
|
||||||
|
: 'bg-accent-500/20 text-accent-300'
|
||||||
|
: 'bg-dark-800 text-dark-300 hover:bg-dark-700'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={`flex h-5 w-5 items-center justify-center rounded-full ${
|
||||||
|
isSelected
|
||||||
|
? isDaily
|
||||||
|
? 'bg-warning-500 text-white'
|
||||||
|
: 'bg-accent-500 text-white'
|
||||||
|
: 'bg-dark-600'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isSelected && <CheckIcon />}
|
||||||
|
</div>
|
||||||
|
<span className="flex-1 text-sm font-medium">{squad.name}</span>
|
||||||
|
<span className="text-xs text-dark-500">
|
||||||
|
{squad.members_count} {t('admin.tariffs.externalSquadUsers')}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Servers */}
|
{/* Servers */}
|
||||||
<div className="card space-y-4">
|
<div className="card space-y-4">
|
||||||
<h4 className="text-sm font-medium text-dark-200">{t('admin.tariffs.serversTitle')}</h4>
|
<h4 className="text-sm font-medium text-dark-200">{t('admin.tariffs.serversTitle')}</h4>
|
||||||
|
|||||||
Reference in New Issue
Block a user