feat(orders): 缩短选号到支付链路并对齐旧站逻辑
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import {
|
||||
Alert,
|
||||
App,
|
||||
@@ -58,15 +58,23 @@ interface ActionFormValues {
|
||||
interface OrderActionPanelProps {
|
||||
order: UserOrderDetail
|
||||
onChanged: () => void | Promise<void>
|
||||
autoPay?: boolean
|
||||
onAutoPayHandled?: () => void
|
||||
}
|
||||
|
||||
export function OrderActionPanel({ order, onChanged }: OrderActionPanelProps) {
|
||||
export function OrderActionPanel({
|
||||
order,
|
||||
onChanged,
|
||||
autoPay = false,
|
||||
onAutoPayHandled,
|
||||
}: OrderActionPanelProps) {
|
||||
const { message, modal } = App.useApp()
|
||||
const [form] = Form.useForm<ActionFormValues>()
|
||||
const user = useSessionStore(state => state.user)
|
||||
const [dialog, setDialog] = useState<DialogKind>(null)
|
||||
const [busy, setBusy] = useState<string | null>(null)
|
||||
const [payURL, setPayURL] = useState('')
|
||||
const autoPayTriggered = useRef(false)
|
||||
const actions = getOrderActionAvailability(order, user?.id)
|
||||
const checkout = order.checkout
|
||||
|
||||
@@ -127,6 +135,14 @@ export function OrderActionPanel({ order, onChanged }: OrderActionPanelProps) {
|
||||
setDialog(kind)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoPay || autoPayTriggered.current || !actions.canPay) return
|
||||
autoPayTriggered.current = true
|
||||
openDialog('pay')
|
||||
onAutoPayHandled?.()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [autoPay, actions.canPay])
|
||||
|
||||
const run = async (key: string, fn: () => Promise<void>) => {
|
||||
setBusy(key)
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user