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 { 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 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 (
<>
Contact admin
Bug reports, suggestions, channel requests,
and account questions.
{conversations.length} threads
{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 && (
No conversations yet.
)}
New conversation
Attach up to 3 files, 200 MB each.
>
);
}
SupportIndex.layout = {
breadcrumbs: [
{
title: 'Contact admin',
href: supportIndex(),
},
],
};
function Field({
label,
error,
children,
}: {
label: string;
error?: string;
children: ReactNode;
}) {
return (
);
}
function StatusBadge({ status }: { status: 'open' | 'closed' }) {
return (
{status === 'open' ? 'OPEN' : 'CLOSED'}
);
}