fix: netlify doesn't seem to handle redirects in a server action therefor we do the redirect on the client instead
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import Image from "next/image"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { type ReactNode, useTransition } from "react"
|
||||
import { FormProvider, useForm } from "react-hook-form"
|
||||
import { useIntl } from "react-intl"
|
||||
@@ -24,8 +25,11 @@ export function LinkAccountForm({
|
||||
onSubmit,
|
||||
}: {
|
||||
initialDateOfBirth: string | null
|
||||
onSubmit: (dateOfBirth: string) => Promise<void>
|
||||
onSubmit: (
|
||||
dateOfBirth: string
|
||||
) => Promise<{ success: boolean; redirectUrl?: string }>
|
||||
}) {
|
||||
const router = useRouter()
|
||||
let [isPending, startTransition] = useTransition()
|
||||
const intl = useIntl()
|
||||
const form = useForm<LinkAccountForm>({
|
||||
@@ -39,7 +43,12 @@ export function LinkAccountForm({
|
||||
startTransition(async () => {
|
||||
if (!data.dateOfBirth || !data.termsAndConditions) return
|
||||
|
||||
await onSubmit(data.dateOfBirth)
|
||||
const result = await onSubmit(data.dateOfBirth)
|
||||
if (!result.success || !result.redirectUrl) {
|
||||
throw new Error("Unable to redirect")
|
||||
}
|
||||
|
||||
router.push(result.redirectUrl)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user