feat: aprimora upload/anexos e regras de atendimento no portal
This commit is contained in:
parent
7e8023ed87
commit
c90e99820f
8 changed files with 218 additions and 74 deletions
|
|
@ -607,10 +607,14 @@ function App() {
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{validatedCompany ? (
|
{validatedCompany ? (
|
||||||
<div className="rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs text-emerald-700">
|
<div className="flex items-start gap-3 rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-700">
|
||||||
<div className="text-sm font-semibold text-emerald-800">{validatedCompany.name}</div>
|
<span className="mt-1 inline-flex size-2 rounded-full bg-emerald-500" aria-hidden="true" />
|
||||||
<div>Tenant: <span className="font-mono text-emerald-800">{validatedCompany.tenantId}</span></div>
|
<div className="space-y-1">
|
||||||
<div>Slug: <span className="font-mono text-emerald-800">{validatedCompany.slug}</span></div>
|
<span className="block text-sm font-semibold text-emerald-800">{validatedCompany.name}</span>
|
||||||
|
<span className="text-xs text-emerald-700/80">
|
||||||
|
Código reconhecido. Esta máquina será vinculada automaticamente à empresa informada.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
|
|
|
||||||
|
|
@ -973,6 +973,7 @@ export const changeAssignee = mutation({
|
||||||
}
|
}
|
||||||
const ticketDoc = ticket as Doc<"tickets">
|
const ticketDoc = ticket as Doc<"tickets">
|
||||||
const viewer = await requireTicketStaff(ctx, actorId, ticketDoc)
|
const viewer = await requireTicketStaff(ctx, actorId, ticketDoc)
|
||||||
|
const isAdmin = viewer.role === "ADMIN"
|
||||||
const assignee = (await ctx.db.get(assigneeId)) as Doc<"users"> | null
|
const assignee = (await ctx.db.get(assigneeId)) as Doc<"users"> | null
|
||||||
if (!assignee || assignee.tenantId !== ticketDoc.tenantId) {
|
if (!assignee || assignee.tenantId !== ticketDoc.tenantId) {
|
||||||
throw new ConvexError("Responsável inválido")
|
throw new ConvexError("Responsável inválido")
|
||||||
|
|
@ -980,6 +981,11 @@ export const changeAssignee = mutation({
|
||||||
if (viewer.role === "MANAGER") {
|
if (viewer.role === "MANAGER") {
|
||||||
throw new ConvexError("Gestores não podem reatribuir chamados")
|
throw new ConvexError("Gestores não podem reatribuir chamados")
|
||||||
}
|
}
|
||||||
|
const currentAssigneeId = ticketDoc.assigneeId ?? null
|
||||||
|
if (currentAssigneeId && currentAssigneeId !== actorId && !isAdmin) {
|
||||||
|
throw new ConvexError("Somente o responsável atual pode reatribuir este chamado")
|
||||||
|
}
|
||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
await ctx.db.patch(ticketId, { assigneeId, updatedAt: now });
|
await ctx.db.patch(ticketId, { assigneeId, updatedAt: now });
|
||||||
await ctx.db.insert("ticketEvents", {
|
await ctx.db.insert("ticketEvents", {
|
||||||
|
|
@ -1165,12 +1171,28 @@ export const startWork = mutation({
|
||||||
if (!ticket) {
|
if (!ticket) {
|
||||||
throw new ConvexError("Ticket não encontrado")
|
throw new ConvexError("Ticket não encontrado")
|
||||||
}
|
}
|
||||||
await requireStaff(ctx, actorId, ticket.tenantId)
|
const ticketDoc = ticket as Doc<"tickets">
|
||||||
if (ticket.activeSessionId) {
|
const viewer = await requireTicketStaff(ctx, actorId, ticketDoc)
|
||||||
return { status: "already_started", sessionId: ticket.activeSessionId }
|
const isAdmin = viewer.role === "ADMIN"
|
||||||
|
const currentAssigneeId = ticketDoc.assigneeId ?? null
|
||||||
|
|
||||||
|
if (currentAssigneeId && currentAssigneeId !== actorId && !isAdmin) {
|
||||||
|
throw new ConvexError("Somente o responsável atual pode iniciar este chamado")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ticketDoc.activeSessionId) {
|
||||||
|
return { status: "already_started", sessionId: ticketDoc.activeSessionId }
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
|
let assigneePatched = false
|
||||||
|
|
||||||
|
if (!currentAssigneeId) {
|
||||||
|
await ctx.db.patch(ticketId, { assigneeId: actorId, updatedAt: now })
|
||||||
|
ticketDoc.assigneeId = actorId
|
||||||
|
assigneePatched = true
|
||||||
|
}
|
||||||
|
|
||||||
const sessionId = await ctx.db.insert("ticketWorkSessions", {
|
const sessionId = await ctx.db.insert("ticketWorkSessions", {
|
||||||
ticketId,
|
ticketId,
|
||||||
agentId: actorId,
|
agentId: actorId,
|
||||||
|
|
@ -1184,11 +1206,25 @@ export const startWork = mutation({
|
||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
})
|
})
|
||||||
|
|
||||||
const actor = (await ctx.db.get(actorId)) as Doc<"users"> | null
|
if (assigneePatched) {
|
||||||
|
await ctx.db.insert("ticketEvents", {
|
||||||
|
ticketId,
|
||||||
|
type: "ASSIGNEE_CHANGED",
|
||||||
|
payload: { assigneeId: actorId, assigneeName: viewer.user.name, actorId },
|
||||||
|
createdAt: now,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
await ctx.db.insert("ticketEvents", {
|
await ctx.db.insert("ticketEvents", {
|
||||||
ticketId,
|
ticketId,
|
||||||
type: "WORK_STARTED",
|
type: "WORK_STARTED",
|
||||||
payload: { actorId, actorName: actor?.name, actorAvatar: actor?.avatarUrl, sessionId, workType: (workType ?? "INTERNAL").toUpperCase() },
|
payload: {
|
||||||
|
actorId,
|
||||||
|
actorName: viewer.user.name,
|
||||||
|
actorAvatar: viewer.user.avatarUrl,
|
||||||
|
sessionId,
|
||||||
|
workType: (workType ?? "INTERNAL").toUpperCase(),
|
||||||
|
},
|
||||||
createdAt: now,
|
createdAt: now,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -1208,8 +1244,14 @@ export const pauseWork = mutation({
|
||||||
if (!ticket) {
|
if (!ticket) {
|
||||||
throw new ConvexError("Ticket não encontrado")
|
throw new ConvexError("Ticket não encontrado")
|
||||||
}
|
}
|
||||||
await requireStaff(ctx, actorId, ticket.tenantId)
|
const ticketDoc = ticket as Doc<"tickets">
|
||||||
if (!ticket.activeSessionId) {
|
const viewer = await requireTicketStaff(ctx, actorId, ticketDoc)
|
||||||
|
const isAdmin = viewer.role === "ADMIN"
|
||||||
|
if (ticketDoc.assigneeId && ticketDoc.assigneeId !== actorId && !isAdmin) {
|
||||||
|
throw new ConvexError("Somente o responsável atual pode pausar este chamado")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ticketDoc.activeSessionId) {
|
||||||
return { status: "already_paused" }
|
return { status: "already_paused" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1217,7 +1259,7 @@ export const pauseWork = mutation({
|
||||||
throw new ConvexError("Motivo de pausa inválido")
|
throw new ConvexError("Motivo de pausa inválido")
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = await ctx.db.get(ticket.activeSessionId)
|
const session = await ctx.db.get(ticketDoc.activeSessionId)
|
||||||
if (!session) {
|
if (!session) {
|
||||||
await ctx.db.patch(ticketId, { activeSessionId: undefined, working: false })
|
await ctx.db.patch(ticketId, { activeSessionId: undefined, working: false })
|
||||||
return { status: "session_missing" }
|
return { status: "session_missing" }
|
||||||
|
|
@ -1226,7 +1268,7 @@ export const pauseWork = mutation({
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
const durationMs = now - session.startedAt
|
const durationMs = now - session.startedAt
|
||||||
|
|
||||||
await ctx.db.patch(ticket.activeSessionId, {
|
await ctx.db.patch(ticketDoc.activeSessionId, {
|
||||||
stoppedAt: now,
|
stoppedAt: now,
|
||||||
durationMs,
|
durationMs,
|
||||||
pauseReason: reason,
|
pauseReason: reason,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,9 @@ export const metadata: Metadata = {
|
||||||
export default async function PortalProfilePage() {
|
export default async function PortalProfilePage() {
|
||||||
const session = await requireAuthenticatedSession()
|
const session = await requireAuthenticatedSession()
|
||||||
const role = (session.user.role ?? "").toLowerCase()
|
const role = (session.user.role ?? "").toLowerCase()
|
||||||
if (role !== "collaborator" && role !== "manager") {
|
const persona = (session.user.machinePersona ?? "").toLowerCase()
|
||||||
|
const allowed = role === "collaborator" || role === "manager" || persona === "collaborator" || persona === "manager"
|
||||||
|
if (!allowed) {
|
||||||
redirect("/portal")
|
redirect("/portal")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1962,6 +1962,7 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ machineId: machine.id }),
|
body: JSON.stringify({ machineId: machine.id }),
|
||||||
|
credentials: "include",
|
||||||
})
|
})
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||||
toast.success("Máquina excluída")
|
toast.success("Máquina excluída")
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ export function TicketStatusBadge({ status, className }: TicketStatusBadgeProps)
|
||||||
const parsed = ticketStatusSchema.parse(status)
|
const parsed = ticketStatusSchema.parse(status)
|
||||||
const styles = statusStyles[parsed]
|
const styles = statusStyles[parsed]
|
||||||
return (
|
return (
|
||||||
<Badge className={cn("inline-flex items-center rounded-full px-3 py-0.5 text-xs font-semibold", styles?.className, className)}>
|
<Badge className={cn("inline-flex h-9 items-center gap-2 rounded-full px-3 text-sm font-semibold", styles?.className, className)}>
|
||||||
{styles?.label ?? parsed}
|
{styles?.label ?? parsed}
|
||||||
</Badge>
|
</Badge>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import { Button } from "@/components/ui/button"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { Dropzone } from "@/components/ui/dropzone"
|
import { Dropzone } from "@/components/ui/dropzone"
|
||||||
import { RichTextEditor, RichTextContent, sanitizeEditorHtml } from "@/components/ui/rich-text-editor"
|
import { RichTextEditor, RichTextContent, sanitizeEditorHtml } from "@/components/ui/rich-text-editor"
|
||||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"
|
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"
|
||||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||||
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@/components/ui/select"
|
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@/components/ui/select"
|
||||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "@/components/ui/empty"
|
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "@/components/ui/empty"
|
||||||
|
|
@ -505,15 +505,18 @@ export function TicketComments({ ticket }: TicketCommentsProps) {
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
<Dialog open={!!preview} onOpenChange={(open) => !open && setPreview(null)}>
|
<Dialog open={!!preview} onOpenChange={(open) => !open && setPreview(null)}>
|
||||||
<DialogContent className="max-w-3xl p-0">
|
<DialogContent className="max-w-3xl border border-slate-200 p-0">
|
||||||
<DialogHeader className="sr-only">
|
<DialogHeader className="flex items-center justify-between gap-3 px-4 py-3">
|
||||||
<DialogTitle>Visualização de anexo</DialogTitle>
|
<DialogTitle className="text-base font-semibold text-neutral-800">Visualização do anexo</DialogTitle>
|
||||||
|
<DialogClose className="inline-flex size-7 items-center justify-center rounded-full border border-slate-200 bg-white text-neutral-600 transition hover:bg-slate-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-400/30">
|
||||||
|
<X className="size-4" />
|
||||||
|
</DialogClose>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
{preview ? (
|
{preview ? (
|
||||||
<>
|
<div className="rounded-b-2xl">
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
<img src={preview} alt="Preview" className="h-auto w-full rounded-xl" />
|
<img src={preview} alt="Preview do anexo" className="h-auto w-full rounded-b-2xl" />
|
||||||
</>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,9 @@ function formatDuration(durationMs: number) {
|
||||||
|
|
||||||
export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
||||||
const { convexUserId, role, isStaff } = useAuth()
|
const { convexUserId, role, isStaff } = useAuth()
|
||||||
const isManager = role === "manager"
|
const normalizedRole = (role ?? "").toLowerCase()
|
||||||
|
const isManager = normalizedRole === "manager"
|
||||||
|
const isAdmin = normalizedRole === "admin"
|
||||||
useDefaultQueues(ticket.tenantId)
|
useDefaultQueues(ticket.tenantId)
|
||||||
const changeAssignee = useMutation(api.tickets.changeAssignee)
|
const changeAssignee = useMutation(api.tickets.changeAssignee)
|
||||||
const changeQueue = useMutation(api.tickets.changeQueue)
|
const changeQueue = useMutation(api.tickets.changeQueue)
|
||||||
|
|
@ -138,6 +140,8 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
||||||
subcategoryId: ticket.subcategory?.id ?? "",
|
subcategoryId: ticket.subcategory?.id ?? "",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
const currentAssigneeId = ticket.assignee?.id ?? ""
|
||||||
|
const [assigneeSelection, setAssigneeSelection] = useState(currentAssigneeId)
|
||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
const [pauseDialogOpen, setPauseDialogOpen] = useState(false)
|
const [pauseDialogOpen, setPauseDialogOpen] = useState(false)
|
||||||
const [pauseReason, setPauseReason] = useState<string>(PAUSE_REASONS[0]?.value ?? "NO_CONTACT")
|
const [pauseReason, setPauseReason] = useState<string>(PAUSE_REASONS[0]?.value ?? "NO_CONTACT")
|
||||||
|
|
@ -159,13 +163,20 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
||||||
const isAvulso = Boolean(((ticket.company ?? null) as { isAvulso?: boolean } | null)?.isAvulso ?? false)
|
const isAvulso = Boolean(((ticket.company ?? null) as { isAvulso?: boolean } | null)?.isAvulso ?? false)
|
||||||
const [queueSelection, setQueueSelection] = useState(currentQueueName)
|
const [queueSelection, setQueueSelection] = useState(currentQueueName)
|
||||||
const queueDirty = useMemo(() => queueSelection !== currentQueueName, [queueSelection, currentQueueName])
|
const queueDirty = useMemo(() => queueSelection !== currentQueueName, [queueSelection, currentQueueName])
|
||||||
const formDirty = dirty || categoryDirty || queueDirty
|
const assigneeDirty = useMemo(() => assigneeSelection !== currentAssigneeId, [assigneeSelection, currentAssigneeId])
|
||||||
|
const formDirty = dirty || categoryDirty || queueDirty || assigneeDirty
|
||||||
|
|
||||||
const activeCategory = useMemo(
|
const activeCategory = useMemo(
|
||||||
() => categories.find((category) => category.id === selectedCategoryId) ?? null,
|
() => categories.find((category) => category.id === selectedCategoryId) ?? null,
|
||||||
[categories, selectedCategoryId]
|
[categories, selectedCategoryId]
|
||||||
)
|
)
|
||||||
const secondaryOptions = useMemo(() => activeCategory?.secondary ?? [], [activeCategory])
|
const secondaryOptions = useMemo(() => activeCategory?.secondary ?? [], [activeCategory])
|
||||||
|
const hasAssignee = Boolean(currentAssigneeId)
|
||||||
|
const isCurrentResponsible = hasAssignee && convexUserId ? currentAssigneeId === convexUserId : false
|
||||||
|
const canControlWork = isAdmin || !hasAssignee || isCurrentResponsible
|
||||||
|
const canPauseWork = isAdmin || isCurrentResponsible
|
||||||
|
const pauseDisabled = !canPauseWork
|
||||||
|
const startDisabled = !canControlWork
|
||||||
|
|
||||||
async function handleSave() {
|
async function handleSave() {
|
||||||
if (!convexUserId || !formDirty) {
|
if (!convexUserId || !formDirty) {
|
||||||
|
|
@ -225,6 +236,31 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
||||||
setQueueSelection(currentQueueName)
|
setQueueSelection(currentQueueName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (assigneeDirty && !isManager) {
|
||||||
|
if (!assigneeSelection) {
|
||||||
|
toast.error("Selecione um responsável válido.", { id: "assignee" })
|
||||||
|
setAssigneeSelection(currentAssigneeId)
|
||||||
|
throw new Error("invalid-assignee")
|
||||||
|
} else {
|
||||||
|
toast.loading("Atualizando responsável...", { id: "assignee" })
|
||||||
|
try {
|
||||||
|
await changeAssignee({
|
||||||
|
ticketId: ticket.id as Id<"tickets">,
|
||||||
|
assigneeId: assigneeSelection as Id<"users">,
|
||||||
|
actorId: convexUserId as Id<"users">,
|
||||||
|
})
|
||||||
|
toast.success("Responsável atualizado!", { id: "assignee" })
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
toast.error("Não foi possível atualizar o responsável.", { id: "assignee" })
|
||||||
|
setAssigneeSelection(currentAssigneeId)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (assigneeDirty && isManager) {
|
||||||
|
setAssigneeSelection(currentAssigneeId)
|
||||||
|
}
|
||||||
|
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
toast.loading("Salvando alterações...", { id: "save-header" })
|
toast.loading("Salvando alterações...", { id: "save-header" })
|
||||||
if (subject !== ticket.subject) {
|
if (subject !== ticket.subject) {
|
||||||
|
|
@ -259,6 +295,7 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
||||||
subcategoryId: currentSubcategoryId,
|
subcategoryId: currentSubcategoryId,
|
||||||
})
|
})
|
||||||
setQueueSelection(currentQueueName)
|
setQueueSelection(currentQueueName)
|
||||||
|
setAssigneeSelection(currentAssigneeId)
|
||||||
setEditing(false)
|
setEditing(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -269,6 +306,7 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
||||||
subcategoryId: ticket.subcategory?.id ?? "",
|
subcategoryId: ticket.subcategory?.id ?? "",
|
||||||
})
|
})
|
||||||
setQueueSelection(ticket.queue ?? "")
|
setQueueSelection(ticket.queue ?? "")
|
||||||
|
setAssigneeSelection(ticket.assignee?.id ?? "")
|
||||||
}, [editing, ticket.category?.id, ticket.subcategory?.id, ticket.queue])
|
}, [editing, ticket.category?.id, ticket.subcategory?.id, ticket.queue])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -387,8 +425,9 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
||||||
} else {
|
} else {
|
||||||
toast.success("Atendimento iniciado", { id: "work" })
|
toast.success("Atendimento iniciado", { id: "work" })
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (error) {
|
||||||
toast.error("Não foi possível atualizar o atendimento", { id: "work" })
|
const message = error instanceof Error ? error.message : "Não foi possível atualizar o atendimento"
|
||||||
|
toast.error(message, { id: "work" })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -410,8 +449,9 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
||||||
toast.success("Atendimento pausado", { id: "work" })
|
toast.success("Atendimento pausado", { id: "work" })
|
||||||
}
|
}
|
||||||
setPauseDialogOpen(false)
|
setPauseDialogOpen(false)
|
||||||
} catch {
|
} catch (error) {
|
||||||
toast.error("Não foi possível atualizar o atendimento", { id: "work" })
|
const message = error instanceof Error ? error.message : "Não foi possível atualizar o atendimento"
|
||||||
|
toast.error(message, { id: "work" })
|
||||||
} finally {
|
} finally {
|
||||||
setPausing(false)
|
setPausing(false)
|
||||||
}
|
}
|
||||||
|
|
@ -506,16 +546,41 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
||||||
requesterName={ticket.requester?.name ?? ticket.requester?.email ?? null}
|
requesterName={ticket.requester?.name ?? ticket.requester?.email ?? null}
|
||||||
/>
|
/>
|
||||||
{isPlaying ? (
|
{isPlaying ? (
|
||||||
<Button
|
<Tooltip>
|
||||||
size="sm"
|
<TooltipTrigger asChild>
|
||||||
className={pauseButtonClass}
|
<span className="inline-flex">
|
||||||
onClick={() => {
|
<Button
|
||||||
if (!convexUserId) return
|
size="sm"
|
||||||
setPauseDialogOpen(true)
|
className={pauseButtonClass}
|
||||||
}}
|
onClick={() => {
|
||||||
>
|
if (!convexUserId || pauseDisabled) return
|
||||||
<IconPlayerPause className="size-4 text-white" /> Pausar
|
setPauseDialogOpen(true)
|
||||||
</Button>
|
}}
|
||||||
|
disabled={pauseDisabled}
|
||||||
|
>
|
||||||
|
<IconPlayerPause className="size-4 text-white" /> Pausar
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
</TooltipTrigger>
|
||||||
|
{pauseDisabled ? (
|
||||||
|
<TooltipContent className="rounded-lg border border-slate-200 bg-white px-3 py-2 text-xs font-medium text-neutral-700 shadow-lg">
|
||||||
|
Apenas o responsável atual ou um administrador pode pausar o atendimento.
|
||||||
|
</TooltipContent>
|
||||||
|
) : null}
|
||||||
|
</Tooltip>
|
||||||
|
) : startDisabled ? (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<span className="inline-flex">
|
||||||
|
<Button size="sm" className={startButtonClass} disabled>
|
||||||
|
<IconPlayerPlay className="size-4 text-white" /> Iniciar
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className="rounded-lg border border-slate-200 bg-white px-3 py-2 text-xs font-medium text-neutral-700 shadow-lg">
|
||||||
|
Apenas o responsável atual ou um administrador pode iniciar este atendimento.
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
) : (
|
) : (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
|
|
@ -666,17 +731,10 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
||||||
{editing ? (
|
{editing ? (
|
||||||
<Select
|
<Select
|
||||||
disabled={isManager}
|
disabled={isManager}
|
||||||
value={ticket.assignee?.id ?? ""}
|
value={assigneeSelection}
|
||||||
onValueChange={async (value) => {
|
onValueChange={(value) => {
|
||||||
if (!convexUserId) return
|
|
||||||
if (isManager) return
|
if (isManager) return
|
||||||
toast.loading("Atribuindo responsável...", { id: "assignee" })
|
setAssigneeSelection(value)
|
||||||
try {
|
|
||||||
await changeAssignee({ ticketId: ticket.id as Id<"tickets">, assigneeId: value as Id<"users">, actorId: convexUserId as Id<"users"> })
|
|
||||||
toast.success("Responsável atualizado!", { id: "assignee" })
|
|
||||||
} catch {
|
|
||||||
toast.error("Não foi possível atribuir.", { id: "assignee" })
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger className={selectTriggerClass}>
|
<SelectTrigger className={selectTriggerClass}>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { api } from "@/convex/_generated/api";
|
||||||
import { useCallback, useRef, useState } from "react";
|
import { useCallback, useRef, useState } from "react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Spinner } from "@/components/ui/spinner";
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
import { Upload } from "lucide-react";
|
import { Upload, Check, X, AlertCircle } from "lucide-react";
|
||||||
import { Progress } from "@/components/ui/progress";
|
import { Progress } from "@/components/ui/progress";
|
||||||
|
|
||||||
type Uploaded = { storageId: string; name: string; size?: number; type?: string; previewUrl?: string };
|
type Uploaded = { storageId: string; name: string; size?: number; type?: string; previewUrl?: string };
|
||||||
|
|
@ -26,7 +26,9 @@ export function Dropzone({
|
||||||
const generateUrl = useAction(api.files.generateUploadUrl);
|
const generateUrl = useAction(api.files.generateUploadUrl);
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const [drag, setDrag] = useState(false);
|
const [drag, setDrag] = useState(false);
|
||||||
const [items, setItems] = useState<Array<{ id: string; name: string; progress: number; status: "idle" | "uploading" | "done" | "error" }>>([]);
|
const [items, setItems] = useState<
|
||||||
|
Array<{ id: string; name: string; progress: number; status: "uploading" | "done" | "error" }>
|
||||||
|
>([]);
|
||||||
|
|
||||||
const startUpload = useCallback(async (files: FileList | File[]) => {
|
const startUpload = useCallback(async (files: FileList | File[]) => {
|
||||||
const list = Array.from(files).slice(0, maxFiles);
|
const list = Array.from(files).slice(0, maxFiles);
|
||||||
|
|
@ -55,29 +57,25 @@ export function Dropzone({
|
||||||
const res = JSON.parse(xhr.responseText);
|
const res = JSON.parse(xhr.responseText);
|
||||||
if (res?.storageId) {
|
if (res?.storageId) {
|
||||||
uploaded.push({ storageId: res.storageId, name: file.name, size: file.size, type: file.type, previewUrl: localPreview });
|
uploaded.push({ storageId: res.storageId, name: file.name, size: file.size, type: file.type, previewUrl: localPreview });
|
||||||
setItems((prev) => prev.map((it) => (it.id === id ? { ...it, progress: 100, status: "done" } : it)));
|
setItems((prev) =>
|
||||||
setTimeout(() => {
|
prev.map((it) => (it.id === id ? { ...it, progress: 100, status: "done" } : it))
|
||||||
setItems((prev) => prev.filter((it) => it.id !== id));
|
);
|
||||||
}, 600);
|
|
||||||
} else {
|
} else {
|
||||||
setItems((prev) => prev.map((it) => (it.id === id ? { ...it, status: "error" } : it)));
|
setItems((prev) =>
|
||||||
setTimeout(() => {
|
prev.map((it) => (it.id === id ? { ...it, status: "error" } : it))
|
||||||
setItems((prev) => prev.filter((it) => it.id !== id));
|
);
|
||||||
}, 1200);
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
setItems((prev) => prev.map((it) => (it.id === id ? { ...it, status: "error" } : it)));
|
setItems((prev) =>
|
||||||
setTimeout(() => {
|
prev.map((it) => (it.id === id ? { ...it, status: "error" } : it))
|
||||||
setItems((prev) => prev.filter((it) => it.id !== id));
|
);
|
||||||
}, 1200);
|
|
||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
xhr.onerror = () => {
|
xhr.onerror = () => {
|
||||||
setItems((prev) => prev.map((it) => (it.id === id ? { ...it, status: "error" } : it)));
|
setItems((prev) =>
|
||||||
setTimeout(() => {
|
prev.map((it) => (it.id === id ? { ...it, status: "error" } : it))
|
||||||
setItems((prev) => prev.filter((it) => it.id !== id));
|
);
|
||||||
}, 1200);
|
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
xhr.send(file);
|
xhr.send(file);
|
||||||
|
|
@ -130,15 +128,51 @@ export function Dropzone({
|
||||||
</div>
|
</div>
|
||||||
{items.length > 0 && (
|
{items.length > 0 && (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{items.map((it) => (
|
{items.map((it) => {
|
||||||
<div key={it.id} className="flex items-center justify-between gap-3 rounded-md border p-2 text-sm">
|
const isUploading = it.status === "uploading";
|
||||||
<span className="truncate">{it.name}</span>
|
const isDone = it.status === "done";
|
||||||
<div className="flex min-w-[140px] items-center gap-2">
|
const isError = it.status === "error";
|
||||||
<Progress value={it.progress} className="h-1.5 w-24" />
|
return (
|
||||||
<span className="w-10 text-right text-xs text-neutral-500">{it.progress}%</span>
|
<div key={it.id} className="flex items-center justify-between gap-3 rounded-md border p-2 text-sm">
|
||||||
|
<div className="flex flex-1 items-center gap-3 overflow-hidden">
|
||||||
|
<span className="truncate">{it.name}</span>
|
||||||
|
{isError ? (
|
||||||
|
<span className="inline-flex items-center gap-1 text-xs text-rose-600">
|
||||||
|
<AlertCircle className="size-3.5" /> Falhou
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{isUploading ? (
|
||||||
|
<>
|
||||||
|
<Progress value={it.progress} className="h-1.5 w-24" />
|
||||||
|
<span className="w-10 text-right text-xs text-neutral-500">{it.progress}%</span>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium",
|
||||||
|
isDone ? "bg-emerald-50 text-emerald-700" : "bg-rose-50 text-rose-700"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{isDone ? <Check className="size-3.5" /> : <AlertCircle className="size-3.5" />}
|
||||||
|
{isDone ? "Pronto" : "Erro"}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="inline-flex size-7 items-center justify-center rounded-full border border-slate-200 bg-white text-neutral-600 transition hover:bg-slate-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-300"
|
||||||
|
aria-label="Remover item"
|
||||||
|
onClick={() => setItems((prev) => prev.filter((item) => item.id !== it.id))}
|
||||||
|
>
|
||||||
|
<X className="size-3.5" />
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)
|
||||||
))}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue