diff --git a/components/4nk/FolderChat.tsx b/components/4nk/FolderChat.tsx index 99aed6e..6aec6aa 100644 --- a/components/4nk/FolderChat.tsx +++ b/components/4nk/FolderChat.tsx @@ -13,6 +13,8 @@ import { MessageSquare } from "lucide-react" import type { EnrichedFolderData } from "@/lib/contexts/FourNKContext"; +import MessageBus from "@/lib/4nk/MessageBus" +import { iframeUrl } from "@/app/page" // Interface pour les props (accepte null) interface FolderChatProps { @@ -45,10 +47,50 @@ export default function FolderChat({ folder }: FolderChatProps) { // Filtre les messages basé sur l'onglet actif const filteredMessages = mockMessages.filter(msg => msg.type === activeTab); + const handleProcessUpdate = async (processId: string, key: string, value: any) => { + try { + const messageBus = MessageBus.getInstance(iframeUrl); + await messageBus.isReady(); + + const updateData = { + [key]: value + }; + + // First update the process + const updatedProcess = await messageBus.updateProcess(processId, updateData, [], null); + if (!updatedProcess) { + throw new Error('No updated process found'); + } + + const newStateId = updatedProcess.diffs[0]?.state_id; + + if (!newStateId) { + throw new Error('No new state id found'); + } + + // Then notify about the update + await messageBus.notifyProcessUpdate(processId, newStateId); + + // Finally validate the state + await messageBus.validateState(processId, newStateId); + + // Refresh the processes data + // const updatedProcesses = await messageBus.getProcesses(); + + console.log('Process updated successfully'); + } catch (error) { + console.error('Error updating field:', error); + // You might want to show an error message to the user here + } + }; + const handleSendMessage = () => { if (newMessage.trim()) { console.log(`Envoi message [${activeTab}] à:`, folder?.folderNumber, "Msg:", newMessage) // TODO: Implémenter la logique d'envoi de message + if(!folder) return; + const key = activeTab === 'owner' ? 'messages_owner' : 'messages' + handleProcessUpdate(folder.processId, key, newMessage) setNewMessage("") } } @@ -131,8 +173,8 @@ export default function FolderChat({ folder }: FolderChatProps) {