"use client" import type React from "react" import { useState } from "react" import { useAuth } from "@/contexts/auth-context" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Textarea } from "@/components/ui/textarea" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Switch } from "@/components/ui/switch" import { Badge } from "@/components/ui/badge" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Separator } from "@/components/ui/separator" import { Upload, FileText, Link, CheckCircle, Clock, Info, Lightbulb, Target, Zap, AlertTriangle, FileVideo, X, } from "lucide-react" interface AppSubmissionDialogProps { open: boolean onOpenChange: (open: boolean) => void } export function AppSubmissionDialog({ open, onOpenChange }: AppSubmissionDialogProps) { const { user, canSubmitApp } = useAuth() const [step, setStep] = useState(1) const [isSubmitting, setIsSubmitting] = useState(false) const [isSubmitted, setIsSubmitted] = useState(false) const [formData, setFormData] = useState({ name: "", type: "文字處理", description: "", appUrl: "", demoFile: null as File | null, sourceCodeUrl: "", documentation: "", features: "", technicalDetails: "", requestFeatured: false, agreeTerms: false, }) // 檢查用戶權限 if (!user || !canSubmitApp()) { return ( 權限不足 您目前沒有提交應用的權限

需要開發者權限

只有開發者角色可以提交 AI 應用申請。您目前是{user?.role === "admin" ? "管理員" : "一般用戶"}身份。

如何獲得開發者權限?

  • • 聯繫管理員申請角色升級
  • • 說明您的開發背景和需求
  • • 等待管理員審核和調整
) } const handleInputChange = (field: string, value: string | boolean | File | null) => { setFormData((prev) => ({ ...prev, [field]: value })) } const handleFileChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0] || null handleInputChange("demoFile", file) } const removeFile = () => { handleInputChange("demoFile", null) } const handleNext = () => { if (step < 3) { setStep(step + 1) } } const handlePrevious = () => { if (step > 1) { setStep(step - 1) } } const handleSubmit = async () => { if (!user) { console.error('用戶未登入') return } setIsSubmitting(true) try { // 準備應用程式資料 const appData = { name: formData.name, description: formData.description, type: mapTypeToApiType(formData.type), demoUrl: formData.appUrl || undefined, githubUrl: formData.sourceCodeUrl || undefined, docsUrl: formData.documentation || undefined, techStack: formData.technicalDetails ? [formData.technicalDetails] : undefined, tags: formData.features ? [formData.features] : undefined, version: '1.0.0' } // 調用 API 創建應用程式 const token = localStorage.getItem('token') const response = await fetch('/api/apps', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }, body: JSON.stringify(appData) }) if (!response.ok) { const errorData = await response.json() throw new Error(errorData.error || '創建應用程式失敗') } const result = await response.json() console.log('應用程式創建成功:', result) setIsSubmitting(false) setIsSubmitted(true) // 3秒後關閉對話框 setTimeout(() => { onOpenChange(false) setIsSubmitted(false) setStep(1) setFormData({ name: "", type: "文字處理", description: "", appUrl: "", demoFile: null, sourceCodeUrl: "", documentation: "", features: "", technicalDetails: "", requestFeatured: false, agreeTerms: false, }) }, 3000) } catch (error) { console.error('創建應用程式失敗:', error) setIsSubmitting(false) // 這裡可以添加錯誤提示 alert(`創建應用程式失敗: ${error instanceof Error ? error.message : '未知錯誤'}`) } } // 將前端類型映射到 API 類型 const mapTypeToApiType = (frontendType: string): string => { const typeMap: Record = { '文字處理': 'productivity', '圖像生成': 'ai_model', '圖像處理': 'ai_model', '語音辨識': 'ai_model', '推薦系統': 'ai_model', '音樂生成': 'ai_model', '程式開發': 'automation', '影像處理': 'ai_model', '對話系統': 'ai_model', '數據分析': 'data_analysis', '設計工具': 'productivity', '語音技術': 'ai_model', '教育工具': 'educational', '健康醫療': 'healthcare', '金融科技': 'finance', '物聯網': 'iot_device', '區塊鏈': 'blockchain', 'AR/VR': 'ar_vr', '機器學習': 'machine_learning', '電腦視覺': 'computer_vision', '自然語言處理': 'nlp', '機器人': 'robotics', '網路安全': 'cybersecurity', '雲端服務': 'cloud_service', '其他': 'other' } return typeMap[frontendType] || 'other' } const isStep1Valid = formData.name && formData.description && formData.appUrl const isStep2Valid = formData.features const isStep3Valid = formData.agreeTerms if (isSubmitted) { return (

提交成功!

您的應用申請已成功提交,我們將在 1-3 個工作日內完成審核。

後續流程

  • • 管理員將審核您的應用
  • • 審核結果將透過電子郵件通知
  • • 通過審核後應用將上線展示

此對話框將自動關閉...

) } return ( 提交 AI 應用申請 分享您的 AI 創新成果,讓更多人體驗您的應用 {/* Progress Indicator */}
{[1, 2, 3].map((stepNumber) => (
= stepNumber ? "bg-blue-600 text-white" : "bg-gray-200 text-gray-600" }`} > {stepNumber}
{stepNumber < 3 && (
stepNumber ? "bg-blue-600" : "bg-gray-200"}`} /> )}
))}
{/* Main Form */}
{step === 1 && ( 基本資訊 請填寫您的 AI 應用基本資訊
handleInputChange("name", e.target.value)} placeholder="輸入您的應用名稱" />