'use client' import { useState } from 'react' import { Header } from '@/components/header' import { Footer } from '@/components/footer' import { useAuth } from '@/contexts/AuthContext' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Textarea } from '@/components/ui/textarea' import { Button } from '@/components/ui/button' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Alert, AlertDescription } from '@/components/ui/alert' import { Switch } from '@/components/ui/switch' import { MessageSquare, AlertTriangle, Send, CheckCircle, AlertCircle } from 'lucide-react' export function FeedbackPageClient() { const { user } = useAuth() const [formType, setFormType] = useState<'suggestion' | 'report'>('suggestion') const [formData, setFormData] = useState({ name: user?.name || '', email: user?.email || '', title: '', details: '', category: 'general', urgency: 'low' }) const [errors, setErrors] = useState>({}) const [isSubmitting, setIsSubmitting] = useState(false) const [isSuccess, setIsSuccess] = useState(false) const categoryOptions = [ { value: 'general', label: 'General' }, { value: 'ui', label: 'User Interface' }, { value: 'performance', label: 'Performance' }, { value: 'feature', label: 'Feature Request' }, { value: 'technical', label: 'Technical Issue' }, { value: 'billing', label: 'Billing/Payment' }, { value: 'security', label: 'Security' }, { value: 'other', label: 'Other' } ] const urgencyOptions = [ { value: 'low', label: 'Low - Not urgent' }, { value: 'medium', label: 'Medium - Needs attention' }, { value: 'high', label: 'High - Impacts usage' }, { value: 'critical', label: 'Critical - Service unavailable' } ] const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsSubmitting(true) setErrors({}) // Client-side validation const newErrors: Record = {} if (!formData.name.trim()) newErrors.name = 'Please enter your name.' if (!formData.email.trim() || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) { newErrors.email = 'Please enter a valid email address.' } if (!formData.title.trim()) newErrors.title = `Please enter a title for your ${formType}.` if (!formData.details.trim()) newErrors.details = `Please provide details for your ${formType}.` if (Object.keys(newErrors).length > 0) { setErrors(newErrors) setIsSubmitting(false) return } try { const response = await fetch('/api/feedback', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ ...formData, type: formType, siliconId: user?.id || null }), }) const result = await response.json() if (response.ok && result.success) { setIsSuccess(true) setFormData({ name: user?.name || '', email: user?.email || '', title: '', details: '', category: 'general', urgency: 'low' }) setFormType('suggestion') } else { if (result.errors) { setErrors(result.errors) } else { setErrors({ submit: result.message || 'Error submitting form. Please try again.' }) } } } catch (error) { setErrors({ submit: 'Network error. Please try again.' }) } finally { setIsSubmitting(false) } } const handleInputChange = (field: string, value: string) => { setFormData(prev => ({ ...prev, [field]: value })) if (errors[field]) { setErrors(prev => ({ ...prev, [field]: '' })) } } const handleTypeToggle = (checked: boolean) => { setFormType(checked ? 'report' : 'suggestion') setIsSuccess(false) } return (
{/* Page Header */}

Suggestion or Report

We value your feedback! Use this form to submit suggestions or report any issues you've encountered.

{/* Success Message */} {isSuccess && ( {formType === 'suggestion' ? 'Thank you for your suggestion! We appreciate your feedback.' : 'Your report has been submitted. We will look into it as soon as possible.' } )} {/* Error Message */} {errors.submit && ( {errors.submit} )}
{/* Form Type Toggle */}
Suggestion
Report
{/* Name and Email */}
handleInputChange('name', e.target.value)} className={errors.name ? 'border-red-500' : ''} /> {errors.name && (

{errors.name}

)}
handleInputChange('email', e.target.value)} className={errors.email ? 'border-red-500' : ''} /> {errors.email && (

{errors.email}

)}
{/* Title */}
handleInputChange('title', e.target.value)} className={errors.title ? 'border-red-500' : ''} /> {errors.title && (

{errors.title}

)}
{/* Category and Urgency */}
{/* Urgency (only for reports) */} {formType === 'report' && (
)}
{/* Details */}