'use client' import { updateThreadName } from '@/app/actions' import { createRef, useEffect } from 'react' import { useFormState, useFormStatus } from 'react-dom' import { Button, Input_Shadcn_, Label_Shadcn_, Modal } from 'ui' import { ThreadType } from './Threads' const EditThreadModal = ({ thread, onClose, visible, }: { thread: ThreadType onClose: () => void visible: boolean }) => { const formRef = createRef() const initialState = { message: undefined, success: undefined, data: { thread_id: thread.thread_id, thread_title: thread.thread_title, }, } const [state, formAction] = useFormState(updateThreadName, initialState) useEffect(() => { if (state?.success === true) { onClose() formRef.current?.reset() state.success = undefined } }, [state, onClose, formRef]) function SubmitButton() { const { pending } = useFormStatus() return ( ) } return (
Provide a name for your thread

{state?.message}

) } export default EditThreadModal