sadmann7 / shadcn-table

Shadcn table with server-side sorting, filtering, and pagination.
https://table.sadmn.com
MIT License
2.44k stars 218 forks source link

[bug]: Update sheet bug #475

Open newtonmathias opened 2 months ago

newtonmathias commented 2 months ago

Describe the bug

If you sort, or filter the table, then try to edit a task, the update sheet opens with the wrong task info. Same with when you click next page, and try to edit the first item, the update sheet contains the first item from the previous page.

How to reproduce

Try to edit a task. Then filter or sort or move to next page. Try to edit another task. The update sheet will not contain info of the current selected task

Link to reproduction

https://table.sadmn.com/

Additional information

No response

whatif-dev commented 2 months ago

@newtonmathias

That has been an issue for awhile now. Got the AI to fix it but didn't want to submit it because I am a code newbie and didn't feel confident submitting AI code fixes. But this did do the trick for me... in src/app_components/update-tasks-sheets.tsx. Use at your own risk ... lol Like I said I am a newbie and it is AI gen.

export function UpdateTaskSheet({ task, ...props }: UpdateTaskSheetProps) { const [isUpdatePending, startUpdateTransition] = React.useTransition()

const form = useForm({ resolver: zodResolver(updateTaskSchema), defaultValues: { title: task.title ?? "", label: task.label, status: task.status, priority: task.priority, }, })

// NEW CODE React.useEffect(() => { form.reset({ title: task.title ?? "", label: task.label, status: task.status, priority: task.priority, }) }, [task])

newtonmathias commented 2 months ago

@whatif-dev Thanks I will check that out

newtonmathias commented 2 months ago

@sadmann7 Are you aware of this bug?