In progress : Implementing the updateProcess logic when sending a message
This commit is contained in:
parent
750eada9b1
commit
e607d7850b
@ -13,6 +13,8 @@ import {
|
|||||||
MessageSquare
|
MessageSquare
|
||||||
} from "lucide-react"
|
} from "lucide-react"
|
||||||
import type { EnrichedFolderData } from "@/lib/contexts/FourNKContext";
|
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 pour les props (accepte null)
|
||||||
interface FolderChatProps {
|
interface FolderChatProps {
|
||||||
@ -45,10 +47,50 @@ export default function FolderChat({ folder }: FolderChatProps) {
|
|||||||
// Filtre les messages basé sur l'onglet actif
|
// Filtre les messages basé sur l'onglet actif
|
||||||
const filteredMessages = mockMessages.filter(msg => msg.type === activeTab);
|
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 = () => {
|
const handleSendMessage = () => {
|
||||||
if (newMessage.trim()) {
|
if (newMessage.trim()) {
|
||||||
console.log(`Envoi message [${activeTab}] à:`, folder?.folderNumber, "Msg:", newMessage)
|
console.log(`Envoi message [${activeTab}] à:`, folder?.folderNumber, "Msg:", newMessage)
|
||||||
// TODO: Implémenter la logique d'envoi de message
|
// 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("")
|
setNewMessage("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,8 +173,8 @@ export default function FolderChat({ folder }: FolderChatProps) {
|
|||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
className={`p-3 rounded-lg ${msg.sender === 'me'
|
className={`p-3 rounded-lg ${msg.sender === 'me'
|
||||||
? 'bg-blue-600 text-white rounded-br-none'
|
? 'bg-blue-600 text-white rounded-br-none'
|
||||||
: 'bg-gray-700 text-gray-100 rounded-bl-none'
|
: 'bg-gray-700 text-gray-100 rounded-bl-none'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{msg.sender === 'other' && (
|
{msg.sender === 'other' && (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user