/opt/canhelp/apps/web/src/components
Edit: /opt/canhelp/apps/web/src/components/SupportModal.tsx (6195B)
'use client'
import { useState } from 'react'
import { useLocale } from '@/context/locale'
import { createSupportTicket } from '@/lib/api'
type TicketType = 'bug' | 'suggestion' | 'other'
interface Props {
onClose: () => void
}
export default function SupportModal({ onClose }: Props) {
const { t } = useLocale()
const [type, setType] = useState
('bug')
const [subject, setSubject] = useState('')
const [body, setBody] = useState('')
const [loading, setLoading] = useState(false)
const [sent, setSent] = useState(false)
const [error, setError] = useState('')
const TYPES: { value: TicketType; label: string; icon: string; color: string }[] = [
{ value: 'bug', label: t('support.type.bug'), icon: '🐛', color: 'border-red-300 bg-red-50 text-red-700' },
{ value: 'suggestion', label: t('support.type.suggestion'), icon: '💡', color: 'border-green-300 bg-green-50 text-green-700' },
{ value: 'other', label: t('support.type.other'), icon: '💬', color: 'border-gray-300 bg-gray-50 text-gray-700' },
]
async function handleSubmit(e: React.FormEvent) {
e.preventDefault()
setError('')
setLoading(true)
try {
await createSupportTicket({ type, subject, body })
setSent(true)
} catch {
setError(t('support.error'))
} finally {
setLoading(false)
}
}
return (
e.target === e.currentTarget && onClose()}
>
{/* Header */}
{sent ? (
/* Success state */
✅
{t('support.sent.title')}
{t('support.sent.body')}
) : (
)}
)
}