refactor(app): tighten feature boundaries
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
import { PendingPaymentOrderStorage } from "@/data/storage";
|
||||
import { savePendingEzpayOrder } from "@/lib/payment/pending_payment_order";
|
||||
import {
|
||||
usePaymentDispatch,
|
||||
usePaymentState,
|
||||
@@ -280,12 +280,10 @@ async function launchEzpayRedirect({
|
||||
return;
|
||||
}
|
||||
|
||||
const saveResult = await PendingPaymentOrderStorage.setPendingOrder({
|
||||
const saveResult = await savePendingEzpayOrder({
|
||||
orderId,
|
||||
payChannel: "ezpay",
|
||||
subscriptionType,
|
||||
...(returnTo ? { returnTo } : {}),
|
||||
createdAt: Date.now(),
|
||||
});
|
||||
if (Result.isErr(saveResult)) {
|
||||
const errorMessage =
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* - 头像右侧两行文本:用户名(16px/600)、副标题(12px/secondary)
|
||||
* - 无头像时显示默认用户图标
|
||||
*/
|
||||
import { UserMessageAvatar } from "@/app/chat/components/user-message-avatar";
|
||||
import { UserMessageAvatar } from "@/app/_components";
|
||||
|
||||
import styles from "./subscription-user-row.module.css";
|
||||
|
||||
|
||||
@@ -4,23 +4,14 @@ import { useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { MobileShell } from "@/app/_components/core";
|
||||
import { PendingPaymentOrderStorage } from "@/data/storage";
|
||||
import {
|
||||
buildPendingPaymentSubscriptionUrl,
|
||||
getPendingPaymentOrder,
|
||||
} from "@/lib/payment/pending_payment_order";
|
||||
import { ROUTES } from "@/router/routes";
|
||||
|
||||
type ReturnStatus = "loading" | "missing";
|
||||
|
||||
function buildSubscriptionUrl(
|
||||
subscriptionType: "vip" | "topup",
|
||||
returnTo?: "chat",
|
||||
): string {
|
||||
const params = new URLSearchParams({
|
||||
type: subscriptionType,
|
||||
paymentReturn: "1",
|
||||
});
|
||||
if (returnTo) params.set("returnTo", returnTo);
|
||||
return `${ROUTES.subscription}?${params.toString()}`;
|
||||
}
|
||||
|
||||
export default function SubscriptionReturnPage() {
|
||||
const router = useRouter();
|
||||
const [status, setStatus] = useState<ReturnStatus>("loading");
|
||||
@@ -29,16 +20,11 @@ export default function SubscriptionReturnPage() {
|
||||
let cancelled = false;
|
||||
|
||||
const redirectToSubscription = async () => {
|
||||
const result = await PendingPaymentOrderStorage.getPendingOrder();
|
||||
const result = await getPendingPaymentOrder();
|
||||
if (cancelled) return;
|
||||
|
||||
if (result.success && result.data !== null) {
|
||||
router.replace(
|
||||
buildSubscriptionUrl(
|
||||
result.data.subscriptionType,
|
||||
result.data.returnTo,
|
||||
),
|
||||
);
|
||||
router.replace(buildPendingPaymentSubscriptionUrl(result.data));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,13 @@ import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { BackButton } from "@/app/_components";
|
||||
import { consumePendingChatImageReturn } from "@/app/chat/chat-image-return-session";
|
||||
import { Checkbox, MobileShell } from "@/app/_components/core";
|
||||
import { AppConstants } from "@/core/app_constants";
|
||||
import { PendingPaymentOrderStorage } from "@/data/storage";
|
||||
import { consumePendingChatImageReturn } from "@/lib/navigation/chat_image_return_session";
|
||||
import {
|
||||
clearPendingPaymentOrder,
|
||||
getPendingPaymentOrderForType,
|
||||
} from "@/lib/payment/pending_payment_order";
|
||||
import {
|
||||
usePaymentDispatch,
|
||||
usePaymentState,
|
||||
@@ -85,13 +88,11 @@ export function SubscriptionScreen({
|
||||
let cancelled = false;
|
||||
|
||||
const handlePendingOrder = async () => {
|
||||
const result = await PendingPaymentOrderStorage.getPendingOrderForType(
|
||||
subscriptionType,
|
||||
);
|
||||
const result = await getPendingPaymentOrderForType(subscriptionType);
|
||||
if (cancelled || !result.success || result.data === null) return;
|
||||
|
||||
if (!shouldResumePendingOrder) {
|
||||
await PendingPaymentOrderStorage.clearPendingOrder();
|
||||
await clearPendingPaymentOrder();
|
||||
if (
|
||||
payment.currentOrderId === result.data.orderId &&
|
||||
(payment.isPollingOrder || payment.isPaid || payment.status === "failed")
|
||||
@@ -130,7 +131,7 @@ export function SubscriptionScreen({
|
||||
if (!payment.currentOrderId) return;
|
||||
if (!payment.isPaid && payment.status !== "failed") return;
|
||||
|
||||
void PendingPaymentOrderStorage.clearPendingOrder();
|
||||
void clearPendingPaymentOrder();
|
||||
}, [payment.currentOrderId, payment.isPaid, payment.status]);
|
||||
|
||||
const vipOfferPlans = useMemo(
|
||||
|
||||
Reference in New Issue
Block a user