refactor(payment): remove vip status flow

This commit is contained in:
2026-06-26 18:48:22 +08:00
parent e9fc001a6f
commit b6f18a1ef3
9 changed files with 46 additions and 176 deletions
+1 -70
View File
@@ -57,11 +57,8 @@ export function SubscriptionScreen({
const refreshedPaidOrderRef = useRef<string | null>(null);
const resumedPendingOrderRef = useRef<string | null>(null);
const successDialogShownOrderRef = useRef<string | null>(null);
const syncedVipOrderRef = useRef<string | null>(null);
const [showPaymentSuccessDialog, setShowPaymentSuccessDialog] =
useState(false);
const [pendingChatReturnAfterVipSync, setPendingChatReturnAfterVipSync] =
useState(false);
const isVipSubscription = subscriptionType === "vip";
useEffect(() => {
@@ -77,35 +74,6 @@ export function SubscriptionScreen({
userDispatch({ type: "UserFetch" });
}, [payment.currentOrderId, payment.isPaid, userDispatch]);
useEffect(() => {
const currentUser = user.currentUser;
const canMarkVipSynced =
subscriptionType === "vip" &&
payment.isPaid &&
payment.currentOrderId &&
payment.vipStatus?.isVip === true &&
currentUser &&
currentUser.isVip !== true;
if (!canMarkVipSynced) return;
if (syncedVipOrderRef.current === payment.currentOrderId) return;
syncedVipOrderRef.current = payment.currentOrderId;
userDispatch({
type: "UserUpdate",
user: {
...currentUser,
isVip: true,
},
});
}, [
payment.currentOrderId,
payment.isPaid,
payment.vipStatus?.isVip,
subscriptionType,
user.currentUser,
userDispatch,
]);
useEffect(() => {
if (!payment.isPaid || !payment.currentOrderId) return;
if (successDialogShownOrderRef.current === payment.currentOrderId) return;
@@ -200,8 +168,7 @@ export function SubscriptionScreen({
: plans.find((plan) => plan.id === payment.selectedPlanId)) ?? null;
const isPaymentBusy =
payment.isCreatingOrder ||
payment.isPollingOrder ||
payment.isCheckingVipStatus;
payment.isPollingOrder;
const canActivate =
selectedPlan !== null && payment.agreed && !isPaymentBusy;
@@ -217,7 +184,6 @@ export function SubscriptionScreen({
: "Choose a subscription plan";
const finishPaymentSuccessClose = () => {
setPendingChatReturnAfterVipSync(false);
setShowPaymentSuccessDialog(false);
paymentDispatch({ type: "PaymentReset" });
if (returnTo === "chat") {
@@ -226,44 +192,9 @@ export function SubscriptionScreen({
};
const handlePaymentSuccessClose = () => {
const shouldWaitForVipSync =
returnTo === "chat" &&
subscriptionType === "vip" &&
user.currentUser?.isVip !== true;
if (shouldWaitForVipSync) {
setPendingChatReturnAfterVipSync(true);
if (payment.vipStatus?.isVip === true && user.currentUser) {
userDispatch({
type: "UserUpdate",
user: {
...user.currentUser,
isVip: true,
},
});
} else {
userDispatch({ type: "UserFetch" });
}
return;
}
finishPaymentSuccessClose();
};
useEffect(() => {
if (!pendingChatReturnAfterVipSync) return;
if (subscriptionType === "vip" && user.currentUser?.isVip !== true) return;
const timer = window.setTimeout(() => {
finishPaymentSuccessClose();
}, 0);
return () => window.clearTimeout(timer);
// `finishPaymentSuccessClose` intentionally stays local to this component;
// this effect is gated by pendingChatReturnAfterVipSync to avoid repeated closes.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pendingChatReturnAfterVipSync, subscriptionType, user.currentUser?.isVip]);
useEffect(() => {
if (isVipSubscription) {
const firstVipPlanId = vipOfferPlans[0]?.id ?? "";