"use client"; import { Loading } from "@/components/dashboard/loading"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTrigger, } from "@/components/ui/dialog"; import { toast } from "@/components/ui/toaster"; // import { trpc } from "@/lib/trpc/client"; // import { PostHogEvent } from "@/providers/PostHogProvider"; // import { type Workspace } from "@aigxion/db"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; import React, { useEffect, useState } from "react"; // import { getTenantId } from "@/lib/auth"; // import { db } from "@/lib/db"; import { ArrowLeft } from "lucide-react"; import Link from "next/link"; import { ChangePlanButton } from "./button"; import { PayInfo, PaymentInfo, PaymentOrder, payStaff, queryPayStatus, queryProductionList } from "@/lib/http/staff"; import { FadeIn } from "@/components/landing/fade-in"; import { cn } from "@/lib/utils"; import { Modal, QRCode, message } from "antd"; import Image from "next/image"; import { useTranslation } from "react-i18next"; type Props = { newPlan: "free" | "pro"; // workspace: Workspace; // tier: string; tiers: ProductInfo }; interface ProductInfoKey { [key: string]: ProductInfo; } interface ProductInfo { id: number; name: string; href: string; price: number | string; description: string; buttonText: string; features: string[]; footnotes: never[]; serial_no?: string; currency?: string; state?: number; language?: string; trial_days?: number; expiring_days?: number; pay_url?: string; is_inactive?: boolean; //如果是true就弹窗提示 is_deleted?: boolean; create_user?: string; edit_user?: string; created_time?: string; updated_time?: string; }; enum OrderStatus { WaitingForPayment = 0, PaymentCompleted = 1, PaymentTimeoutClosed = 2, Refunded = 3, EndedNonRefundable = 4, PaymentPlatformException = 5 } function getOrderStatusString(status: OrderStatus): string { switch (status) { case OrderStatus.WaitingForPayment: return '等待付款'; case OrderStatus.PaymentCompleted: return '已完成付款'; case OrderStatus.PaymentTimeoutClosed: return '付款超时关闭'; case OrderStatus.Refunded: return '已退款'; case OrderStatus.EndedNonRefundable: return '已结束[不可退款]'; case OrderStatus.PaymentPlatformException: return '支付平台异常'; default: return ''; } } export const PlanCard: React.FC = ({ newPlan = "free", tiers }) => { const router = useRouter(); const [open, setOpen] = useState(false); console.log("----PlanCard----", tiers) const [isLoading, setIsLoading] = useState(false); const [payQrcode, setPayQrcode] = useState(""); const path = usePathname() const { t, i18n } = useTranslation() const searchParams = useSearchParams() const staffId = searchParams.get('staffId') console.log("---PlanCard----", staffId, path) const isChatPage = path.includes('chat') // const changePlan = trpc.workspace.changePlan.useMutation({ // onSuccess: (data, variables, _context) => { // toast.success(data.title, { // description: data.message, // }); // PostHogEvent({ // name: "plan_changed", // properties: { plan: variables.plan, workspace: variables.workspaceId }, // }); // setOpen(false); // router.refresh(); // }, // onError: (error) => { // toast.error(error.message); // }, // }); async function pollOrder(orderId: string, interval: number, maxAttempts: number): Promise { let attempts = 0; console.log("开始轮训订单", orderId) const poll = async (): Promise => { try { // 发送订单查询请求,假设返回的数据结构为 Order const result = await queryPayStatus(orderId); const order = result.data as PaymentOrder; console.log("---pollOrder------", order, attempts) //支付状态(0=等待付款 1=已完成付款 2=付款超时关闭 3=已退款 4=已结束[不可退款] 5=支付平台异常) // 如果订单状态为已完成,或者达到最大尝试次数,则停止轮询并返回订单 if (order.state >= 2 || attempts >= maxAttempts) { message.warning(getOrderStatusString(order.state)) router.push(`/manage/staffs`) return order; } else if (order.state == 1) { message.warning(getOrderStatusString(order.state)) router.push(`/manage/staffs`) return order; } // 增加尝试次数 attempts++; // 等待一段时间后继续轮询 await new Promise(resolve => setTimeout(resolve, interval)); // 递归调用自身,继续轮询 return poll(); } catch (error) { // 处理轮询过程中的错误 console.error("Error occurred while polling order:", error); return null; } }; return poll(); } const isSamePlan = true; return (

{tiers.name}

{/*

{tiers.description}

*/}

{typeof tiers.price === "number" ? ( <> {`${tiers.price}`} {"/month"} ) : ( <> {tiers.price} /{tiers.expiring_days}天 )}

    {tiers.features.map((feature) => (
  • {feature}
  • ))}
{tiers.footnotes && (
    {tiers.footnotes.map((footnote, i) => (
  • {footnote}
  • ))}
)} {/* {tier === "custom" ? ( ) : ( )} */} {/* */} { (staffId && !tiers.is_inactive) ? : }
{ if (setOpen) { setOpen(false) } }} onCancel={() => { setOpen(false) setIsLoading(false) }} footer="" // width={"50%"} className={cn('min-w-[95%] lg:min-w-[700px] p-[20px]', "")} >

请使用支付宝进行支付

{/*
*/} {payQrcode &&
{/*
Hero Image
*/} {/*
Hero Image
*/}
}
); }; export const PlanCardView: React.FC = () => { const [tiers, setTiers] = useState([ { id: 1, name: "月度计划", href: "/manage", price: 299, description: "启动下一个 API 所需的一切!", buttonText: "基础", features: [ // "100 个每月活动密钥", // "每月 2500 次成功验证", "无限的API", "7天免费保留", ], footnotes: [], }, { id: 2, name: "季度计划", href: "/manage", price: 699, description: "对于那些有团队和更苛刻需求的人", buttonText: "Pro", features: [ // "250 每月 xxxxxxxx*", // "150,000 成功 xxxxxxx 包括 **", // "xxxxxxxx APIs", "与团队成员的工作空间", "90 天分析保留", "90 天审核日志保留", ], footnotes: [ // " * Additional active keys are billed at $0.10", // " ** Additional verifications are billed at $10 per 100,000", ], }, { id: 3, name: "年度计划", href: "/manage", price: 1299, description: "我们为有批量需求的人提供定制定价", buttonText: "Go", features: [ // "自定义验证限制", // "自定义活动键限制", "自定义分析保留", "专用支持合同", "每个API的白名单IP", ], footnotes: [], }, ]); const [clientReady, setClientReady] = useState(false); useEffect(() => { async function initFunc() { const result = await queryProductionList() console.log(result) let newTiers = result.data.list as ProductInfo[] // 使用map方法更新原来的数组 const updatedTiers = tiers.map(originalTier => { const newTier = newTiers.find(newTier => newTier.id === originalTier.id); if (newTier) { newTier.features = newTier.description.split('\n') } return newTier ? { ...originalTier, ...newTier } : originalTier; }); // 更新状态 setTiers(updatedTiers); setClientReady(true) } initFunc() }, []); return ( <> {clientReady &&
{tiers.map((tier) => ())}
} ); };