fix(rg): missing actionbutton context
This commit is contained in:
@@ -5,6 +5,11 @@ import { useRouter } from "next/navigation";
|
|||||||
import posthog from "posthog-js";
|
import posthog from "posthog-js";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { submitEndgame, submitEndgamePayment } from "./api";
|
import { submitEndgame, submitEndgamePayment } from "./api";
|
||||||
|
import { useRef } from "react";
|
||||||
|
import {
|
||||||
|
ActionSubmitContext,
|
||||||
|
ActionSubmitContextData,
|
||||||
|
} from "@/components/action-submit-provider";
|
||||||
|
|
||||||
export function EndgameFormWrapper({
|
export function EndgameFormWrapper({
|
||||||
type,
|
type,
|
||||||
@@ -12,6 +17,13 @@ export function EndgameFormWrapper({
|
|||||||
}: React.ComponentProps<"form"> & { type: "registration" | "payment" }) {
|
}: React.ComponentProps<"form"> & { type: "registration" | "payment" }) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { start, stop } = useProgress();
|
const { start, stop } = useProgress();
|
||||||
|
const callback = useRef<() => void>(() => {});
|
||||||
|
const context: ActionSubmitContextData = {
|
||||||
|
listenForComplete(complete) {
|
||||||
|
callback.current = complete;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
async function submit(data: FormData) {
|
async function submit(data: FormData) {
|
||||||
start();
|
start();
|
||||||
posthog.capture(
|
posthog.capture(
|
||||||
@@ -37,12 +49,16 @@ export function EndgameFormWrapper({
|
|||||||
.finally(stop);
|
.finally(stop);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<form
|
<ActionSubmitContext.Provider value={context}>
|
||||||
{...props}
|
<form
|
||||||
onSubmit={(e) => {
|
{...props}
|
||||||
e.preventDefault();
|
onSubmit={(e) => {
|
||||||
submit(new FormData(e.target as HTMLFormElement));
|
e.preventDefault();
|
||||||
}}
|
submit(new FormData(e.target as HTMLFormElement)).finally(() =>
|
||||||
/>
|
setTimeout(callback.current, 1000),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ActionSubmitContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user