Implemented the authenticated admin contact system.
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
import { Link, usePage } from '@inertiajs/react';
|
||||
import { LayoutGrid, Menu, Radio, Search, Shield } from 'lucide-react';
|
||||
import {
|
||||
LayoutGrid,
|
||||
LifeBuoy,
|
||||
Menu,
|
||||
Radio,
|
||||
Search,
|
||||
Shield,
|
||||
} from 'lucide-react';
|
||||
import AppLogo from '@/components/app-logo';
|
||||
import AppLogoIcon from '@/components/app-logo-icon';
|
||||
import { Breadcrumbs } from '@/components/breadcrumbs';
|
||||
@@ -34,6 +41,8 @@ import { useInitials } from '@/hooks/use-initials';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { dashboard, home } from '@/routes';
|
||||
import { dashboard as adminDashboard } from '@/routes/admin';
|
||||
import { index as adminSupportIndex } from '@/routes/admin/support';
|
||||
import { index as supportIndex } from '@/routes/support';
|
||||
import type { BreadcrumbItem, NavItem } from '@/types';
|
||||
|
||||
type Props = {
|
||||
@@ -58,6 +67,11 @@ export function AppHeader({ breadcrumbs = [] }: Props) {
|
||||
href: dashboard(),
|
||||
icon: LayoutGrid,
|
||||
},
|
||||
{
|
||||
title: 'Contact',
|
||||
href: supportIndex(),
|
||||
icon: LifeBuoy,
|
||||
},
|
||||
];
|
||||
|
||||
if (auth.user?.is_admin) {
|
||||
@@ -66,6 +80,11 @@ export function AppHeader({ breadcrumbs = [] }: Props) {
|
||||
href: adminDashboard(),
|
||||
icon: Shield,
|
||||
});
|
||||
mainNavItems.push({
|
||||
title: 'Support',
|
||||
href: adminSupportIndex(),
|
||||
icon: LifeBuoy,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Link, usePage } from '@inertiajs/react';
|
||||
import { LayoutGrid, Radio, Shield } from 'lucide-react';
|
||||
import { LayoutGrid, LifeBuoy, Radio, Shield } from 'lucide-react';
|
||||
import AppLogo from '@/components/app-logo';
|
||||
import { NavMain } from '@/components/nav-main';
|
||||
import { NavUser } from '@/components/nav-user';
|
||||
@@ -14,6 +14,8 @@ import {
|
||||
} from '@/components/ui/sidebar';
|
||||
import { dashboard, home } from '@/routes';
|
||||
import { dashboard as adminDashboard } from '@/routes/admin';
|
||||
import { index as adminSupportIndex } from '@/routes/admin/support';
|
||||
import { index as supportIndex } from '@/routes/support';
|
||||
import type { NavItem } from '@/types';
|
||||
|
||||
export function AppSidebar() {
|
||||
@@ -29,6 +31,11 @@ export function AppSidebar() {
|
||||
href: dashboard(),
|
||||
icon: LayoutGrid,
|
||||
},
|
||||
{
|
||||
title: 'Contact',
|
||||
href: supportIndex(),
|
||||
icon: LifeBuoy,
|
||||
},
|
||||
];
|
||||
|
||||
if (auth.user?.is_admin) {
|
||||
@@ -37,6 +44,11 @@ export function AppSidebar() {
|
||||
href: adminDashboard(),
|
||||
icon: Shield,
|
||||
});
|
||||
mainNavItems.push({
|
||||
title: 'Support',
|
||||
href: adminSupportIndex(),
|
||||
icon: LifeBuoy,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
140
resources/js/pages/admin/support/index.tsx
Normal file
140
resources/js/pages/admin/support/index.tsx
Normal file
@@ -0,0 +1,140 @@
|
||||
import { Head, Link } from '@inertiajs/react';
|
||||
import { Inbox, MessageSquare, Shield, User } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import {
|
||||
index as adminSupportIndex,
|
||||
show as showAdminSupport,
|
||||
} from '@/routes/admin/support';
|
||||
import type { SupportConversationSummary } from '@/types';
|
||||
|
||||
type Props = {
|
||||
stats: {
|
||||
open: number;
|
||||
closed: number;
|
||||
};
|
||||
conversations: SupportConversationSummary[];
|
||||
};
|
||||
|
||||
export default function AdminSupportIndex({ stats, conversations }: Props) {
|
||||
return (
|
||||
<>
|
||||
<Head title="Support inbox" />
|
||||
<div className="grid gap-6 p-4 md:p-6">
|
||||
<div className="flex flex-col gap-4 rounded-md border bg-card p-5 md:flex-row md:items-center md:justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="flex size-10 items-center justify-center rounded-md bg-primary text-primary-foreground">
|
||||
<Inbox className="size-5" />
|
||||
</span>
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">
|
||||
Support inbox
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Contact threads from users and channel request
|
||||
notes.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2 text-sm">
|
||||
<Stat label="Open" value={stats.open} />
|
||||
<Stat label="Closed" value={stats.closed} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section className="rounded-md border bg-card p-5 shadow-sm">
|
||||
<div className="mb-4 flex items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Shield className="size-5 text-primary" />
|
||||
<h2 className="font-semibold">Conversations</h2>
|
||||
</div>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{conversations.length} rows
|
||||
</span>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
{conversations.map((conversation) => (
|
||||
<Link
|
||||
key={conversation.id}
|
||||
href={showAdminSupport(conversation.id)}
|
||||
className="grid gap-3 rounded-md border bg-background p-3 transition hover:border-primary/50 md:grid-cols-[minmax(0,1fr)_auto]"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<StatusBadge
|
||||
status={conversation.status}
|
||||
/>
|
||||
<span className="rounded-md border px-2 py-0.5 text-xs text-muted-foreground">
|
||||
{conversation.category_label}
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-2 truncate font-medium">
|
||||
{conversation.subject}
|
||||
</div>
|
||||
<div className="mt-1 flex min-w-0 items-center gap-2 text-sm text-muted-foreground">
|
||||
<User className="size-4 shrink-0" />
|
||||
<span className="truncate">
|
||||
{conversation.user?.name} -{' '}
|
||||
{conversation.user?.email}
|
||||
</span>
|
||||
</div>
|
||||
{conversation.latest_message && (
|
||||
<p className="mt-2 line-clamp-2 text-sm text-muted-foreground">
|
||||
{
|
||||
conversation.latest_message
|
||||
.author.name
|
||||
}
|
||||
: {conversation.latest_message.body}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground md:justify-end">
|
||||
<MessageSquare className="size-4" />
|
||||
{conversation.messages_count}
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
|
||||
{conversations.length === 0 && (
|
||||
<div className="rounded-md border border-dashed bg-background p-6 text-sm text-muted-foreground">
|
||||
No support conversations found.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
AdminSupportIndex.layout = {
|
||||
breadcrumbs: [
|
||||
{
|
||||
title: 'Support inbox',
|
||||
href: adminSupportIndex(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
function Stat({ label, value }: { label: string; value: number }) {
|
||||
return (
|
||||
<div className="rounded-md border bg-background px-3 py-2">
|
||||
<span className="text-muted-foreground">{label}</span>{' '}
|
||||
<span className="font-semibold">{value}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StatusBadge({ status }: { status: 'open' | 'closed' }) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
'rounded-md border px-2 py-0.5 text-xs font-medium',
|
||||
status === 'open'
|
||||
? 'border-success/40 bg-success/10 text-success'
|
||||
: 'text-muted-foreground',
|
||||
)}
|
||||
>
|
||||
{status === 'open' ? 'OPEN' : 'CLOSED'}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
378
resources/js/pages/admin/support/show.tsx
Normal file
378
resources/js/pages/admin/support/show.tsx
Normal file
@@ -0,0 +1,378 @@
|
||||
import { Head, Link, router, useForm } from '@inertiajs/react';
|
||||
import {
|
||||
ArrowLeft,
|
||||
FileDown,
|
||||
FileUp,
|
||||
KeyRound,
|
||||
Lock,
|
||||
Send,
|
||||
Unlock,
|
||||
User,
|
||||
} from 'lucide-react';
|
||||
import type { FormEvent, ReactNode } from 'react';
|
||||
import { useRef } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { dashboard as adminDashboard } from '@/routes/admin';
|
||||
import {
|
||||
index as adminSupportIndex,
|
||||
update as updateConversation,
|
||||
} from '@/routes/admin/support';
|
||||
import { store as storeAdminMessage } from '@/routes/admin/support/messages';
|
||||
import { show as showChannel } from '@/routes/channels';
|
||||
import { show as showAttachment } from '@/routes/support/attachments';
|
||||
import type {
|
||||
SupportAttachment,
|
||||
SupportConversation,
|
||||
SupportMessage,
|
||||
} from '@/types';
|
||||
|
||||
type Props = {
|
||||
conversation: SupportConversation;
|
||||
};
|
||||
|
||||
export default function AdminSupportShow({ conversation }: Props) {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const form = useForm({
|
||||
body: '',
|
||||
attachments: [] as File[],
|
||||
});
|
||||
const isClosed = conversation.status === 'closed';
|
||||
|
||||
function submit(event: FormEvent) {
|
||||
event.preventDefault();
|
||||
|
||||
form.post(storeAdminMessage.url(conversation.id), {
|
||||
forceFormData: true,
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = '';
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function setStatus(status: 'open' | 'closed') {
|
||||
router.patch(
|
||||
updateConversation(conversation.id),
|
||||
{ status },
|
||||
{ preserveScroll: true },
|
||||
);
|
||||
}
|
||||
|
||||
function setAttachments(files: FileList | null) {
|
||||
form.setData('attachments', Array.from(files ?? []).slice(0, 3));
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head title={conversation.subject} />
|
||||
<div className="grid gap-6 p-4 md:p-6 xl:grid-cols-[minmax(0,1fr)_340px]">
|
||||
<div className="grid min-w-0 gap-6">
|
||||
<div className="rounded-md border bg-card p-5 shadow-sm">
|
||||
<Button
|
||||
asChild
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="mb-4"
|
||||
>
|
||||
<Link href={adminSupportIndex()}>
|
||||
<ArrowLeft className="size-4" />
|
||||
Support inbox
|
||||
</Link>
|
||||
</Button>
|
||||
<div className="flex flex-col gap-3 md:flex-row md:items-start md:justify-between">
|
||||
<div className="min-w-0">
|
||||
<div className="mb-2 flex flex-wrap items-center gap-2">
|
||||
<StatusBadge status={conversation.status} />
|
||||
<span className="rounded-md border px-2 py-0.5 text-xs text-muted-foreground">
|
||||
{conversation.category_label}
|
||||
</span>
|
||||
</div>
|
||||
<h1 className="text-2xl font-semibold break-words">
|
||||
{conversation.subject}
|
||||
</h1>
|
||||
</div>
|
||||
<Button
|
||||
variant={isClosed ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
setStatus(isClosed ? 'open' : 'closed')
|
||||
}
|
||||
>
|
||||
{isClosed ? (
|
||||
<Unlock className="size-4" />
|
||||
) : (
|
||||
<Lock className="size-4" />
|
||||
)}
|
||||
{isClosed ? 'Reopen' : 'Close'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section className="grid gap-3">
|
||||
{conversation.messages.map((message) => (
|
||||
<MessageBubble key={message.id} message={message} />
|
||||
))}
|
||||
</section>
|
||||
|
||||
<section className="rounded-md border bg-card p-5 shadow-sm">
|
||||
{isClosed ? (
|
||||
<div className="flex items-start gap-3 rounded-md border border-dashed bg-background p-4 text-sm text-muted-foreground">
|
||||
<Lock className="mt-0.5 size-4 shrink-0" />
|
||||
<span>Reopen the conversation to reply.</span>
|
||||
</div>
|
||||
) : (
|
||||
<form onSubmit={submit} className="grid gap-4">
|
||||
<Field label="Reply" error={form.errors.body}>
|
||||
<textarea
|
||||
value={form.data.body}
|
||||
onChange={(event) =>
|
||||
form.setData(
|
||||
'body',
|
||||
event.target.value,
|
||||
)
|
||||
}
|
||||
className="min-h-32 rounded-md border bg-background px-3 py-2 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50"
|
||||
maxLength={2000}
|
||||
/>
|
||||
</Field>
|
||||
<Field
|
||||
label="Attachments"
|
||||
error={form.errors.attachments}
|
||||
>
|
||||
<Input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
multiple
|
||||
onChange={(event) =>
|
||||
setAttachments(event.target.files)
|
||||
}
|
||||
/>
|
||||
{form.data.attachments.length > 0 && (
|
||||
<div className="grid gap-1 text-xs text-muted-foreground">
|
||||
{form.data.attachments.map(
|
||||
(file) => (
|
||||
<span
|
||||
key={`${file.name}-${file.size}`}
|
||||
className="flex min-w-0 items-center gap-2"
|
||||
>
|
||||
<FileUp className="size-3.5 shrink-0" />
|
||||
<span className="truncate">
|
||||
{file.name}
|
||||
</span>
|
||||
</span>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{form.progress && (
|
||||
<progress
|
||||
value={form.progress.percentage}
|
||||
max="100"
|
||||
className="h-1.5 w-full"
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={form.processing}
|
||||
className="w-fit"
|
||||
>
|
||||
<Send className="size-4" />
|
||||
Send reply
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<aside className="grid content-start gap-6">
|
||||
<section className="rounded-md border bg-card p-5 shadow-sm">
|
||||
<div className="mb-4 flex items-center gap-2">
|
||||
<User className="size-5 text-primary" />
|
||||
<h2 className="font-semibold">User</h2>
|
||||
</div>
|
||||
<div className="grid gap-3 text-sm">
|
||||
<div>
|
||||
<div className="font-medium">
|
||||
{conversation.user?.name}
|
||||
</div>
|
||||
<div className="text-muted-foreground">
|
||||
{conversation.user?.email}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<span
|
||||
className={cn(
|
||||
'rounded-md border px-2 py-0.5 text-xs font-medium',
|
||||
conversation.user?.can_create_channel
|
||||
? 'border-success/40 bg-success/10 text-success'
|
||||
: 'text-muted-foreground',
|
||||
)}
|
||||
>
|
||||
{conversation.user?.can_create_channel
|
||||
? 'CAN CREATE CHANNEL'
|
||||
: 'NEEDS CHANNEL GRANT'}
|
||||
</span>
|
||||
{conversation.user?.suspended_at && (
|
||||
<span className="rounded-md border border-destructive/40 bg-destructive/10 px-2 py-0.5 text-xs font-medium text-destructive">
|
||||
SUSPENDED
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{conversation.user?.channel && (
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<Link
|
||||
href={showChannel(
|
||||
conversation.user.channel.slug,
|
||||
)}
|
||||
>
|
||||
Open channel
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{conversation.category === 'channel_request' && (
|
||||
<section className="rounded-md border bg-card p-5 shadow-sm">
|
||||
<div className="mb-3 flex items-center gap-2">
|
||||
<KeyRound className="size-5 text-primary" />
|
||||
<h2 className="font-semibold">
|
||||
Channel request
|
||||
</h2>
|
||||
</div>
|
||||
<p className="mb-4 text-sm text-muted-foreground">
|
||||
Creator access grants stay in the moderation
|
||||
console.
|
||||
</p>
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<Link href={adminDashboard()}>
|
||||
Open moderation
|
||||
</Link>
|
||||
</Button>
|
||||
</section>
|
||||
)}
|
||||
</aside>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
AdminSupportShow.layout = {
|
||||
breadcrumbs: [
|
||||
{
|
||||
title: 'Support inbox',
|
||||
href: adminSupportIndex(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
function MessageBubble({ message }: { message: SupportMessage }) {
|
||||
const isAdmin = message.author.is_admin;
|
||||
|
||||
return (
|
||||
<article
|
||||
className={cn(
|
||||
'grid max-w-3xl gap-3 rounded-md border bg-card p-4 shadow-sm',
|
||||
isAdmin && 'justify-self-end border-primary/30',
|
||||
)}
|
||||
>
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||
<span className="font-medium">{message.author.name}</span>
|
||||
<span className="rounded-md border px-2 py-0.5 text-xs text-muted-foreground">
|
||||
{isAdmin ? 'ADMIN' : 'USER'}
|
||||
</span>
|
||||
{message.created_at && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{formatDateTime(message.created_at)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm leading-6 break-words whitespace-pre-wrap">
|
||||
{message.body}
|
||||
</p>
|
||||
{message.attachments && message.attachments.length > 0 && (
|
||||
<AttachmentList attachments={message.attachments} />
|
||||
)}
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
function AttachmentList({ attachments }: { attachments: SupportAttachment[] }) {
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{attachments.map((attachment) => (
|
||||
<a
|
||||
key={attachment.id}
|
||||
href={showAttachment.url(attachment.id)}
|
||||
className="inline-flex max-w-full items-center gap-2 rounded-md border bg-background px-2 py-1 text-xs hover:bg-accent hover:text-accent-foreground"
|
||||
>
|
||||
<FileDown className="size-3.5 shrink-0" />
|
||||
<span className="truncate">{attachment.original_name}</span>
|
||||
<span className="shrink-0 text-muted-foreground">
|
||||
{formatBytes(attachment.size)}
|
||||
</span>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Field({
|
||||
label,
|
||||
error,
|
||||
children,
|
||||
}: {
|
||||
label: string;
|
||||
error?: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<label className="grid gap-2">
|
||||
<Label>{label}</Label>
|
||||
{children}
|
||||
{error && <span className="text-sm text-destructive">{error}</span>}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
function StatusBadge({ status }: { status: 'open' | 'closed' }) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
'rounded-md border px-2 py-0.5 text-xs font-medium',
|
||||
status === 'open'
|
||||
? 'border-success/40 bg-success/10 text-success'
|
||||
: 'text-muted-foreground',
|
||||
)}
|
||||
>
|
||||
{status === 'open' ? 'OPEN' : 'CLOSED'}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function formatDateTime(value: string): string {
|
||||
return new Date(value).toLocaleString([], {
|
||||
dateStyle: 'medium',
|
||||
timeStyle: 'short',
|
||||
});
|
||||
}
|
||||
|
||||
function formatBytes(value: number): string {
|
||||
if (value < 1024) {
|
||||
return `${value} B`;
|
||||
}
|
||||
|
||||
if (value < 1024 * 1024) {
|
||||
return `${Math.round(value / 102.4) / 10} KB`;
|
||||
}
|
||||
|
||||
return `${Math.round(value / 1024 / 102.4) / 10} MB`;
|
||||
}
|
||||
253
resources/js/pages/support/index.tsx
Normal file
253
resources/js/pages/support/index.tsx
Normal file
@@ -0,0 +1,253 @@
|
||||
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 { 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<HTMLInputElement>(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 (
|
||||
<>
|
||||
<Head title="Contact admin" />
|
||||
<div className="grid gap-6 p-4 md:p-6 xl:grid-cols-[minmax(0,1fr)_420px]">
|
||||
<section className="grid content-start gap-4">
|
||||
<div className="flex flex-col gap-4 rounded-md border bg-card p-5 md:flex-row md:items-center md:justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="flex size-10 items-center justify-center rounded-md bg-primary text-primary-foreground">
|
||||
<LifeBuoy className="size-5" />
|
||||
</span>
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">
|
||||
Contact admin
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Bug reports, suggestions, channel requests,
|
||||
and account questions.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-md border bg-background px-3 py-2 text-sm">
|
||||
{conversations.length} threads
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-2">
|
||||
{conversations.map((conversation) => (
|
||||
<Link
|
||||
key={conversation.id}
|
||||
href={showConversation(conversation.id)}
|
||||
className="grid gap-3 rounded-md border bg-card p-4 shadow-sm transition hover:border-primary/50 md:grid-cols-[minmax(0,1fr)_auto]"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<StatusBadge
|
||||
status={conversation.status}
|
||||
/>
|
||||
<span className="rounded-md border px-2 py-0.5 text-xs text-muted-foreground">
|
||||
{conversation.category_label}
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-2 truncate font-medium">
|
||||
{conversation.subject}
|
||||
</div>
|
||||
{conversation.latest_message && (
|
||||
<p className="mt-1 line-clamp-2 text-sm text-muted-foreground">
|
||||
{
|
||||
conversation.latest_message
|
||||
.author.name
|
||||
}
|
||||
: {conversation.latest_message.body}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground md:justify-end">
|
||||
<MessageSquare className="size-4" />
|
||||
{conversation.messages_count}
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
|
||||
{conversations.length === 0 && (
|
||||
<div className="grid min-h-64 place-items-center rounded-md border border-dashed bg-card p-6 text-center text-sm text-muted-foreground">
|
||||
No conversations yet.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="rounded-md border bg-card p-5 shadow-sm">
|
||||
<div className="mb-5">
|
||||
<h2 className="font-semibold">New conversation</h2>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Attach up to 3 files, 10 MB each.
|
||||
</p>
|
||||
</div>
|
||||
<form onSubmit={submit} className="grid gap-4">
|
||||
<Field label="Category" error={form.errors.category}>
|
||||
<select
|
||||
value={form.data.category}
|
||||
onChange={(event) =>
|
||||
form.setData('category', event.target.value)
|
||||
}
|
||||
className="h-9 rounded-md border bg-background px-3 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50"
|
||||
>
|
||||
{categories.map((category) => (
|
||||
<option
|
||||
key={category.value}
|
||||
value={category.value}
|
||||
>
|
||||
{category.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Subject" error={form.errors.subject}>
|
||||
<Input
|
||||
value={form.data.subject}
|
||||
onChange={(event) =>
|
||||
form.setData('subject', event.target.value)
|
||||
}
|
||||
maxLength={120}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Message" error={form.errors.body}>
|
||||
<textarea
|
||||
value={form.data.body}
|
||||
onChange={(event) =>
|
||||
form.setData('body', event.target.value)
|
||||
}
|
||||
className="min-h-36 rounded-md border bg-background px-3 py-2 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50"
|
||||
maxLength={2000}
|
||||
/>
|
||||
</Field>
|
||||
<Field
|
||||
label="Attachments"
|
||||
error={form.errors.attachments}
|
||||
>
|
||||
<Input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
multiple
|
||||
onChange={(event) =>
|
||||
setAttachments(event.target.files)
|
||||
}
|
||||
/>
|
||||
{form.data.attachments.length > 0 && (
|
||||
<div className="grid gap-1 text-xs text-muted-foreground">
|
||||
{form.data.attachments.map((file) => (
|
||||
<span
|
||||
key={`${file.name}-${file.size}`}
|
||||
className="flex min-w-0 items-center gap-2"
|
||||
>
|
||||
<FileUp className="size-3.5 shrink-0" />
|
||||
<span className="truncate">
|
||||
{file.name}
|
||||
</span>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{form.progress && (
|
||||
<progress
|
||||
value={form.progress.percentage}
|
||||
max="100"
|
||||
className="h-1.5 w-full"
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
<Button type="submit" disabled={form.processing}>
|
||||
<Send className="size-4" />
|
||||
Send
|
||||
</Button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
SupportIndex.layout = {
|
||||
breadcrumbs: [
|
||||
{
|
||||
title: 'Contact admin',
|
||||
href: supportIndex(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
function Field({
|
||||
label,
|
||||
error,
|
||||
children,
|
||||
}: {
|
||||
label: string;
|
||||
error?: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<label className="grid gap-2">
|
||||
<Label>{label}</Label>
|
||||
{children}
|
||||
{error && <span className="text-sm text-destructive">{error}</span>}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
function StatusBadge({ status }: { status: 'open' | 'closed' }) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
'rounded-md border px-2 py-0.5 text-xs font-medium',
|
||||
status === 'open'
|
||||
? 'border-success/40 bg-success/10 text-success'
|
||||
: 'text-muted-foreground',
|
||||
)}
|
||||
>
|
||||
{status === 'open' ? 'OPEN' : 'CLOSED'}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
264
resources/js/pages/support/show.tsx
Normal file
264
resources/js/pages/support/show.tsx
Normal file
@@ -0,0 +1,264 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { ArrowLeft, FileDown, FileUp, Lock, Send } from 'lucide-react';
|
||||
import type { FormEvent, ReactNode } from 'react';
|
||||
import { useRef } from 'react';
|
||||
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 } from '@/routes/support';
|
||||
import { show as showAttachment } from '@/routes/support/attachments';
|
||||
import { store as storeMessage } from '@/routes/support/messages';
|
||||
import type {
|
||||
SupportAttachment,
|
||||
SupportConversation,
|
||||
SupportMessage,
|
||||
} from '@/types';
|
||||
|
||||
type Props = {
|
||||
conversation: SupportConversation;
|
||||
};
|
||||
|
||||
export default function SupportShow({ conversation }: Props) {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const form = useForm({
|
||||
body: '',
|
||||
attachments: [] as File[],
|
||||
});
|
||||
const isClosed = conversation.status === 'closed';
|
||||
|
||||
function submit(event: FormEvent) {
|
||||
event.preventDefault();
|
||||
|
||||
form.post(storeMessage.url(conversation.id), {
|
||||
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 (
|
||||
<>
|
||||
<Head title={conversation.subject} />
|
||||
<div className="grid gap-6 p-4 md:p-6">
|
||||
<div className="rounded-md border bg-card p-5 shadow-sm">
|
||||
<Button asChild variant="ghost" size="sm" className="mb-4">
|
||||
<Link href={supportIndex()}>
|
||||
<ArrowLeft className="size-4" />
|
||||
Contact admin
|
||||
</Link>
|
||||
</Button>
|
||||
<div className="flex flex-col gap-3 md:flex-row md:items-start md:justify-between">
|
||||
<div className="min-w-0">
|
||||
<div className="mb-2 flex flex-wrap items-center gap-2">
|
||||
<StatusBadge status={conversation.status} />
|
||||
<span className="rounded-md border px-2 py-0.5 text-xs text-muted-foreground">
|
||||
{conversation.category_label}
|
||||
</span>
|
||||
</div>
|
||||
<h1 className="text-2xl font-semibold break-words">
|
||||
{conversation.subject}
|
||||
</h1>
|
||||
</div>
|
||||
<div className="rounded-md border bg-background px-3 py-2 text-sm text-muted-foreground">
|
||||
{conversation.messages_count} messages
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section className="grid gap-3">
|
||||
{conversation.messages.map((message) => (
|
||||
<MessageBubble key={message.id} message={message} />
|
||||
))}
|
||||
</section>
|
||||
|
||||
<section className="rounded-md border bg-card p-5 shadow-sm">
|
||||
{isClosed ? (
|
||||
<div className="flex items-start gap-3 rounded-md border border-dashed bg-background p-4 text-sm text-muted-foreground">
|
||||
<Lock className="mt-0.5 size-4 shrink-0" />
|
||||
<span>This conversation is closed.</span>
|
||||
</div>
|
||||
) : (
|
||||
<form onSubmit={submit} className="grid gap-4">
|
||||
<Field label="Reply" error={form.errors.body}>
|
||||
<textarea
|
||||
value={form.data.body}
|
||||
onChange={(event) =>
|
||||
form.setData('body', event.target.value)
|
||||
}
|
||||
className="min-h-32 rounded-md border bg-background px-3 py-2 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50"
|
||||
maxLength={2000}
|
||||
/>
|
||||
</Field>
|
||||
<Field
|
||||
label="Attachments"
|
||||
error={form.errors.attachments}
|
||||
>
|
||||
<Input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
multiple
|
||||
onChange={(event) =>
|
||||
setAttachments(event.target.files)
|
||||
}
|
||||
/>
|
||||
{form.data.attachments.length > 0 && (
|
||||
<div className="grid gap-1 text-xs text-muted-foreground">
|
||||
{form.data.attachments.map((file) => (
|
||||
<span
|
||||
key={`${file.name}-${file.size}`}
|
||||
className="flex min-w-0 items-center gap-2"
|
||||
>
|
||||
<FileUp className="size-3.5 shrink-0" />
|
||||
<span className="truncate">
|
||||
{file.name}
|
||||
</span>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{form.progress && (
|
||||
<progress
|
||||
value={form.progress.percentage}
|
||||
max="100"
|
||||
className="h-1.5 w-full"
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={form.processing}
|
||||
className="w-fit"
|
||||
>
|
||||
<Send className="size-4" />
|
||||
Send reply
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
SupportShow.layout = {
|
||||
breadcrumbs: [
|
||||
{
|
||||
title: 'Contact admin',
|
||||
href: supportIndex(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
function MessageBubble({ message }: { message: SupportMessage }) {
|
||||
const isAdmin = message.author.is_admin;
|
||||
|
||||
return (
|
||||
<article
|
||||
className={cn(
|
||||
'grid max-w-3xl gap-3 rounded-md border bg-card p-4 shadow-sm',
|
||||
!isAdmin && 'justify-self-end border-primary/30',
|
||||
)}
|
||||
>
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||
<span className="font-medium">{message.author.name}</span>
|
||||
<span className="rounded-md border px-2 py-0.5 text-xs text-muted-foreground">
|
||||
{isAdmin ? 'ADMIN' : 'YOU'}
|
||||
</span>
|
||||
{message.created_at && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{formatDateTime(message.created_at)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm leading-6 break-words whitespace-pre-wrap">
|
||||
{message.body}
|
||||
</p>
|
||||
{message.attachments && message.attachments.length > 0 && (
|
||||
<AttachmentList attachments={message.attachments} />
|
||||
)}
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
function AttachmentList({ attachments }: { attachments: SupportAttachment[] }) {
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{attachments.map((attachment) => (
|
||||
<a
|
||||
key={attachment.id}
|
||||
href={showAttachment.url(attachment.id)}
|
||||
className="inline-flex max-w-full items-center gap-2 rounded-md border bg-background px-2 py-1 text-xs hover:bg-accent hover:text-accent-foreground"
|
||||
>
|
||||
<FileDown className="size-3.5 shrink-0" />
|
||||
<span className="truncate">{attachment.original_name}</span>
|
||||
<span className="shrink-0 text-muted-foreground">
|
||||
{formatBytes(attachment.size)}
|
||||
</span>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Field({
|
||||
label,
|
||||
error,
|
||||
children,
|
||||
}: {
|
||||
label: string;
|
||||
error?: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<label className="grid gap-2">
|
||||
<Label>{label}</Label>
|
||||
{children}
|
||||
{error && <span className="text-sm text-destructive">{error}</span>}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
function StatusBadge({ status }: { status: 'open' | 'closed' }) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
'rounded-md border px-2 py-0.5 text-xs font-medium',
|
||||
status === 'open'
|
||||
? 'border-success/40 bg-success/10 text-success'
|
||||
: 'text-muted-foreground',
|
||||
)}
|
||||
>
|
||||
{status === 'open' ? 'OPEN' : 'CLOSED'}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function formatDateTime(value: string): string {
|
||||
return new Date(value).toLocaleString([], {
|
||||
dateStyle: 'medium',
|
||||
timeStyle: 'short',
|
||||
});
|
||||
}
|
||||
|
||||
function formatBytes(value: number): string {
|
||||
if (value < 1024) {
|
||||
return `${value} B`;
|
||||
}
|
||||
|
||||
if (value < 1024 * 1024) {
|
||||
return `${Math.round(value / 102.4) / 10} KB`;
|
||||
}
|
||||
|
||||
return `${Math.round(value / 1024 / 102.4) / 10} MB`;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { Head, Link, usePage } from '@inertiajs/react';
|
||||
import {
|
||||
ArrowRight,
|
||||
Compass,
|
||||
LifeBuoy,
|
||||
LayoutDashboard,
|
||||
Radio,
|
||||
Search,
|
||||
@@ -15,6 +16,7 @@ import { Input } from '@/components/ui/input';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { dashboard, home, login, register } from '@/routes';
|
||||
import { show as showChannel } from '@/routes/channels';
|
||||
import { index as supportIndex } from '@/routes/support';
|
||||
import type { Category, ChannelCard } from '@/types';
|
||||
|
||||
type Props = {
|
||||
@@ -75,23 +77,39 @@ export default function Welcome({
|
||||
Live
|
||||
</Link>
|
||||
{auth.user && (
|
||||
<Link
|
||||
href={dashboard()}
|
||||
className="rounded-md px-3 py-2 hover:bg-accent hover:text-accent-foreground"
|
||||
>
|
||||
Studio
|
||||
</Link>
|
||||
<>
|
||||
<Link
|
||||
href={dashboard()}
|
||||
className="rounded-md px-3 py-2 hover:bg-accent hover:text-accent-foreground"
|
||||
>
|
||||
Studio
|
||||
</Link>
|
||||
<Link
|
||||
href={supportIndex()}
|
||||
className="rounded-md px-3 py-2 hover:bg-accent hover:text-accent-foreground"
|
||||
>
|
||||
Contact
|
||||
</Link>
|
||||
</>
|
||||
)}
|
||||
</nav>
|
||||
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
{auth.user ? (
|
||||
<Button asChild size="sm">
|
||||
<Link href={dashboard()}>
|
||||
<LayoutDashboard className="size-4" />
|
||||
Studio
|
||||
</Link>
|
||||
</Button>
|
||||
<>
|
||||
<Button asChild size="sm">
|
||||
<Link href={dashboard()}>
|
||||
<LayoutDashboard className="size-4" />
|
||||
Studio
|
||||
</Link>
|
||||
</Button>
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<Link href={supportIndex()}>
|
||||
<LifeBuoy className="size-4" />
|
||||
Contact
|
||||
</Link>
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Button asChild variant="ghost" size="sm">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export type * from './auth';
|
||||
export type * from './navigation';
|
||||
export type * from './streaming';
|
||||
export type * from './support';
|
||||
export type * from './ui';
|
||||
|
||||
57
resources/js/types/support.ts
Normal file
57
resources/js/types/support.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
export type SupportCategoryOption = {
|
||||
value: string;
|
||||
label: string;
|
||||
};
|
||||
|
||||
export type SupportStatus = 'open' | 'closed';
|
||||
|
||||
export type SupportAuthor = {
|
||||
id: number | null;
|
||||
name: string;
|
||||
is_admin: boolean;
|
||||
};
|
||||
|
||||
export type SupportAttachment = {
|
||||
id: number;
|
||||
original_name: string;
|
||||
mime_type: string;
|
||||
size: number;
|
||||
};
|
||||
|
||||
export type SupportMessage = {
|
||||
id: number;
|
||||
body: string;
|
||||
created_at: string | null;
|
||||
author: SupportAuthor;
|
||||
attachments?: SupportAttachment[];
|
||||
};
|
||||
|
||||
export type SupportUser = {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
can_create_channel?: boolean;
|
||||
suspended_at?: string | null;
|
||||
channel?: {
|
||||
id: number;
|
||||
slug: string;
|
||||
display_name: string;
|
||||
} | null;
|
||||
};
|
||||
|
||||
export type SupportConversationSummary = {
|
||||
id: number;
|
||||
category: string;
|
||||
category_label: string;
|
||||
subject: string;
|
||||
status: SupportStatus;
|
||||
last_message_at: string | null;
|
||||
messages_count: number;
|
||||
latest_message: SupportMessage | null;
|
||||
user?: SupportUser;
|
||||
};
|
||||
|
||||
export type SupportConversation = SupportConversationSummary & {
|
||||
messages: SupportMessage[];
|
||||
user?: SupportUser;
|
||||
};
|
||||
Reference in New Issue
Block a user