sadmann7/shadcn-table

[bug]: Update sheet bug

newtonmathias opened this issue · 3 comments

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

@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])

@whatif-dev Thanks I will check that out

@sadmann7 Are you aware of this bug?