mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 19:35:06 +03:00
* add a new component for input * add textArea * some colors * rename * Update page.tsx * move files * Update ChatInput.tsx * Update Header.tsx * chore:upgrade next14 * Update package-lock.json * update graphql * add graphql dep * Update package.json * Update package-lock.json * added server action in * more actions * getting actions in everywhere * Update ConfirmDeleteThreadModal.tsx * Update Input.tsx * update modal action * Bump nextjs in database-new to v14. * fix build * trying server hooks * more experiemntal stuff * update delete * shimmering * update thread UI * Update actions.ts * Update actions.ts * Update Thread.tsx * Update Input.tsx * updated * delete thread updated * fix build * Update package-lock.json * Update edit thread modal * fixing build * reset * Update package-lock.json * Update SpreadsheetImport.utils.ts * reset * Update package-lock.json * Update sitemap_www.xml * pacakge update * change to node 18 * Fix deleting threads --------- Co-authored-by: Terry Sutton <saltcod@gmail.com>
84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
'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<HTMLFormElement>()
|
|
|
|
const initialState = {
|
|
message: undefined,
|
|
success: undefined,
|
|
data: {
|
|
row_id: 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 (
|
|
<Button type="secondary" htmlType="submit" aria-disabled={pending} loading={pending}>
|
|
Update thread name
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Modal
|
|
alignFooter="right"
|
|
size="medium"
|
|
visible={visible}
|
|
onCancel={onClose}
|
|
hideFooter
|
|
header="Edit thread name"
|
|
className="pb-2"
|
|
>
|
|
<form ref={formRef} action={formAction} key={`${thread.id}-update-thread-title-form`}>
|
|
<Modal.Content className="py-4">
|
|
<Label_Shadcn_ htmlFor="thread_title">Provide a name for your thread</Label_Shadcn_>
|
|
<Input_Shadcn_
|
|
placeholder="Type in a name for the thread..."
|
|
type="text"
|
|
name="thread_title"
|
|
defaultValue={state.data.thread_title}
|
|
/>
|
|
<Input_Shadcn_ name="row_id" value={state.data.row_id} type="hidden" />
|
|
</Modal.Content>
|
|
<Modal.Separator />
|
|
<Modal.Content className="flex flex-row gap-3 justify-end">
|
|
<Button type="default">Cancel</Button>
|
|
<SubmitButton />
|
|
<p aria-live="polite" className="sr-only" role="status">
|
|
{state?.message}
|
|
</p>
|
|
</Modal.Content>
|
|
</form>
|
|
</Modal>
|
|
)
|
|
}
|
|
|
|
export default EditThreadModal
|