Enhance user management and billing integration
- Updated the `UserSummaryDto` to include `BillingEnabled` and `BillingPaidUntil` properties, allowing for better tracking of user billing status. - Refactored the `IdentityService` to populate the new billing fields when retrieving user summaries. - Modified the dashboard and admin user management components to display billing information, including a link to the billing page and a badge for billing status. - Added internationalization support for new billing-related labels in both English and Russian. - Ensured frontend components reflect the updated user data structure, enhancing user experience with billing visibility.
This commit is contained in:
@@ -34,7 +34,9 @@ public sealed record UserSummaryDto(
|
|||||||
string Role,
|
string Role,
|
||||||
bool IsActivated,
|
bool IsActivated,
|
||||||
bool IsBlocked,
|
bool IsBlocked,
|
||||||
DateTimeOffset? ActivatedAt
|
DateTimeOffset? ActivatedAt,
|
||||||
|
bool BillingEnabled,
|
||||||
|
DateTimeOffset? BillingPaidUntil
|
||||||
);
|
);
|
||||||
|
|
||||||
public sealed record UserStatsDto(int Total, int Activated);
|
public sealed record UserStatsDto(int Total, int Activated);
|
||||||
|
|||||||
@@ -269,15 +269,17 @@ internal sealed class IdentityService(
|
|||||||
var items = new List<UserSummaryDto>(users.Count);
|
var items = new List<UserSummaryDto>(users.Count);
|
||||||
foreach (var user in users)
|
foreach (var user in users)
|
||||||
{
|
{
|
||||||
var roleName = await GetPrimaryRoleNameAsync(user);
|
var role = await GetPrimaryRoleAsync(user);
|
||||||
items.Add(
|
items.Add(
|
||||||
new UserSummaryDto(
|
new UserSummaryDto(
|
||||||
user.Id,
|
user.Id,
|
||||||
user.UserName!,
|
user.UserName!,
|
||||||
roleName,
|
role.Name!,
|
||||||
user.IsActivated,
|
user.IsActivated,
|
||||||
user.IsBlocked,
|
user.IsBlocked,
|
||||||
user.ActivatedAt
|
user.ActivatedAt,
|
||||||
|
role.BillingEnabled,
|
||||||
|
user.BillingPaidUntil
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Badge } from '@/shared/ui/badge'
|
||||||
|
|
||||||
|
const RED_THRESHOLD_DAYS = 3
|
||||||
|
const YELLOW_THRESHOLD_DAYS = 7
|
||||||
|
|
||||||
|
/** Дней до paidUntil, округление вверх — «меньше суток» всё равно считается как 1 день, а не 0. */
|
||||||
|
function daysRemaining(paidUntil: string): number {
|
||||||
|
const diffMs = new Date(paidUntil).getTime() - Date.now()
|
||||||
|
return Math.ceil(diffMs / (24 * 60 * 60 * 1000))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Цветовая индикация оплаченного периода: зелёный — обычный запас, жёлтый — ≤7 дней, красный —
|
||||||
|
* ≤3 дней или уже истекло. Общий компонент для дашборда пользователя и списка пользователей в админке. */
|
||||||
|
export function PaidUntilBadge({ paidUntil }: { paidUntil: string | null }) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
if (!paidUntil) return <Badge variant="destructive">{t('billing.neverPaidShort')}</Badge>
|
||||||
|
|
||||||
|
const days = daysRemaining(paidUntil)
|
||||||
|
const variant = days <= RED_THRESHOLD_DAYS ? 'destructive' : days <= YELLOW_THRESHOLD_DAYS ? 'warning' : 'success'
|
||||||
|
const label =
|
||||||
|
days <= 0
|
||||||
|
? t('billing.expiredShort')
|
||||||
|
: t('billing.daysRemaining', { count: days })
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Badge variant={variant} title={new Date(paidUntil).toLocaleDateString()}>
|
||||||
|
{label}
|
||||||
|
</Badge>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next'
|
|||||||
import { Input } from '@/shared/ui/input'
|
import { Input } from '@/shared/ui/input'
|
||||||
import { Button } from '@/shared/ui/button'
|
import { Button } from '@/shared/ui/button'
|
||||||
import { Badge } from '@/shared/ui/badge'
|
import { Badge } from '@/shared/ui/badge'
|
||||||
|
import { PaidUntilBadge } from '@/features/billing/PaidUntilBadge'
|
||||||
import { listUsers } from '@/features/admin/users/api'
|
import { listUsers } from '@/features/admin/users/api'
|
||||||
import { UserManageDialog } from '@/features/admin/users/UserManageDialog'
|
import { UserManageDialog } from '@/features/admin/users/UserManageDialog'
|
||||||
import type { UserSummaryDto } from '@/shared/api/types'
|
import type { UserSummaryDto } from '@/shared/api/types'
|
||||||
@@ -56,6 +57,7 @@ function AdminUsersPage() {
|
|||||||
<th className="py-2 font-medium">{t('admin.users.userName')}</th>
|
<th className="py-2 font-medium">{t('admin.users.userName')}</th>
|
||||||
<th className="py-2 font-medium">{t('admin.users.role')}</th>
|
<th className="py-2 font-medium">{t('admin.users.role')}</th>
|
||||||
<th className="py-2 font-medium">{t('admin.users.statusLabel')}</th>
|
<th className="py-2 font-medium">{t('admin.users.statusLabel')}</th>
|
||||||
|
<th className="py-2 font-medium">{t('admin.users.billingLabel')}</th>
|
||||||
<th className="py-2" />
|
<th className="py-2" />
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -73,6 +75,13 @@ function AdminUsersPage() {
|
|||||||
: t('admin.users.status.pending')}
|
: t('admin.users.status.pending')}
|
||||||
</Badge>
|
</Badge>
|
||||||
</td>
|
</td>
|
||||||
|
<td className="py-2">
|
||||||
|
{user.billingEnabled ? (
|
||||||
|
<PaidUntilBadge paidUntil={user.billingPaidUntil} />
|
||||||
|
) : (
|
||||||
|
<span className="text-muted-foreground">—</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
<td className="py-2 text-right">
|
<td className="py-2 text-right">
|
||||||
<Button size="sm" variant="outline" onClick={() => setManaging(user)}>
|
<Button size="sm" variant="outline" onClick={() => setManaging(user)}>
|
||||||
{t('admin.users.manage')}
|
{t('admin.users.manage')}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute, Link } from '@tanstack/react-router'
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery } from '@tanstack/react-query'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useRequireAuth } from '@/features/auth/guards'
|
import { useRequireAuth } from '@/features/auth/guards'
|
||||||
@@ -6,6 +6,8 @@ import { ActivationGate } from '@/features/activation/ActivationGate'
|
|||||||
import { ConfigCard } from '@/features/configs/ConfigCard'
|
import { ConfigCard } from '@/features/configs/ConfigCard'
|
||||||
import { CreateConfigDialog } from '@/features/configs/CreateConfigDialog'
|
import { CreateConfigDialog } from '@/features/configs/CreateConfigDialog'
|
||||||
import { SubscriptionCard } from '@/features/configs/SubscriptionCard'
|
import { SubscriptionCard } from '@/features/configs/SubscriptionCard'
|
||||||
|
import { PaidUntilBadge } from '@/features/billing/PaidUntilBadge'
|
||||||
|
import { getMyBillingStatus } from '@/features/billing/api'
|
||||||
import { getMyConfigs, listAvailableInbounds } from '@/features/configs/api'
|
import { getMyConfigs, listAvailableInbounds } from '@/features/configs/api'
|
||||||
|
|
||||||
export const Route = createFileRoute('/dashboard')({ component: DashboardPage })
|
export const Route = createFileRoute('/dashboard')({ component: DashboardPage })
|
||||||
@@ -26,6 +28,7 @@ function ConfigsList() {
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { data, isLoading } = useQuery({ queryKey: ['my-configs'], queryFn: getMyConfigs })
|
const { data, isLoading } = useQuery({ queryKey: ['my-configs'], queryFn: getMyConfigs })
|
||||||
const inboundsQuery = useQuery({ queryKey: ['available-inbounds'], queryFn: listAvailableInbounds })
|
const inboundsQuery = useQuery({ queryKey: ['available-inbounds'], queryFn: listAvailableInbounds })
|
||||||
|
const billingStatusQuery = useQuery({ queryKey: ['my-billing-status'], queryFn: getMyBillingStatus })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto flex w-full max-w-4xl flex-col gap-6 px-6 py-10">
|
<div className="mx-auto flex w-full max-w-4xl flex-col gap-6 px-6 py-10">
|
||||||
@@ -39,6 +42,12 @@ function ConfigsList() {
|
|||||||
: t('configs.quota', { used: data.configs.length, max: data.maxConfigs })}
|
: t('configs.quota', { used: data.configs.length, max: data.maxConfigs })}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
{billingStatusQuery.data?.billingEnabled && (
|
||||||
|
<Link to="/billing" className="mt-1 inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground">
|
||||||
|
{t('billing.paidUntilLabel')}
|
||||||
|
<PaidUntilBadge paidUntil={billingStatusQuery.data.paidUntil} />
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{inboundsQuery.data?.length === 0 ? (
|
{inboundsQuery.data?.length === 0 ? (
|
||||||
<p className="max-w-xs text-right text-sm text-muted-foreground">{t('configs.noInboundsNotice')}</p>
|
<p className="max-w-xs text-right text-sm text-muted-foreground">{t('configs.noInboundsNotice')}</p>
|
||||||
|
|||||||
@@ -165,6 +165,8 @@ export type UserSummaryDto = {
|
|||||||
isActivated: boolean
|
isActivated: boolean
|
||||||
isBlocked: boolean
|
isBlocked: boolean
|
||||||
activatedAt: string | null
|
activatedAt: string | null
|
||||||
|
billingEnabled: boolean
|
||||||
|
billingPaidUntil: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RoleDto = {
|
export type RoleDto = {
|
||||||
|
|||||||
@@ -107,7 +107,11 @@ const resources = {
|
|||||||
status: 'Статус оплаты',
|
status: 'Статус оплаты',
|
||||||
suspended: 'Приостановлено',
|
suspended: 'Приостановлено',
|
||||||
paidUntil: 'Оплачено до {{date}}',
|
paidUntil: 'Оплачено до {{date}}',
|
||||||
|
paidUntilLabel: 'Оплата:',
|
||||||
neverPaid: 'Оплата ещё не производилась.',
|
neverPaid: 'Оплата ещё не производилась.',
|
||||||
|
neverPaidShort: 'Не оплачено',
|
||||||
|
expiredShort: 'Истекло',
|
||||||
|
daysRemaining: '{{count}} дн.',
|
||||||
newRequest: 'Оформить оплату',
|
newRequest: 'Оформить оплату',
|
||||||
period: 'Период',
|
period: 'Период',
|
||||||
periods: {
|
periods: {
|
||||||
@@ -246,6 +250,7 @@ const resources = {
|
|||||||
userName: 'Имя пользователя',
|
userName: 'Имя пользователя',
|
||||||
role: 'Роль',
|
role: 'Роль',
|
||||||
statusLabel: 'Статус',
|
statusLabel: 'Статус',
|
||||||
|
billingLabel: 'Оплачено до',
|
||||||
manage: 'Управление',
|
manage: 'Управление',
|
||||||
empty: 'Пользователи не найдены.',
|
empty: 'Пользователи не найдены.',
|
||||||
total: 'Всего: {{count}}',
|
total: 'Всего: {{count}}',
|
||||||
@@ -616,7 +621,11 @@ const resources = {
|
|||||||
status: 'Payment status',
|
status: 'Payment status',
|
||||||
suspended: 'Suspended',
|
suspended: 'Suspended',
|
||||||
paidUntil: 'Paid until {{date}}',
|
paidUntil: 'Paid until {{date}}',
|
||||||
|
paidUntilLabel: 'Payment:',
|
||||||
neverPaid: 'No payment has been made yet.',
|
neverPaid: 'No payment has been made yet.',
|
||||||
|
neverPaidShort: 'Not paid',
|
||||||
|
expiredShort: 'Expired',
|
||||||
|
daysRemaining: '{{count}}d',
|
||||||
newRequest: 'Set up payment',
|
newRequest: 'Set up payment',
|
||||||
period: 'Period',
|
period: 'Period',
|
||||||
periods: {
|
periods: {
|
||||||
@@ -755,6 +764,7 @@ const resources = {
|
|||||||
userName: 'Username',
|
userName: 'Username',
|
||||||
role: 'Role',
|
role: 'Role',
|
||||||
statusLabel: 'Status',
|
statusLabel: 'Status',
|
||||||
|
billingLabel: 'Paid until',
|
||||||
manage: 'Manage',
|
manage: 'Manage',
|
||||||
empty: 'No users found.',
|
empty: 'No users found.',
|
||||||
total: 'Total: {{count}}',
|
total: 'Total: {{count}}',
|
||||||
|
|||||||
Reference in New Issue
Block a user