Compare commits
3 Commits
95b9f85a14
...
43de8a1323
| Author | SHA1 | Date | |
|---|---|---|---|
| 43de8a1323 | |||
| b216b53f2e | |||
| cf67b06fb9 |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 2.0 MiB After Width: | Height: | Size: 663 KiB |
|
Before Width: | Height: | Size: 2.1 MiB After Width: | Height: | Size: 468 KiB |
@@ -0,0 +1,14 @@
|
|||||||
|
import { renderToStaticMarkup } from "react-dom/server";
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
vi.mock("next/navigation", () => ({
|
||||||
|
useRouter: () => ({ replace: vi.fn() }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
import SubscriptionReturnPage from "../page";
|
||||||
|
|
||||||
|
describe("SubscriptionReturnPage", () => {
|
||||||
|
it("renders outside CharacterProvider", () => {
|
||||||
|
expect(() => renderToStaticMarkup(<SubscriptionReturnPage />)).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
import { MobileShell } from "@/app/_components/core";
|
import { MobileShell } from "@/app/_components/core";
|
||||||
import {
|
import {
|
||||||
@@ -8,12 +9,11 @@ import {
|
|||||||
getPendingPaymentOrder,
|
getPendingPaymentOrder,
|
||||||
} from "@/lib/payment/pending_payment_order";
|
} from "@/lib/payment/pending_payment_order";
|
||||||
import { ROUTES } from "@/router/routes";
|
import { ROUTES } from "@/router/routes";
|
||||||
import { useAppNavigator } from "@/router/use-app-navigator";
|
|
||||||
|
|
||||||
type ReturnStatus = "loading" | "missing";
|
type ReturnStatus = "loading" | "missing";
|
||||||
|
|
||||||
export default function SubscriptionReturnPage() {
|
export default function SubscriptionReturnPage() {
|
||||||
const navigator = useAppNavigator();
|
const router = useRouter();
|
||||||
const [status, setStatus] = useState<ReturnStatus>("loading");
|
const [status, setStatus] = useState<ReturnStatus>("loading");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -24,7 +24,7 @@ export default function SubscriptionReturnPage() {
|
|||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
|
|
||||||
if (result.success && result.data !== null) {
|
if (result.success && result.data !== null) {
|
||||||
navigator.replace(buildPendingPaymentSubscriptionUrl(result.data));
|
router.replace(buildPendingPaymentSubscriptionUrl(result.data));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ export default function SubscriptionReturnPage() {
|
|||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [navigator]);
|
}, [router]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MobileShell>
|
<MobileShell>
|
||||||
@@ -62,7 +62,7 @@ export default function SubscriptionReturnPage() {
|
|||||||
{status === "missing" ? (
|
{status === "missing" ? (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => navigator.replace(ROUTES.subscription)}
|
onClick={() => router.replace(ROUTES.subscription)}
|
||||||
style={{
|
style={{
|
||||||
marginTop: "0.5rem",
|
marginTop: "0.5rem",
|
||||||
padding: "0.75rem 1.5rem",
|
padding: "0.75rem 1.5rem",
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
import { usePaymentRouteFlow } from "@/app/_hooks/use-payment-route-flow";
|
import { usePaymentRouteFlow } from "@/app/_hooks/use-payment-route-flow";
|
||||||
import { useAppNavigator } from "@/router/use-app-navigator";
|
|
||||||
import type { PayChannel } from "@/data/schemas/payment";
|
import type { PayChannel } from "@/data/schemas/payment";
|
||||||
import { DEFAULT_CHARACTER_SLUG } from "@/data/constants/character";
|
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";
|
import type { SubscriptionType } from "./subscription-screen.helpers";
|
||||||
|
|
||||||
@@ -25,7 +29,7 @@ export function useSubscriptionPaymentFlow({
|
|||||||
initialPayChannel,
|
initialPayChannel,
|
||||||
characterSlug = DEFAULT_CHARACTER_SLUG,
|
characterSlug = DEFAULT_CHARACTER_SLUG,
|
||||||
}: UseSubscriptionPaymentFlowInput) {
|
}: UseSubscriptionPaymentFlowInput) {
|
||||||
const navigator = useAppNavigator();
|
const router = useRouter();
|
||||||
const { payment, paymentDispatch } = usePaymentRouteFlow({
|
const { payment, paymentDispatch } = usePaymentRouteFlow({
|
||||||
initialPayChannel,
|
initialPayChannel,
|
||||||
paymentType: subscriptionType,
|
paymentType: subscriptionType,
|
||||||
@@ -44,13 +48,21 @@ export function useSubscriptionPaymentFlow({
|
|||||||
}, [payment.currentOrderId, payment.isPaid]);
|
}, [payment.currentOrderId, payment.isPaid]);
|
||||||
|
|
||||||
const handleBackClick = () => {
|
const handleBackClick = () => {
|
||||||
navigator.exitSubscription(returnTo, characterSlug);
|
void (async () => {
|
||||||
|
router.replace(
|
||||||
|
await consumeSubscriptionExitUrl(returnTo, characterSlug),
|
||||||
|
);
|
||||||
|
})();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePaymentSuccessClose = () => {
|
const handlePaymentSuccessClose = () => {
|
||||||
setShowPaymentSuccessDialog(false);
|
setShowPaymentSuccessDialog(false);
|
||||||
paymentDispatch({ type: "PaymentReset" });
|
paymentDispatch({ type: "PaymentReset" });
|
||||||
navigator.exitSubscriptionAfterSuccess(returnTo, characterSlug);
|
void (async () => {
|
||||||
|
router.replace(
|
||||||
|
await resolveSubscriptionSuccessExitUrl(returnTo, characterSlug),
|
||||||
|
);
|
||||||
|
})();
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||