import { Head, Link, useForm } from '@inertiajs/react'; import { FileUp, LifeBuoy, MessageSquare, Send } from 'lucide-react'; import type { FormEvent, ReactNode } from 'react'; import { useRef } from 'react'; import { SupportAttachmentErrors } from '@/components/support-attachment-errors'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { useTranslation } from '@/lib/translations'; import { cn } from '@/lib/utils'; import { index as supportIndex, show as showConversation, store as storeConversation, } from '@/routes/support'; import type { SupportCategoryOption, SupportConversationSummary, } from '@/types'; type Props = { categories: SupportCategoryOption[]; conversations: SupportConversationSummary[]; }; export default function SupportIndex({ categories, conversations }: Props) { const fileInputRef = useRef(null); const { t } = useTranslation(); const form = useForm({ category: categories[0]?.value ?? 'bug', subject: '', body: '', attachments: [] as File[], }); function submit(event: FormEvent) { event.preventDefault(); form.post(storeConversation.url(), { forceFormData: true, preserveScroll: true, onSuccess: () => { form.reset(); if (fileInputRef.current) { fileInputRef.current.value = ''; } }, }); } function setAttachments(files: FileList | null) { form.setData('attachments', Array.from(files ?? []).slice(0, 3)); } return ( <>

{t('Contact admin')}

{t( 'Bug reports, suggestions, channel requests, and account questions.', )}

{t(':count threads', { count: conversations.length, })}
{conversations.map((conversation) => (
{conversation.category_label}
{conversation.subject}
{conversation.latest_message && (

{ conversation.latest_message .author.name } : {conversation.latest_message.body}

)}
{conversation.messages_count}
))} {conversations.length === 0 && (
{t('No conversations yet.')}
)}

{t('New conversation')}

{t('Attach up to 3 files, 200 MB each.')}

form.setData('subject', event.target.value) } maxLength={120} />