From 328427376e1b2107341ad2ffda1d796f145f9a33 Mon Sep 17 00:00:00 2001 From: Alex Whiteside Date: Mon, 23 Sep 2024 10:11:42 -0400 Subject: [PATCH] Auth Works --- packages/chat/src/ui/chat/Input.client.tsx | 1 + packages/chat/src/ui/chat/insertMessage.action.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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}`) }