'use client'; import { Display } from '@/components/display'; import { ProTable } from '@/components/pro-table'; import { queryQuotaTaskList } from '@/services/admin/marketing'; import { useSubscribe } from '@/store/subscribe'; import { formatDate } from '@/utils/common'; import { Badge } from '@workspace/ui/components/badge'; import { ScrollArea } from '@workspace/ui/components/scroll-area'; import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger, } from '@workspace/ui/components/sheet'; import { Icon } from '@workspace/ui/custom-components/icon'; import { useTranslations } from 'next-intl'; import { useState } from 'react'; export default function QuotaTaskManager() { const t = useTranslations('marketing'); const [open, setOpen] = useState(false); const { subscribes } = useSubscribe(); const subscribeMap = subscribes?.reduce( (acc, subscribe) => { acc[subscribe.id!] = subscribe.name!; return acc; }, {} as Record, ) || {}; const getStatusBadge = (status: number) => { const statusConfig = { 0: { label: t('notStarted'), variant: 'secondary' as const }, 1: { label: t('inProgress'), variant: 'default' as const }, 2: { label: t('completed'), variant: 'default' as const }, }; const config = statusConfig[status as keyof typeof statusConfig] || { label: `${t('status')} ${status}`, variant: 'secondary' as const, }; return {config.label}; }; return (

{t('quotaTaskManager')}

{t('viewAndManageQuotaTasks')}

{t('quotaTasks')}
{open && ( columns={[ { accessorKey: 'subscribers', header: t('subscribers'), size: 200, cell: ({ row }) => { const subscribers = row.getValue('subscribers') as number[]; const subscriptionNames = subscribers?.map((id) => subscribeMap[id]).filter(Boolean) || []; if (subscriptionNames.length === 0) { return ( {t('noSubscriptions')} ); } return (
{subscriptionNames.map((name, index) => ( {name} ))}
); }, }, { accessorKey: 'is_active', header: t('validOnly'), size: 120, cell: ({ row }) => { const isActive = row.getValue('is_active') as boolean; return {isActive ? t('yes') : t('no')}; }, }, { accessorKey: 'reset_traffic', header: t('resetTraffic'), size: 120, cell: ({ row }) => { const resetTraffic = row.getValue('reset_traffic') as boolean; return {resetTraffic ? t('yes') : t('no')}; }, }, { accessorKey: 'gift_value', header: t('giftAmount'), size: 120, cell: ({ row }) => { const giftValue = row.getValue('gift_value') as number; const task = row.original as API.QuotaTask; const giftType = task.gift_type; return (
{giftType === 1 ? ( ) : ( `${giftValue}%` )}
); }, }, { accessorKey: 'days', header: t('quotaDays'), size: 100, cell: ({ row }) => { const days = row.getValue('days') as number; return ( {days} {t('days')} ); }, }, { accessorKey: 'time_range', header: t('timeRange'), size: 180, cell: ({ row }) => { const task = row.original as API.QuotaTask; const startTime = task.start_time; const endTime = task.end_time; if (!startTime && !endTime) { return ( {t('noTimeLimit')} ); } return (
{startTime && (
{t('startTime')}: {formatDate(startTime)}
)} {endTime && (
{t('endTime')}: {formatDate(endTime)}
)}
); }, }, { accessorKey: 'status', header: t('status'), size: 100, cell: ({ row }) => getStatusBadge(row.getValue('status') as number), }, { accessorKey: 'created_at', header: t('createdAt'), size: 150, cell: ({ row }) => { const createdAt = row.getValue('created_at') as number; return formatDate(createdAt); }, }, ]} request={async (pagination, filters) => { const response = await queryQuotaTaskList({ ...filters, page: pagination.page, size: pagination.size, }); return { list: response.data?.data?.list || [], total: response.data?.data?.total || 0, }; }} params={[ { key: 'status', placeholder: t('status'), options: [ { label: t('notStarted'), value: '0' }, { label: t('inProgress'), value: '1' }, { label: t('completed'), value: '2' }, ], }, ]} /> )}
); }