'use client'; import { ProTable, ProTableActions } from '@/components/pro-table'; import { createTicketFollow, getTicket, getTicketList, updateTicketStatus, } from '@/services/admin/ticket'; import { useQuery } from '@tanstack/react-query'; import { Button } from '@workspace/ui/components/button'; import { Drawer, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, } from '@workspace/ui/components/drawer'; import { Input } from '@workspace/ui/components/input'; import { Label } from '@workspace/ui/components/label'; import { ScrollArea } from '@workspace/ui/components/scroll-area'; import { ConfirmButton } from '@workspace/ui/custom-components/confirm-button'; import { Icon } from '@workspace/ui/custom-components/icon'; import { cn } from '@workspace/ui/lib/utils'; import { formatDate } from '@workspace/ui/utils'; import { useTranslations } from 'next-intl'; import NextImage from 'next/legacy/image'; import { useEffect, useRef, useState } from 'react'; import { toast } from 'sonner'; import { UserDetail } from '../user/user-detail'; export default function Page() { const t = useTranslations('ticket'); const [ticketId, setTicketId] = useState(null); const [message, setMessage] = useState(''); const { data: ticket, refetch: refetchTicket } = useQuery({ queryKey: ['getTicket', ticketId], queryFn: async () => { const { data } = await getTicket({ id: ticketId, }); return data.data as API.Ticket; }, enabled: !!ticketId, refetchInterval: 5000, }); const scrollRef = useRef(null); useEffect(() => { setTimeout(() => { if (scrollRef.current) { scrollRef.current.children[1]?.scrollTo({ top: scrollRef.current.children[1].scrollHeight, behavior: 'smooth', }); } }, 66); }, [ticket?.follow?.length]); const ref = useRef(null); return ( <> action={ref} header={{ title: t('ticketList'), }} columns={[ { accessorKey: 'title', header: t('title'), }, { accessorKey: 'user_id', header: t('user'), cell: ({ row }) => , }, { accessorKey: 'status', header: t('status.0'), cell: ({ row }) => ( {t(`status.${row.original.status}`)} ), }, { accessorKey: 'updated_at', header: t('updatedAt'), cell: ({ row }) => formatDate(row.getValue('updated_at')), }, ]} params={[ { key: 'status', placeholder: t('status.0'), options: [ { label: t('close'), value: '4', }, ], }, ]} request={async (pagination, filters) => { const { data } = await getTicketList({ ...pagination, ...filters, issue_type: 0, }); return { list: data.data?.list || [], total: data.data?.total || 0, }; }} actions={{ render(row) { if (row.status !== 4) { return [ , {t('close')}} title={t('confirmClose')} description={t('closeWarning')} onConfirm={async () => { await updateTicketStatus({ id: row.id, status: 4, }); toast.success(t('closeSuccess')); ref.current?.refresh(); }} cancelText={t('cancel')} confirmText={t('confirm')} />, ]; } return [ , ]; }, }} /> { if (!open) setTicketId(null); }} > {ticket?.title} {ticket?.description}
{ticket?.follow?.map((item) => (

{formatDate(item.created_at)}

{item.type === 1 && item.content} {item.type === 2 && ( )}

))}
{ticket?.status !== 4 && (
{ event.preventDefault(); if (message) { await createTicketFollow({ ticket_id: ticketId, from: 'System', type: 1, content: message, }); refetchTicket(); setMessage(''); } }} > setMessage(e.target.value)} />
)}
); }