diff --git a/packages/chat/src/ui/chat/Input.client.tsx b/packages/chat/src/ui/chat/Input.client.tsx index c3408b3..6d8fca4 100644 --- a/packages/chat/src/ui/chat/Input.client.tsx +++ b/packages/chat/src/ui/chat/Input.client.tsx @@ -15,6 +15,7 @@ export const SendMessageUI = ({ chatId }: ChatId) => { diff --git a/packages/chat/src/ui/chat/insertMessage.action.ts b/packages/chat/src/ui/chat/insertMessage.action.ts index 6571696..9b601a6 100644 --- a/packages/chat/src/ui/chat/insertMessage.action.ts +++ b/packages/chat/src/ui/chat/insertMessage.action.ts @@ -3,6 +3,8 @@ import type {Chat, User} from '../../payload-types' import {headers} from 'next/headers' import config from '@payload-config' import {get, isString} from 'radash' +import {revalidatePath} from 'next/cache' +import {redirect} from 'next/navigation' interface Props { message: string @@ -37,6 +39,14 @@ export async function insertMessageAction(data: FormData) { messages: [{ role: 'user', text: message }], user: get(user, 'id'), } satisfies Partial - await instance.create({ collection: 'chats', data: chat, user }) + const newChat = await instance.create({ + collection: 'chats', + data: chat, + user, + }) + const id = get(newChat, 'id') + redirect(`/admin/chat/${id}`) } + + revalidatePath(`/admin/chat/${chatId}`) }