Skip to content

Commit

Permalink
🐛 Fix pay wall submitting wrong form on click (#1503)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevella authored Jan 17, 2025
1 parent 5d9606b commit 7371842
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions apps/web/src/components/upgrade-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export const UpgradeButton = ({
large,
}: React.PropsWithChildren<{ annual?: boolean; large?: boolean }>) => {
const posthog = usePostHog();
const formRef = React.useRef<HTMLFormElement>(null);

return (
<form method="POST" action="/api/stripe/checkout">
<form ref={formRef} method="POST" action="/api/stripe/checkout">
<input
type="hidden"
name="period"
Expand All @@ -26,9 +27,14 @@ export const UpgradeButton = ({
<Button
size={large ? "lg" : "default"}
className="w-full"
type="submit"
variant="primary"
onClick={() => {
onClick={(e) => {
// 🐛 Since we have nested forms, we need to prevent the default
// action of the button from being triggered so that we don't submit
// the parent form.
// TODO: Fix this by making sure we never have nested forms.
e.preventDefault();
formRef.current?.submit();
posthog?.capture("click upgrade button");
}}
>
Expand Down

0 comments on commit 7371842

Please sign in to comment.