Skip to content

Commit

Permalink
Auth Works
Browse files Browse the repository at this point in the history
  • Loading branch information
awhiteside1 committed Sep 23, 2024
1 parent 37f3645 commit 3284273
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/chat/src/ui/chat/Input.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const SendMessageUI = ({ chatId }: ChatId) => {
<input
name="message"
id="message"
required
className="flex-grow p-2 border border-gray-300 rounded-l"
placeholder="Type your message..."
/>
Expand Down
12 changes: 11 additions & 1 deletion packages/chat/src/ui/chat/insertMessage.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,6 +39,14 @@ export async function insertMessageAction(data: FormData) {
messages: [{ role: 'user', text: message }],
user: get<number>(user, 'id'),
} satisfies Partial<Chat>
await instance.create({ collection: 'chats', data: chat, user })
const newChat = await instance.create({
collection: 'chats',
data: chat,
user,
})
const id = get<number>(newChat, 'id')
redirect(`/admin/chat/${id}`)
}

revalidatePath(`/admin/chat/${chatId}`)
}

0 comments on commit 3284273

Please sign in to comment.