Fix sender detection logic to use senderRef field

- Change IMessage interface to use senderRef instead of sender
- Update message rendering logic to check if senderRef === 'Admin' for admin messages
- All other messages are treated as seller messages
This commit is contained in:
hamid zarghami
2025-10-12 17:05:46 +03:30
parent 28e59d6805
commit 361c761435
2 changed files with 39 additions and 36 deletions
+38 -35
View File
@@ -146,46 +146,49 @@ const TicketMessages: FC = () => {
هیچ پیامی یافت نشد
</div>
) : (
messages.map((message: IMessage) => (
<div
key={message._id}
className={`flex ${message.sender === 'admin' ? 'justify-end' : 'justify-start'}`}
>
messages.map((message: IMessage) => {
const isAdmin = message.senderRef === 'Admin'
return (
<div
className={`max-w-[70%] p-4 rounded-2xl ${
message.sender === 'admin'
? 'bg-blue-500 text-white rounded-br-md'
: 'bg-gray-100 text-gray-900 rounded-bl-md'
}`}
key={message._id}
className={`flex ${isAdmin ? 'justify-end' : 'justify-start'}`}
>
<div className="text-sm mb-2">
{message.sender === 'admin' ? 'ادمین' : 'فروشنده'}
</div>
<div className="whitespace-pre-wrap">
{message.content}
</div>
{message.attachments && message.attachments.length > 0 && (
<div className="mt-2 space-y-1">
{message.attachments.map((attachment, index) => (
<div
key={index}
className={`text-xs underline ${
message.sender === 'admin' ? 'text-blue-100' : 'text-blue-600'
}`}
>
فایل ضمیمه: {attachment}
</div>
))}
<div
className={`max-w-[70%] p-4 rounded-2xl ${
isAdmin
? 'bg-blue-500 text-white rounded-br-md'
: 'bg-gray-100 text-gray-900 rounded-bl-md'
}`}
>
<div className="text-sm mb-2">
{isAdmin ? 'ادمین' : 'فروشنده'}
</div>
<div className="whitespace-pre-wrap">
{message.content}
</div>
{message.attachments && message.attachments.length > 0 && (
<div className="mt-2 space-y-1">
{message.attachments.map((attachment, index) => (
<div
key={index}
className={`text-xs underline ${
isAdmin ? 'text-blue-100' : 'text-blue-600'
}`}
>
فایل ضمیمه: {attachment}
</div>
))}
</div>
)}
<div className={`text-xs mt-2 ${
isAdmin ? 'text-blue-100' : 'text-gray-500'
}`}>
{message.createdAt && formatDate(message.createdAt)}
</div>
)}
<div className={`text-xs mt-2 ${
message.sender === 'admin' ? 'text-blue-100' : 'text-gray-500'
}`}>
{message.createdAt && formatDate(message.createdAt)}
</div>
</div>
</div>
))
)
})
)}
</div>
</div>
+1 -1
View File
@@ -65,7 +65,7 @@ export interface IMessage {
attachments?: string[];
createdAt?: string;
updatedAt?: string;
sender?: "admin" | "seller";
senderRef?: string;
}
export interface ITicketResponse extends IBaseResponse {