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
+10 -7
View File
@@ -146,20 +146,22 @@ const TicketMessages: FC = () => {
هیچ پیامی یافت نشد هیچ پیامی یافت نشد
</div> </div>
) : ( ) : (
messages.map((message: IMessage) => ( messages.map((message: IMessage) => {
const isAdmin = message.senderRef === 'Admin'
return (
<div <div
key={message._id} key={message._id}
className={`flex ${message.sender === 'admin' ? 'justify-end' : 'justify-start'}`} className={`flex ${isAdmin ? 'justify-end' : 'justify-start'}`}
> >
<div <div
className={`max-w-[70%] p-4 rounded-2xl ${ className={`max-w-[70%] p-4 rounded-2xl ${
message.sender === 'admin' isAdmin
? 'bg-blue-500 text-white rounded-br-md' ? 'bg-blue-500 text-white rounded-br-md'
: 'bg-gray-100 text-gray-900 rounded-bl-md' : 'bg-gray-100 text-gray-900 rounded-bl-md'
}`} }`}
> >
<div className="text-sm mb-2"> <div className="text-sm mb-2">
{message.sender === 'admin' ? 'ادمین' : 'فروشنده'} {isAdmin ? 'ادمین' : 'فروشنده'}
</div> </div>
<div className="whitespace-pre-wrap"> <div className="whitespace-pre-wrap">
{message.content} {message.content}
@@ -170,7 +172,7 @@ const TicketMessages: FC = () => {
<div <div
key={index} key={index}
className={`text-xs underline ${ className={`text-xs underline ${
message.sender === 'admin' ? 'text-blue-100' : 'text-blue-600' isAdmin ? 'text-blue-100' : 'text-blue-600'
}`} }`}
> >
فایل ضمیمه: {attachment} فایل ضمیمه: {attachment}
@@ -179,13 +181,14 @@ const TicketMessages: FC = () => {
</div> </div>
)} )}
<div className={`text-xs mt-2 ${ <div className={`text-xs mt-2 ${
message.sender === 'admin' ? 'text-blue-100' : 'text-gray-500' isAdmin ? 'text-blue-100' : 'text-gray-500'
}`}> }`}>
{message.createdAt && formatDate(message.createdAt)} {message.createdAt && formatDate(message.createdAt)}
</div> </div>
</div> </div>
</div> </div>
)) )
})
)} )}
</div> </div>
</div> </div>
+1 -1
View File
@@ -65,7 +65,7 @@ export interface IMessage {
attachments?: string[]; attachments?: string[];
createdAt?: string; createdAt?: string;
updatedAt?: string; updatedAt?: string;
sender?: "admin" | "seller"; senderRef?: string;
} }
export interface ITicketResponse extends IBaseResponse { export interface ITicketResponse extends IBaseResponse {