feat(orders): migrate orders to backend API
This commit is contained in:
@@ -7,13 +7,11 @@ import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import type { Actor } from "@/lib/actor"
|
||||
import { getPlayerById, getServiceById } from "@/lib/api"
|
||||
import { createPaidOrder } from "@/lib/api/orders"
|
||||
import { notifySuccess } from "@/lib/toast"
|
||||
import type { Player, PlayerService } from "@/lib/types"
|
||||
import { useRequireAuth } from "@/lib/use-require-auth"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { useOrderStore } from "@/store/orders"
|
||||
import { useWalletStore } from "@/store/wallet"
|
||||
import { ArrowLeft, CheckCircle, CreditCard, ShieldCheck } from "lucide-react"
|
||||
import Link from "next/link"
|
||||
@@ -24,7 +22,6 @@ export default function NewOrderPage() {
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams()
|
||||
const { requireAuth } = useRequireAuth()
|
||||
const createPaidOrder = useOrderStore((state) => state.createPaidOrder)
|
||||
const balance = useWalletStore((state) => state.balance)
|
||||
const serviceId = searchParams.get("serviceId")
|
||||
|
||||
@@ -234,34 +231,26 @@ export default function NewOrderPage() {
|
||||
disabled={balance < totalPrice}
|
||||
onClick={() =>
|
||||
requireAuth(() => {
|
||||
const authUser = useAuthStore.getState().user
|
||||
if (!authUser) return
|
||||
|
||||
const actor: Actor = {
|
||||
userId: authUser.id,
|
||||
role: "consumer",
|
||||
}
|
||||
|
||||
const result = createPaidOrder(
|
||||
{
|
||||
Promise.resolve(
|
||||
createPaidOrder({
|
||||
playerId: player.id,
|
||||
serviceId: service.id,
|
||||
shopId: player.shopId,
|
||||
quantity,
|
||||
note,
|
||||
},
|
||||
actor,
|
||||
)
|
||||
if (!result.decision.ok || !result.order) {
|
||||
return
|
||||
}
|
||||
const nextOrder = result.order
|
||||
}),
|
||||
).then((result) => {
|
||||
if (!result.decision.ok || !result.order) {
|
||||
return
|
||||
}
|
||||
const nextOrder = result.order
|
||||
|
||||
setSubmitted(true)
|
||||
notifySuccess("下单成功")
|
||||
setTimeout(() => {
|
||||
router.push(`/order/${nextOrder.id}`)
|
||||
}, 800)
|
||||
setSubmitted(true)
|
||||
notifySuccess("下单成功")
|
||||
setTimeout(() => {
|
||||
router.push(`/order/${nextOrder.id}`)
|
||||
}, 800)
|
||||
})
|
||||
})
|
||||
}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user