veza/apps/web/src/features/chat/components/ChatMessage.tsx

41 lines
1.1 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { ChatMessage } from '../store/chatStore';
import { useAuthStore } from '@/features/auth/store/authStore';
import { cn } from '@/lib/utils';
interface ChatMessageProps {
message: ChatMessage;
}
2025-12-13 02:34:34 +00:00
export const ChatMessageComponent: React.FC<ChatMessageProps> = ({
message,
}) => {
const { user } = useAuthStore();
2025-12-13 02:34:34 +00:00
const isMe = String(user?.id) === String(message.sender_id);
return (
<div
className={cn(
2025-12-13 02:34:34 +00:00
'flex items-start gap-3 p-2 rounded-lg max-w-[80%] my-1',
isMe
? 'ml-auto bg-blue-500 text-white'
: 'mr-auto bg-gray-200 text-gray-800',
)}
>
<div className="flex flex-col">
<div className="flex items-center gap-2">
<span className="font-semibold text-sm">
2025-12-13 02:34:34 +00:00
{isMe
? 'Moi'
: message.sender_username || `Utilisateur ${message.sender_id}`}
</span>
<span className="text-xs opacity-75">
{new Date(message.created_at).toLocaleTimeString()}
</span>
</div>
<p className="text-sm">{message.content}</p>
</div>
</div>
);
2025-12-13 02:34:34 +00:00
};