diff --git a/src/pages/ticket/TicketMessages.tsx b/src/pages/ticket/TicketMessages.tsx new file mode 100644 index 0000000..725f31d --- /dev/null +++ b/src/pages/ticket/TicketMessages.tsx @@ -0,0 +1,228 @@ +import { type FC, useState } from 'react' +import { useGetTicket, useAddTicketMessage } from './hooks/useTicketData' +import { useParams } from 'react-router-dom' +import { type IMessage, type TicketStatus } from './types/Types' +import PageLoading from '../../components/PageLoading' +import Error from '../../components/Error' +import StatusWithText from '../../components/StatusWithText' +import { formatDate } from '../../helpers/func' +import { MessageQuestion, User as UserIcon, Category, Calendar } from 'iconsax-react' +import Button from '@/components/Button' +import Textarea from '@/components/Textarea' +import UploadBox from '@/components/UploadBox' + +const TicketMessages: FC = () => { + const { id } = useParams() + const { data, isLoading, refetch } = useGetTicket(id as string) + const [messageContent, setMessageContent] = useState('') + const [attachments, setAttachments] = useState([]) + + const addMessageMutation = useAddTicketMessage() + + if (isLoading) { + return ( +
+ +
+ ) + } + + if (!data) { + return ( +
+ +
+ ) + } + + const ticket = data.results.ticket + const messages = data.results.messages + + const getStatusVariant = (status: TicketStatus) => { + switch (status) { + case 'closed': return 'error' + case 'answered': return 'success' + case 'pending': return 'warning' + default: return 'warning' + } + } + + const getStatusText = (status: TicketStatus) => { + switch (status) { + case 'closed': return 'بسته شده' + case 'answered': return 'پاسخ داده شده' + case 'pending': return 'در انتظار' + default: return status + } + } + + const handleSendMessage = async () => { + if (!messageContent.trim()) return + + try { + await addMessageMutation.mutateAsync({ + ticketId: ticket._id, + params: { + content: messageContent, + attachments: [] // TODO: handle file uploads + } + }) + setMessageContent('') + setAttachments([]) + refetch() + } catch (error) { + console.error('Error sending message:', error) + } + } + + const handleFileChange = (files: File[]) => { + setAttachments(files) + } + + return ( +
+ {/* Ticket Info */} +
+
+ +

جزئیات تیکت

+
+ +
+
+
شماره تیکت
+
+ + {ticket.numericId} +
+
+ +
+
فروشنده
+
+ + {ticket.seller?.fullName || '-'} +
+
+ +
+
موضوع
+
{ticket.subject}
+
+ +
+
دسته‌بندی
+
+ + {ticket.category?.title_fa || '-'} +
+
+ +
+
وضعیت
+ +
+ +
+
تاریخ بروزرسانی
+
+ + {formatDate(ticket.updatedAt)} +
+
+
+
+ + {/* Messages Section */} +
+

پیام‌ها

+ +
+ {messages.length === 0 ? ( +
+ هیچ پیامی یافت نشد +
+ ) : ( + messages.map((message: IMessage) => ( +
+
+
+ {message.sender === 'admin' ? 'ادمین' : 'فروشنده'} +
+
+ {message.content} +
+ {message.attachments && message.attachments.length > 0 && ( +
+ {message.attachments.map((attachment, index) => ( +
+ فایل ضمیمه: {attachment} +
+ ))} +
+ )} +
+ {message.createdAt && formatDate(message.createdAt)} +
+
+
+ )) + )} +
+
+ + {/* Send Message Form */} +
+

ارسال پیام جدید

+ +
+