fix(subscription): allow return route prerendering
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { usePaymentRouteFlow } from "@/app/_hooks/use-payment-route-flow";
|
||||
import { useAppNavigator } from "@/router/use-app-navigator";
|
||||
import type { PayChannel } from "@/data/schemas/payment";
|
||||
import { DEFAULT_CHARACTER_SLUG } from "@/data/constants/character";
|
||||
import type { SubscriptionReturnTo } from "@/lib/navigation/subscription_exit";
|
||||
import {
|
||||
consumeSubscriptionExitUrl,
|
||||
resolveSubscriptionSuccessExitUrl,
|
||||
type SubscriptionReturnTo,
|
||||
} from "@/lib/navigation/subscription_exit";
|
||||
|
||||
import type { SubscriptionType } from "./subscription-screen.helpers";
|
||||
|
||||
@@ -25,7 +29,7 @@ export function useSubscriptionPaymentFlow({
|
||||
initialPayChannel,
|
||||
characterSlug = DEFAULT_CHARACTER_SLUG,
|
||||
}: UseSubscriptionPaymentFlowInput) {
|
||||
const navigator = useAppNavigator();
|
||||
const router = useRouter();
|
||||
const { payment, paymentDispatch } = usePaymentRouteFlow({
|
||||
initialPayChannel,
|
||||
paymentType: subscriptionType,
|
||||
@@ -44,13 +48,21 @@ export function useSubscriptionPaymentFlow({
|
||||
}, [payment.currentOrderId, payment.isPaid]);
|
||||
|
||||
const handleBackClick = () => {
|
||||
navigator.exitSubscription(returnTo, characterSlug);
|
||||
void (async () => {
|
||||
router.replace(
|
||||
await consumeSubscriptionExitUrl(returnTo, characterSlug),
|
||||
);
|
||||
})();
|
||||
};
|
||||
|
||||
const handlePaymentSuccessClose = () => {
|
||||
setShowPaymentSuccessDialog(false);
|
||||
paymentDispatch({ type: "PaymentReset" });
|
||||
navigator.exitSubscriptionAfterSuccess(returnTo, characterSlug);
|
||||
void (async () => {
|
||||
router.replace(
|
||||
await resolveSubscriptionSuccessExitUrl(returnTo, characterSlug),
|
||||
);
|
||||
})();
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user