import "./components/ui/tidal.css"; import { useMemo, useRef, useState, type FormEvent } from "react"; import { TidalSupportInbox, type TidalSupportAction, type TidalSupportStatusOption, type TidalSupportTicket } from "./components/ui/support-inbox"; import "./components/ui/support-inbox.css"; function tidalExampleAvatarDataUri(seed: unknown) { const text = String(seed).replace(/[^a-z0-9]/gi, "").slice(-2) || "UI"; const palette = ["#333333", "#555555", "#777777", "#999999", "#bbbbbb"]; const color = palette[Array.from(text).reduce((sum, character) => sum + character.charCodeAt(0), 0) % palette.length]; const svg = ``; return `data:image/svg+xml,${encodeURIComponent(svg)}`; } function tidalExampleImageDataUri(label: string) { const safeLabel = label.replace(/[<>&]/g, "").slice(0, 28) || "Sample image"; const svg = `${safeLabel}`; return `data:image/svg+xml,${encodeURIComponent(svg)}`; } const tidalExampleStyles = ".tidal-scope .support-inbox-demo,\n.tidal-scope .support-inbox-demo * {\n box-sizing: border-box;\n}\n\n.tidal-scope .support-inbox-demo {\n width: 100%;\n max-width: 1160px;\n min-width: 0;\n padding: 20px;\n border: 1px solid var(--t-border);\n border-radius: 22px;\n background:\n linear-gradient(var(--t-border) 1px, transparent 1px),\n linear-gradient(90deg, var(--t-border) 1px, transparent 1px),\n var(--t-subtle);\n background-size: 22px 22px;\n container: support-demo / inline-size;\n}\n\n@container support-demo (max-width: 430px) {\n .tidal-scope .support-inbox-demo {\n padding: 8px;\n }\n}"; const INITIAL_TICKETS: readonly TidalSupportTicket[] = [ { id: "ava-export", customerName: "Ava Chen", subject: "Export includes an extra blank page", preview: "The PDF is correct except for the final page.", timestamp: "12 min", avatarSrc: tidalExampleAvatarDataUri("01"), status: "open", statusLabel: "Open", unreadCount: 2, messages: [ { id: "ava-1", authorName: "Ava Chen", avatarSrc: tidalExampleAvatarDataUri("01"), side: "customer", timestamp: "9:12 AM", body: "The sample export looks right, but it adds one blank page at the end.", }, { id: "ava-2", authorName: "Eli Park", avatarSrc: tidalExampleAvatarDataUri("04"), side: "agent", timestamp: "9:18 AM", body: "Thanks. I can reproduce that in this fictional thread and will check the final section break.", }, ], }, { id: "noah-members", customerName: "Noah Reed", subject: "Where do I review invited members?", preview: "Looking for the sample member list.", timestamp: "34 min", avatarSrc: tidalExampleAvatarDataUri("02"), status: "pending", statusLabel: "Pending", messages: [ { id: "noah-1", authorName: "Noah Reed", avatarSrc: tidalExampleAvatarDataUri("02"), side: "customer", timestamp: "8:46 AM", body: "Where can I see the people already invited to the sample workspace?", }, ], }, { id: "mila-copy", customerName: "Mila Stone", subject: "Update the confirmation copy", preview: "The current line needs a clearer next step.", timestamp: "Yesterday", avatarSrc: tidalExampleAvatarDataUri("03"), status: "resolved", statusLabel: "Resolved", messages: [ { id: "mila-1", authorName: "Mila Stone", avatarSrc: tidalExampleAvatarDataUri("03"), side: "customer", timestamp: "Yesterday", body: "Could the confirmation explain what happens after the local draft is created?", }, { id: "mila-2", authorName: "Eli Park", avatarSrc: tidalExampleAvatarDataUri("04"), side: "agent", timestamp: "Yesterday", body: "The revised fictional copy now points to the review step.", }, ], }, ]; const STATUS_OPTIONS: readonly TidalSupportStatusOption[] = [ { value: "all", label: "All statuses" }, { value: "open", label: "Open" }, { value: "pending", label: "Pending" }, { value: "resolved", label: "Resolved" }, ]; function filterTickets( tickets: readonly TidalSupportTicket[], search: string, status: string, ) { const query = search.trim().toLocaleLowerCase(); return tickets.filter((ticket) => { const matchesStatus = status === "all" || ticket.status === status; const matchesSearch = !query || `${ticket.customerName} ${ticket.subject}` .toLocaleLowerCase() .includes(query); return matchesStatus && matchesSearch; }); } export function SupportInboxDemo() { const [tickets, setTickets] = useState(INITIAL_TICKETS); const [selectedId, setSelectedId] = useState("ava-export"); const [search, setSearch] = useState(""); const [status, setStatus] = useState("all"); const [draft, setDraft] = useState(""); const [message, setMessage] = useState( "This fictional inbox uses only local preview state.", ); const localReplyNumber = useRef(0); const textareaRef = useRef(null); const visibleTickets = useMemo( () => filterTickets(tickets, search, status), [search, status, tickets], ); function reconcileSelection(nextTickets: readonly TidalSupportTicket[]) { if (nextTickets.some((ticket) => ticket.id === selectedId)) return; setSelectedId(nextTickets[0]?.id ?? ""); setDraft(""); } const selectedTicket = tickets.find((ticket) => ticket.id === selectedId); const conversationActions = useMemo( () => selectedTicket ? [ { kind: "button" as const, id: "toggle-pending", label: selectedTicket.status === "pending" ? "Mark open" : "Mark pending", onAction: () => { const nextStatus = selectedTicket.status === "pending" ? "open" : "pending"; setStatus("all"); setTickets((current) => current.map((ticket) => ticket.id === selectedTicket.id ? { ...ticket, status: nextStatus, statusLabel: nextStatus === "open" ? "Open" : "Pending", } : ticket, ), ); setMessage( `${selectedTicket.subject} marked ${nextStatus} in the local sample. The status filter returned to All statuses so the selected thread stays open.`, ); }, }, ] : [], [selectedTicket], ); function addLocalReply( ticket: TidalSupportTicket, event: FormEvent, ) { event.preventDefault(); const body = draft.trim(); if (!body) { setMessage("Write a local reply before adding it."); textareaRef.current?.focus({ preventScroll: true }); return; } localReplyNumber.current += 1; const replyId = `local-reply-${localReplyNumber.current}`; setTickets((current) => current.map((currentTicket) => currentTicket.id === ticket.id ? { ...currentTicket, messages: [ ...currentTicket.messages, { id: replyId, authorName: "Eli Park", avatarSrc: tidalExampleAvatarDataUri("04"), side: "agent" as const, timestamp: "Just now", body, }, ], } : currentTicket, ), ); setDraft(""); setMessage(`A fictional reply was added locally to ${ticket.subject}.`); textareaRef.current?.focus({ preventScroll: true }); } return (
{ setSelectedId(ticket.id); setDraft(""); setMessage(`${ticket.subject} selected.`); }} searchValue={search} onSearchValueChange={(value) => { setSearch(value); reconcileSelection(filterTickets(tickets, value, status)); }} searchInputProps={{ placeholder: "Search name or subject" }} statusFilterValue={status} statusOptions={STATUS_OPTIONS} onStatusFilterChange={(value) => { setStatus(value); reconcileSelection(filterTickets(tickets, search, value)); }} conversationActions={conversationActions} draftValue={draft} onDraftValueChange={setDraft} onReplySubmit={addLocalReply} composerLabel="Local reply draft" composerPlaceholder="Write a fictional reply" submitLabel="Add local reply" textareaRef={textareaRef} submitButtonProps={{ disabled: !draft.trim() }} footer={ {message} {" "} No reply is sent, stored, or connected to a support service. } />
); } export default function AgentExample() { return (
); }