MCPcopy
hub / github.com/shadcn-ui/taxonomy / onSubmit

Function onSubmit

components/editor.tsx:86–117  ·  view source on GitHub ↗
(data: FormData)

Source from the content-addressed store, hash-verified

84 }, [isMounted, initializeEditor])
85
86 async function onSubmit(data: FormData) {
87 setIsSaving(true)
88
89 const blocks = await ref.current?.save()
90
91 const response = await fetch(`/api/posts/${post.id}`, {
92 method: "PATCH",
93 headers: {
94 "Content-Type": "application/json",
95 },
96 body: JSON.stringify({
97 title: data.title,
98 content: blocks,
99 }),
100 })
101
102 setIsSaving(false)
103
104 if (!response?.ok) {
105 return toast({
106 title: "Something went wrong.",
107 description: "Your post was not saved. Please try again.",
108 variant: "destructive",
109 })
110 }
111
112 router.refresh()
113
114 return toast({
115 description: "Your post has been saved.",
116 })
117 }
118
119 if (!isMounted) {
120 return null

Callers

nothing calls this directly

Calls 1

toastFunction · 0.90

Tested by

no test coverage detected