Enhance user plan management and update related endpoints
- Added new configuration options for user plans in `.env.example`, including `Plans__MaxCustomConfigCount` and `Plans__MinCustomConfigCount`. - Introduced `MapPlanEndpoints` in `Program.cs` to handle plan-related API routes. - Implemented `SetUserPlan` endpoint in `RoleEndpoints` to allow admins to assign plans to users. - Removed deprecated role request approval endpoints from `AdminSupportEndpoints`. - Updated `ITelegramNotifier` and related classes to reflect changes in role request handling and payment notifications. - Refactored role management commands to remove `MaxConfigs` and focus on `MaxIpLimit` and billing settings. - Enhanced billing request handling to accommodate plan changes instead of role changes. - Updated various interfaces and command handlers to support new plan management features.
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
||||
|
||||
export const Route = createFileRoute('/admin/billing')({ component: AdminBillingPage })
|
||||
|
||||
const KIND_FILTERS: (PaymentRequestKind | 'All')[] = ['Subscription', 'RoleChangeTopUp', 'All']
|
||||
const KIND_FILTERS: (PaymentRequestKind | 'All')[] = ['Subscription', 'PlanChangeTopUp', 'All']
|
||||
|
||||
const STATUS_FILTERS: (PaymentRequestStatus | 'All')[] = [
|
||||
'AwaitingConfirmation',
|
||||
@@ -162,7 +162,7 @@ function RequestsSection() {
|
||||
<SelectContent>
|
||||
{KIND_FILTERS.map((k) => (
|
||||
<SelectItem key={k} value={k}>
|
||||
{k === 'All' ? t('admin.billing.allKinds') : k === 'RoleChangeTopUp' ? t('billing.roleChangeTopUp') : t('billing.subscription')}
|
||||
{k === 'All' ? t('admin.billing.allKinds') : k === 'PlanChangeTopUp' ? t('billing.planChangeTopUp') : t('billing.subscription')}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
@@ -200,7 +200,7 @@ function RequestsSection() {
|
||||
<tr key={request.id} className="border-b border-border">
|
||||
<td className="py-2">{request.userName}</td>
|
||||
<td className="py-2">
|
||||
{request.kind === 'RoleChangeTopUp' ? t('billing.roleChangeTopUp') : t(`billing.periods.${request.period}`)}
|
||||
{request.kind === 'PlanChangeTopUp' ? t('billing.planChangeTopUp') : t(`billing.periods.${request.period}`)}
|
||||
</td>
|
||||
<td className="py-2">{request.amountSnapshot} ₽</td>
|
||||
<td className="py-2">
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
import { useState } from 'react'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { toast } from '@/shared/ui/toast-store'
|
||||
import { Button } from '@/shared/ui/button'
|
||||
import { Badge } from '@/shared/ui/badge'
|
||||
import { listAdminPlans, deletePlan } from '@/features/admin/plans/api'
|
||||
import { PlanFormDialog } from '@/features/admin/plans/PlanFormDialog'
|
||||
import { getPricingSettings } from '@/features/admin/pricing/api'
|
||||
import { applyDiscount, resolveDiscountPercent } from '@/shared/lib/pricing'
|
||||
import type { AdminPlanDto } from '@/shared/api/types'
|
||||
|
||||
export const Route = createFileRoute('/admin/plans')({ component: AdminPlansPage })
|
||||
|
||||
function AdminPlansPage() {
|
||||
const { t } = useTranslation()
|
||||
const queryClient = useQueryClient()
|
||||
const [editing, setEditing] = useState<AdminPlanDto | null>(null)
|
||||
|
||||
const { data, isLoading, isError, refetch } = useQuery({ queryKey: ['admin-plans'], queryFn: listAdminPlans })
|
||||
const { data: pricing } = useQuery({ queryKey: ['admin-pricing'], queryFn: getPricingSettings })
|
||||
|
||||
const priceCell = (monthlyRate: number | null | undefined, configCount: number, months: number) => {
|
||||
if (monthlyRate == null) return <span>{t('admin.plans.noPrice')}</span>
|
||||
|
||||
const original = monthlyRate * months * configCount
|
||||
const percent = resolveDiscountPercent(pricing?.discountTiers ?? [], configCount)
|
||||
if (percent <= 0) return <span>{original} ₽</span>
|
||||
|
||||
const discounted = applyDiscount(original, percent)
|
||||
return (
|
||||
<span className="flex flex-col">
|
||||
<span className="text-xs text-muted-foreground line-through">{original} ₽</span>
|
||||
<span className="flex items-center gap-1">
|
||||
{discounted} ₽
|
||||
<Badge variant="success">-{percent}%</Badge>
|
||||
</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: deletePlan,
|
||||
onSuccess: async () => {
|
||||
toast.success(t('admin.plans.deleted'))
|
||||
await queryClient.invalidateQueries({ queryKey: ['admin-plans'] })
|
||||
},
|
||||
onError: () => toast.error(t('auth.genericError')),
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex justify-end">
|
||||
<PlanFormDialog />
|
||||
</div>
|
||||
|
||||
{isLoading && <p className="text-sm text-muted-foreground">…</p>}
|
||||
|
||||
{isError && (
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="text-sm text-muted-foreground">{t('auth.genericError')}</p>
|
||||
<Button variant="outline" size="sm" onClick={() => void refetch()}>
|
||||
{t('activation.retry')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{data?.length === 0 && <p className="text-sm text-muted-foreground">{t('admin.plans.empty')}</p>}
|
||||
|
||||
{data && data.length > 0 && (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border text-muted-foreground">
|
||||
<th className="py-2 font-medium">{t('admin.plans.name')}</th>
|
||||
<th className="py-2 font-medium">{t('admin.plans.configCount')}</th>
|
||||
<th className="py-2 font-medium">{t('admin.plans.totalPerQuarter')}</th>
|
||||
<th className="py-2 font-medium">{t('admin.plans.totalHalfYear')}</th>
|
||||
<th className="py-2 font-medium">{t('admin.plans.totalPerYear')}</th>
|
||||
<th className="py-2" />
|
||||
<th className="py-2" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.map((plan) => (
|
||||
<tr key={plan.id} className="border-b border-border">
|
||||
<td className="py-2">
|
||||
{plan.name} {!plan.isEnabled && <Badge variant="outline">{t('admin.plans.disabled')}</Badge>}
|
||||
</td>
|
||||
<td className="py-2">{plan.configCount}</td>
|
||||
<td className="py-2">{priceCell(pricing?.pricePerConfigPerQuarter, plan.configCount, 3)}</td>
|
||||
<td className="py-2">{priceCell(pricing?.pricePerConfigPerHalfYear, plan.configCount, 6)}</td>
|
||||
<td className="py-2">{priceCell(pricing?.pricePerConfigPerYear, plan.configCount, 12)}</td>
|
||||
<td className="py-2 text-right">
|
||||
<Button size="sm" variant="outline" onClick={() => setEditing(plan)}>
|
||||
{t('admin.plans.edit')}
|
||||
</Button>
|
||||
</td>
|
||||
<td className="py-2 text-right">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
disabled={deleteMutation.isPending}
|
||||
onClick={() => {
|
||||
if (confirm(t('admin.plans.confirmDelete'))) deleteMutation.mutate(plan.id)
|
||||
}}
|
||||
>
|
||||
{t('admin.plans.delete')}
|
||||
</Button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{editing && <PlanFormDialog plan={editing} open={!!editing} onOpenChange={(open) => !open && setEditing(null)} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -7,8 +7,6 @@ import { Button } from '@/shared/ui/button'
|
||||
import { Badge } from '@/shared/ui/badge'
|
||||
import { listRoles, deleteRole } from '@/features/admin/roles/api'
|
||||
import { RoleFormDialog } from '@/features/admin/roles/RoleFormDialog'
|
||||
import { getPricingSettings } from '@/features/admin/pricing/api'
|
||||
import { applyDiscount, resolveDiscountPercent } from '@/shared/lib/pricing'
|
||||
import type { RoleDto } from '@/shared/api/types'
|
||||
|
||||
export const Route = createFileRoute('/admin/roles')({ component: AdminRolesPage })
|
||||
@@ -19,28 +17,6 @@ function AdminRolesPage() {
|
||||
const [editing, setEditing] = useState<RoleDto | null>(null)
|
||||
|
||||
const { data, isLoading, isError, refetch } = useQuery({ queryKey: ['admin-roles'], queryFn: listRoles })
|
||||
const { data: pricing } = useQuery({ queryKey: ['admin-pricing'], queryFn: getPricingSettings })
|
||||
|
||||
// Ставки — цена за конфиг В МЕСЯЦ при данном тарифе; итог за период = ставка × месяцев × квота,
|
||||
// затем скидка по лесенке (см. shared/lib/pricing) — за роль с большей квотой конфигов.
|
||||
const priceCell = (monthlyRate: number | null | undefined, maxConfigs: number, months: number) => {
|
||||
if (monthlyRate == null || maxConfigs < 0) return <span>{t('admin.roles.noPrice')}</span>
|
||||
|
||||
const original = monthlyRate * months * maxConfigs
|
||||
const percent = resolveDiscountPercent(pricing?.discountTiers ?? [], maxConfigs)
|
||||
if (percent <= 0) return <span>{original} ₽</span>
|
||||
|
||||
const discounted = applyDiscount(original, percent)
|
||||
return (
|
||||
<span className="flex flex-col">
|
||||
<span className="text-xs text-muted-foreground line-through">{original} ₽</span>
|
||||
<span className="flex items-center gap-1">
|
||||
{discounted} ₽
|
||||
<Badge variant="success">-{percent}%</Badge>
|
||||
</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: deleteRole,
|
||||
@@ -74,11 +50,7 @@ function AdminRolesPage() {
|
||||
<thead>
|
||||
<tr className="border-b border-border text-muted-foreground">
|
||||
<th className="py-2 font-medium">{t('admin.roles.name')}</th>
|
||||
<th className="py-2 font-medium">{t('admin.roles.maxConfigs')}</th>
|
||||
<th className="py-2 font-medium">{t('admin.roles.maxIpLimit')}</th>
|
||||
<th className="py-2 font-medium">{t('admin.roles.totalPerQuarter')}</th>
|
||||
<th className="py-2 font-medium">{t('admin.roles.totalHalfYear')}</th>
|
||||
<th className="py-2 font-medium">{t('admin.roles.totalPerYear')}</th>
|
||||
<th className="py-2" />
|
||||
<th className="py-2" />
|
||||
</tr>
|
||||
@@ -90,11 +62,7 @@ function AdminRolesPage() {
|
||||
{role.name} {role.isSystem && <Badge variant="outline">{t('admin.roles.system')}</Badge>}{' '}
|
||||
{role.billingEnabled && <Badge variant="success">{t('admin.roles.billingBadge')}</Badge>}
|
||||
</td>
|
||||
<td className="py-2">{role.maxConfigs < 0 ? t('unlimited') : role.maxConfigs}</td>
|
||||
<td className="py-2">{role.maxIpLimit < 0 ? t('unlimited') : role.maxIpLimit}</td>
|
||||
<td className="py-2">{priceCell(pricing?.pricePerConfigPerQuarter, role.maxConfigs, 3)}</td>
|
||||
<td className="py-2">{priceCell(pricing?.pricePerConfigPerHalfYear, role.maxConfigs, 6)}</td>
|
||||
<td className="py-2">{priceCell(pricing?.pricePerConfigPerYear, role.maxConfigs, 12)}</td>
|
||||
<td className="py-2 text-right">
|
||||
<Button size="sm" variant="outline" onClick={() => setEditing(role)}>
|
||||
{t('admin.roles.edit')}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { AdminTicketDetailDialog } from '@/features/admin/support/AdminTicketDet
|
||||
import { listAllTickets } from '@/features/admin/support/api'
|
||||
import type { TicketStatus, TicketType } from '@/shared/api/types'
|
||||
|
||||
const TYPES: TicketType[] = ['BugReport', 'RoleRequest', 'ExtensionRequest']
|
||||
const TYPES: TicketType[] = ['BugReport', 'ExtensionRequest']
|
||||
const STATUSES: TicketStatus[] = ['Open', 'Resolved', 'Closed']
|
||||
|
||||
export const Route = createFileRoute('/admin/support')({
|
||||
|
||||
Reference in New Issue
Block a user