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

Function onSubmit

components/billing-form.tsx:32–54  ·  view source on GitHub ↗
(event)

Source from the content-addressed store, hash-verified

30 const [isLoading, setIsLoading] = React.useState<boolean>(false)
31
32 async function onSubmit(event) {
33 event.preventDefault()
34 setIsLoading(!isLoading)
35
36 // Get a Stripe session URL.
37 const response = await fetch("/api/users/stripe")
38
39 if (!response?.ok) {
40 return toast({
41 title: "Something went wrong.",
42 description: "Please refresh the page and try again.",
43 variant: "destructive",
44 })
45 }
46
47 // Redirect to the Stripe session.
48 // This could be a checkout page for initial upgrade.
49 // Or portal to manage existing subscription.
50 const session = await response.json()
51 if (session) {
52 window.location.href = session.url
53 }
54 }
55
56 return (
57 <form className={cn(className)} onSubmit={onSubmit} {...props}>

Callers

nothing calls this directly

Calls 1

toastFunction · 0.90

Tested by

no test coverage detected