feat: surface ticket work metrics and refresh list layout

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
esdrasrenan 2025-10-04 22:22:02 -03:00
parent 744d5933d4
commit 55511f3a0e
20 changed files with 1102 additions and 357 deletions

View file

@ -3,7 +3,7 @@
import { z } from "zod"
import { useState } from "react"
import type { Id } from "@/convex/_generated/dataModel"
import type { TicketQueueSummary } from "@/lib/schemas/ticket"
import type { TicketPriority, TicketQueueSummary } from "@/lib/schemas/ticket"
import { useMutation, useQuery } from "convex/react"
// @ts-ignore
import { api } from "@/convex/_generated/api"
@ -20,6 +20,15 @@ import { toast } from "sonner"
import { Spinner } from "@/components/ui/spinner"
import { Dropzone } from "@/components/ui/dropzone"
import { RichTextEditor } from "@/components/ui/rich-text-editor"
import { Badge } from "@/components/ui/badge"
import { cn } from "@/lib/utils"
import {
PriorityIcon,
priorityBadgeClass,
priorityItemClass,
priorityStyles,
priorityTriggerClass,
} from "@/components/tickets/priority-select"
const schema = z.object({
subject: z.string().min(3, "Informe um assunto"),
@ -43,6 +52,11 @@ export function NewTicketDialog() {
const create = useMutation(api.tickets.create)
const addComment = useMutation(api.tickets.addComment)
const [attachments, setAttachments] = useState<Array<{ storageId: string; name: string; size?: number; type?: string }>>([])
const priorityValue = form.watch("priority") as TicketPriority
const channelValue = form.watch("channel")
const queueValue = form.watch("queueName") ?? "NONE"
const selectTriggerClass = "flex h-8 w-full items-center justify-between rounded-full border border-slate-300 bg-white px-3 text-sm font-medium text-neutral-800 shadow-sm focus:ring-0 data-[state=open]:border-[#00d6eb]"
const selectItemClass = "flex items-center gap-2 rounded-md px-2 py-2 text-sm text-neutral-800 transition data-[state=checked]:bg-[#00e8ff]/15 data-[state=checked]:text-neutral-900 focus:bg-[#00e8ff]/10"
async function submit(values: z.infer<typeof schema>) {
if (!userId) return
@ -91,7 +105,12 @@ export function NewTicketDialog() {
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button size="sm">Novo ticket</Button>
<Button
size="sm"
className="rounded-lg border border-black bg-black px-3 py-1.5 text-sm font-semibold text-white transition hover:bg-[#18181b]/85 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#18181b]/30"
>
Novo ticket
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
@ -126,53 +145,90 @@ export function NewTicketDialog() {
<div className="grid gap-3 sm:grid-cols-3">
<Field>
<FieldLabel>Prioridade</FieldLabel>
<Select value={form.watch("priority")} onValueChange={(v) => form.setValue("priority", v as z.infer<typeof schema>["priority"])}>
<SelectTrigger><SelectValue placeholder="Prioridade" /></SelectTrigger>
<SelectContent>
<SelectItem value="LOW">Baixa</SelectItem>
<SelectItem value="MEDIUM">Média</SelectItem>
<SelectItem value="HIGH">Alta</SelectItem>
<SelectItem value="URGENT">Urgente</SelectItem>
<Select value={priorityValue} onValueChange={(v) => form.setValue("priority", v as z.infer<typeof schema>["priority"])}>
<SelectTrigger className={cn(priorityTriggerClass, "w-full justify-between")}>
<SelectValue>
<Badge className={cn(priorityBadgeClass, priorityStyles[priorityValue]?.badgeClass)}>
<PriorityIcon value={priorityValue} />
{priorityStyles[priorityValue]?.label ?? priorityValue}
</Badge>
</SelectValue>
</SelectTrigger>
<SelectContent className="rounded-xl border border-slate-200 bg-white text-neutral-800 shadow-md">
{(["LOW", "MEDIUM", "HIGH", "URGENT"] as const).map((option) => (
<SelectItem key={option} value={option} className={priorityItemClass}>
<span className="inline-flex items-center gap-2">
<PriorityIcon value={option} />
{priorityStyles[option].label}
</span>
</SelectItem>
))}
</SelectContent>
</Select>
</Field>
<Field>
<FieldLabel>Canal</FieldLabel>
<Select value={form.watch("channel")} onValueChange={(v) => form.setValue("channel", v as z.infer<typeof schema>["channel"])}>
<SelectTrigger><SelectValue placeholder="Canal" /></SelectTrigger>
<SelectContent>
<SelectItem value="EMAIL">E-mail</SelectItem>
<SelectItem value="WHATSAPP">WhatsApp</SelectItem>
<SelectItem value="CHAT">Chat</SelectItem>
<SelectItem value="PHONE">Telefone</SelectItem>
<SelectItem value="API">API</SelectItem>
<SelectItem value="MANUAL">Manual</SelectItem>
<Select value={channelValue} onValueChange={(v) => form.setValue("channel", v as z.infer<typeof schema>["channel"])}>
<SelectTrigger className={selectTriggerClass}>
<SelectValue placeholder="Canal" />
</SelectTrigger>
<SelectContent className="rounded-xl border border-slate-200 bg-white text-neutral-800 shadow-md">
<SelectItem value="EMAIL" className={selectItemClass}>
E-mail
</SelectItem>
<SelectItem value="WHATSAPP" className={selectItemClass}>
WhatsApp
</SelectItem>
<SelectItem value="CHAT" className={selectItemClass}>
Chat
</SelectItem>
<SelectItem value="PHONE" className={selectItemClass}>
Telefone
</SelectItem>
<SelectItem value="API" className={selectItemClass}>
API
</SelectItem>
<SelectItem value="MANUAL" className={selectItemClass}>
Manual
</SelectItem>
</SelectContent>
</Select>
</Field>
<Field>
<FieldLabel>Fila</FieldLabel>
<Select value={queueValue} onValueChange={(v) => form.setValue("queueName", v === "NONE" ? null : v)}>
<SelectTrigger className={selectTriggerClass}>
<SelectValue placeholder="Sem fila" />
</SelectTrigger>
<SelectContent className="rounded-xl border border-slate-200 bg-white text-neutral-800 shadow-md">
<SelectItem value="NONE" className={selectItemClass}>
Sem fila
</SelectItem>
{queues.map((q) => (
<SelectItem key={q.id} value={q.name} className={selectItemClass}>
{q.name}
</SelectItem>
))}
</SelectContent>
</Select>
</Field>
<Field>
<FieldLabel>Fila</FieldLabel>
{(() => {
const NONE = "NONE";
const current = form.watch("queueName") ?? NONE;
return (
<Select value={current} onValueChange={(v) => form.setValue("queueName", v === NONE ? null : v)}>
<SelectTrigger><SelectValue placeholder="Sem fila" /></SelectTrigger>
<SelectContent>
<SelectItem value={NONE}>Sem fila</SelectItem>
{queues.map((q) => (
<SelectItem key={q.id} value={q.name}>{q.name}</SelectItem>
))}
</SelectContent>
</Select>
)
})()}
</Field>
</div>
</FieldGroup>
</FieldSet>
<div className="flex justify-end">
<Button type="submit" disabled={loading}>{loading ? (<><Spinner className="me-2" /> Criando</>) : "Criar"}</Button>
<Button
type="submit"
disabled={loading}
className="rounded-lg border border-black bg-black px-4 py-2 text-sm font-semibold text-white transition hover:bg-[#18181b]/85 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#18181b]/30 disabled:opacity-60"
>
{loading ? (
<>
<Spinner className="me-2" /> Criando
</>
) : (
"Criar"
)}
</Button>
</div>
</form>
</DialogContent>