Refactor client update handling to support nullable parameters for name and expiration
CI / Backend (build + test) (push) Successful in 1m18s
CI / Frontend (lint + typecheck + build) (push) Successful in 59s

- Updated the `UpdateClientAsync` method in `IXuiPanelGateway` to accept nullable parameters for `name` and `expiresAt`, allowing for more flexible client management without unintended modifications.
- Adjusted the `BlockUserCommandHandler`, `UnblockUserCommandHandler`, and other related command handlers to utilize the new nullable parameters, ensuring that client names remain unchanged during block/unblock operations and that expiration dates are managed correctly.
- Enhanced the billing and configuration handling to reflect the new logic for managing client states based on expiration rather than enabling/disabling, improving reliability in client status management.
- Updated tests to cover the new behavior and ensure proper functionality across the application.
This commit is contained in:
Leonid Pershin
2026-07-19 18:58:36 +03:00
parent 5ff5224935
commit 979eddf72e
20 changed files with 282 additions and 29 deletions
@@ -1,5 +1,6 @@
import { useState } from 'react'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { useNavigate } from '@tanstack/react-router'
import { useTranslation } from 'react-i18next'
import { Plus } from 'lucide-react'
import { toast } from '@/shared/ui/toast-store'
@@ -15,6 +16,7 @@ import { createConfig } from './api'
export function CreateConfigDialog({ inbounds }: { inbounds: AvailableInboundDto[] }) {
const { t } = useTranslation()
const queryClient = useQueryClient()
const navigate = useNavigate()
const [open, setOpen] = useState(false)
const [inboundId, setInboundId] = useState('')
const [label, setLabel] = useState('')
@@ -29,6 +31,15 @@ export function CreateConfigDialog({ inbounds }: { inbounds: AvailableInboundDto
setLabel('')
},
onError: (error) => {
// Safety-net: дашборд уже скрывает эту кнопку при истёкшей оплате (см. dashboard.tsx), но
// между открытием страницы и отправкой формы биллинг мог протухнуть — сервер всё равно
// проверяет (ConfigErrors.BillingRequired) и на всякий случай отправляем на оплату.
if (error instanceof HttpError && error.title === 'Configs.BillingRequired') {
toast.error(t('configs.billingRequiredNotice'))
setOpen(false)
void navigate({ to: '/billing' })
return
}
const message =
error instanceof HttpError && error.status === 409 ? t('configs.quotaExceeded') : t('auth.genericError')
toast.error(message)
+14 -1
View File
@@ -30,6 +30,12 @@ function ConfigsList() {
const inboundsQuery = useQuery({ queryKey: ['available-inbounds'], queryFn: listAvailableInbounds })
const billingStatusQuery = useQuery({ queryKey: ['my-billing-status'], queryFn: getMyBillingStatus })
// Зеркалит серверную проверку в CreateVpnConfigCommandHandler (ConfigErrors.BillingRequired) —
// роль с биллингом и просроченной/неоплаченной подпиской не может создавать новые конфиги.
const billing = billingStatusQuery.data
const billingBlocksCreate =
!!billing?.billingEnabled && (billing.paidUntil == null || new Date(billing.paidUntil) < new Date())
return (
<div className="mx-auto flex w-full max-w-4xl flex-col gap-6 px-6 py-10">
<div className="flex items-center justify-between gap-4">
@@ -52,7 +58,14 @@ function ConfigsList() {
</Link>
)}
</div>
{inboundsQuery.data?.length === 0 ? (
{billingBlocksCreate ? (
<div className="flex max-w-xs flex-col items-end gap-1 text-right text-sm">
<p className="text-muted-foreground">{t('configs.billingRequiredNotice')}</p>
<Link to="/billing" className="font-medium text-foreground underline underline-offset-2">
{t('configs.goToBilling')}
</Link>
</div>
) : inboundsQuery.data?.length === 0 ? (
<p className="max-w-xs text-right text-sm text-muted-foreground">{t('configs.noInboundsNotice')}</p>
) : (
inboundsQuery.data && <CreateConfigDialog inbounds={inboundsQuery.data} />
+4
View File
@@ -78,6 +78,8 @@ const resources = {
location: 'Локация',
label: 'Метка (необязательно)',
noInboundsNotice: 'Пока нет доступных локаций для создания конфига. Обратитесь к администратору — необходимо, чтобы он добавил сервер.',
billingRequiredNotice: 'Оплата подписки истекла — создание новых конфигов недоступно, пока не продлите доступ.',
goToBilling: 'Перейти к оплате',
created: 'Конфиг создан.',
quotaExceeded: 'Достигнут лимит конфигов для вашей роли.',
showLink: 'Ссылка / QR',
@@ -618,6 +620,8 @@ const resources = {
location: 'Location',
label: 'Label (optional)',
noInboundsNotice: 'No locations are available for creating a config yet. Please contact the administrator — a server needs to be added.',
billingRequiredNotice: 'Your subscription has expired — creating new configs is unavailable until you renew.',
goToBilling: 'Go to payment',
created: 'Config created.',
quotaExceeded: 'Config quota reached for your role.',
showLink: 'Link / QR',