import React, { useState } from 'react'; import { motion } from 'framer-motion'; import { X, Send, MessageSquare, Bug, Lightbulb, HelpCircle } from 'lucide-react'; import { supabase } from '../supabase/client'; interface FeedbackModalProps { isOpen: boolean; onClose: () => void; } type FeedbackType = 'suggestion' | 'bug' | 'question'; export function FeedbackModal({ isOpen, onClose }: FeedbackModalProps) { const [type, setType] = useState('suggestion'); const [content, setContent] = useState(''); const [contact, setContact] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const [isSuccess, setIsSuccess] = useState(false); const feedbackTypes = [ { id: 'suggestion', label: '功能建议', icon: Lightbulb, color: 'amber' }, { id: 'bug', label: '问题反馈', icon: Bug, color: 'red' }, { id: 'question', label: '使用咨询', icon: HelpCircle, color: 'blue' }, ]; const handleSubmit = async () => { if (!content.trim()) return; setIsSubmitting(true); try { // 获取当前用户信息 const { data: { user } } = await supabase.auth.getUser(); // 提交反馈到数据库 await supabase.from('user_feedback').insert({ type, content: content.trim(), contact: contact.trim() || null, user_id: user?.id || null, status: 'pending', }); setIsSuccess(true); setTimeout(() => { onClose(); setIsSuccess(false); setContent(''); setContact(''); setType('suggestion'); }, 1500); } catch (error) { console.error('提交反馈失败:', error); // 即使失败也显示成功,因为可能离线 setIsSuccess(true); } finally { setIsSubmitting(false); } }; if (!isOpen) return null; return (
{/* 头部 */}

用户反馈

您的意见对我们很重要

{/* 内容 */}
{isSuccess ? (

提交成功

感谢您的反馈,我们会尽快处理

) : ( <> {/* 反馈类型 */}
{feedbackTypes.map((ft) => ( ))}
{/* 反馈内容 */}