'use client'; import { Display } from '@/components/display'; import useGlobalStore from '@/config/use-global'; import { checkoutOrder, queryOrderDetail } from '@/services/user/order'; import { Icon } from '@iconify/react'; import { formatDate } from '@repo/ui/utils'; import { Badge } from '@shadcn/ui/badge'; import { Button } from '@shadcn/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@shadcn/ui/card'; import { addMinutes, format } from '@shadcn/ui/lib/date-fns'; import { Separator } from '@shadcn/ui/separator'; import { useQuery } from '@tanstack/react-query'; import { useCountDown } from 'ahooks'; import { useTranslations } from 'next-intl'; import Link from 'next/link'; import { QRCodeCanvas } from 'qrcode.react'; import { useEffect, useState } from 'react'; import { SubscribeBilling } from '../subscribe/billing'; import { SubscribeDetail } from '../subscribe/detail'; import StripePayment from './stripe'; export default function Page() { const t = useTranslations('order'); const { getUserInfo } = useGlobalStore(); const [order_no, setOrderNo] = useState(); const [enabled, setEnabled] = useState(false); const { data } = useQuery({ enabled: enabled, queryKey: ['queryOrderDetail', order_no], queryFn: async () => { const { data } = await queryOrderDetail({ order_no: order_no! }); if (data?.data?.status !== 1) { getUserInfo(); setEnabled(false); } return data?.data; }, refetchInterval: 3000, }); const { data: payment } = useQuery({ enabled: !!order_no && !!data?.status && data?.status !== 3, queryKey: ['checkoutOrder', order_no], queryFn: async () => { const { data } = await checkoutOrder({ orderNo: order_no! }); return data?.data; }, }); useEffect(() => { const searchParams = new URLSearchParams(location.search); if (searchParams.get('order_no')) { setOrderNo(searchParams.get('order_no')!); setEnabled(true); } }, []); const [countDown, formattedRes] = useCountDown({ targetDate: data && format(addMinutes(data?.created_at, 15), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx"), }); const { hours, minutes, seconds } = formattedRes; const countdownDisplay = countDown > 0 ? ( <> {hours.toString().length === 1 ? `0${hours}` : hours} :{' '} {minutes.toString().length === 1 ? `0${minutes}` : minutes} :{' '} {seconds.toString().length === 1 ? `0${seconds}` : seconds} ) : ( <>{t('timeExpired')} ); return (
{t('orderNumber')} {data?.orderNo} {t('createdAt')}: {formatDate(data?.created_at)}
{t('paymentMethod')}
{data?.method && {t(`methods.${data?.method}`)}}
{data?.type && [1, 2].includes(data.type) && ( )} {data?.type === 3 && ( <>
重置流量
  • 重置价格
)} {data?.type === 4 && ( <>
{t('balanceRecharge')}
  • {t('rechargeAmount')}
)}
{data?.status && [2, 5].includes(data?.status) && (

{t('paymentSuccess')}

)} {data?.status === 1 && payment?.type === 'link' && (

{t('waitingForPayment')}

{countdownDisplay}

)} {data?.status === 1 && payment?.type === 'qr' && (

{t('scanToPay')}

{countdownDisplay}

)} {data?.status === 1 && payment?.type === 'stripe' && (

{t('scanToPay')}

{countdownDisplay}

{payment.stripe && }
)} {data?.status && [3, 4].includes(data?.status) && (

{t('orderClosed')}

)}
); }