mirror of
https://github.com/shadcn-ui/taxonomy
synced 2026-05-24 09:48:32 +00:00
fix: post can't be updated without input change
This commit is contained in:
parent
55e17df39f
commit
507ab2fef6
1 changed files with 4 additions and 2 deletions
|
|
@ -24,7 +24,7 @@ interface EditorProps {
|
|||
type FormData = z.infer<typeof postPatchSchema>
|
||||
|
||||
export function Editor({ post }: EditorProps) {
|
||||
const { register, handleSubmit } = useForm<FormData>({
|
||||
const { register, handleSubmit, formState } = useForm<FormData>({
|
||||
resolver: zodResolver(postPatchSchema),
|
||||
})
|
||||
const ref = React.useRef<EditorJS>()
|
||||
|
|
@ -84,6 +84,8 @@ export function Editor({ post }: EditorProps) {
|
|||
}, [isMounted, initializeEditor])
|
||||
|
||||
async function onSubmit(data: FormData) {
|
||||
if (!formState.isDirty) return
|
||||
|
||||
setIsSaving(true)
|
||||
|
||||
const blocks = await ref.current?.save()
|
||||
|
|
@ -140,7 +142,7 @@ export function Editor({ post }: EditorProps) {
|
|||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSaving}
|
||||
disabled={isSaving || !formState.isDirty}
|
||||
className={cn(buttonVariants())}
|
||||
>
|
||||
{isSaving && (
|
||||
|
|
|
|||
Loading…
Reference in a new issue