import React, { useState, useRef, useEffect } from 'react'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '../ui/dialog'; import { Button } from '../ui/button'; import { Input } from '../ui/input'; import { Avatar, AvatarFallback } from '../ui/avatar'; import { Badge } from '../ui/badge'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '../ui/tabs'; import { ScrollArea } from '../ui/scroll-area'; import { Send, Smile, Paperclip, Users, FileText, Download, Eye, MoreHorizontal } from 'lucide-react'; interface Message { id: string; user: { name: string; avatar: string; role: string; }; content: string; timestamp: string; mentions?: string[]; isSystem?: boolean; } interface WorkNoteModalProps { open: boolean; onClose: () => void; requestId: string; } export function WorkNoteModal({ open, onClose, requestId }: WorkNoteModalProps) { const [message, setMessage] = useState(''); const [isTyping, setIsTyping] = useState(false); const messagesEndRef = useRef(null); const participants = [ { name: 'Sarah Chen', avatar: 'SC', role: 'Initiator', status: 'online' }, { name: 'Mike Johnson', avatar: 'MJ', role: 'Team Lead', status: 'online' }, { name: 'Lisa Wong', avatar: 'LW', role: 'Finance Manager', status: 'away' }, { name: 'Anna Smith', avatar: 'AS', role: 'Spectator', status: 'offline' }, { name: 'John Doe', avatar: 'JD', role: 'Spectator', status: 'online' } ]; const documents = [ { name: 'Q4_Marketing_Strategy.pdf', size: '2.4 MB', uploadedBy: 'Sarah Chen', uploadedAt: '2024-10-05 14:32' }, { name: 'Budget_Breakdown.xlsx', size: '1.1 MB', uploadedBy: 'Sarah Chen', uploadedAt: '2024-10-05 14:35' }, { name: 'Previous_Campaign_ROI.pdf', size: '856 KB', uploadedBy: 'Anna Smith', uploadedAt: '2024-10-06 09:15' } ]; const [messages, setMessages] = useState([ { id: '1', user: { name: 'Sarah Chen', avatar: 'SC', role: 'Initiator' }, content: 'Hi everyone! I\'ve submitted the marketing campaign budget request. Please review the attached documents.', timestamp: '2024-10-05 14:30', isSystem: false }, { id: '2', user: { name: 'System', avatar: 'SY', role: 'System' }, content: 'Request RE-REQ-001 has been created and assigned to Mike Johnson for initial review.', timestamp: '2024-10-05 14:31', isSystem: true }, { id: '3', user: { name: 'Anna Smith', avatar: 'AS', role: 'Spectator' }, content: 'I\'ve added the previous campaign ROI data to help with the decision. @Mike Johnson @Lisa Wong please check it out.', timestamp: '2024-10-06 09:15', mentions: ['Mike Johnson', 'Lisa Wong'] }, { id: '4', user: { name: 'Mike Johnson', avatar: 'MJ', role: 'Team Lead' }, content: 'Thanks @Anna Smith! The numbers look good. I\'m approving this and forwarding to Finance.', timestamp: '2024-10-06 10:30', mentions: ['Anna Smith'] }, { id: '5', user: { name: 'System', avatar: 'SY', role: 'System' }, content: 'Request approved by Mike Johnson and forwarded to Lisa Wong for finance review.', timestamp: '2024-10-06 10:31', isSystem: true }, { id: '6', user: { name: 'Lisa Wong', avatar: 'LW', role: 'Finance Manager' }, content: 'I\'m reviewing the budget allocation. @Sarah Chen can you clarify the expected timeline for the LinkedIn ads campaign?', timestamp: '2024-10-07 14:20', mentions: ['Sarah Chen'] } ]); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }; useEffect(() => { scrollToBottom(); }, [messages]); const handleSendMessage = () => { if (message.trim()) { const newMessage: Message = { id: Date.now().toString(), user: { name: 'You', avatar: 'YO', role: 'Current User' }, content: message, timestamp: new Date().toLocaleString(), mentions: extractMentions(message) }; setMessages([...messages, newMessage]); setMessage(''); } }; const extractMentions = (text: string): string[] => { const mentionRegex = /@(\w+\s?\w+)/g; const mentions = []; let match; while ((match = mentionRegex.exec(text)) !== null) { mentions.push(match[1]); } return mentions; }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSendMessage(); } }; const getStatusColor = (status: string) => { switch (status) { case 'online': return 'bg-green-500'; case 'away': return 'bg-yellow-500'; case 'offline': return 'bg-gray-400'; default: return 'bg-gray-400'; } }; const formatMessage = (content: string) => { // Simple mention highlighting return content.replace(/@(\w+\s?\w+)/g, '@$1'); }; return ( Work Notes - {requestId} Collaborate with all request participants
{/* Main Chat Area */}
Chat Media
{messages.map((msg) => (
{!msg.isSystem && ( {msg.user.avatar} )}
{msg.isSystem ? (
{msg.content} {msg.timestamp}
) : ( <>
{msg.user.name} {msg.user.role} {msg.timestamp}
)}
))} {isTyping && (
...
Someone is typing...
)}
{/* Message Input */}
setMessage(e.target.value)} onKeyPress={handleKeyPress} className="pr-20" />

Documents ({documents.length})

{documents.map((doc, index) => (

{doc.name}

{doc.size} • by {doc.uploadedBy}

{doc.uploadedAt}

))}
{/* Participants Sidebar */}

Participants

{participants.length}
{participants.map((participant, index) => (
{participant.avatar}

{participant.name}

{participant.role}

))}

Quick Actions

); }