chore: trim dashboard tickets and clean references
This commit is contained in:
parent
561b19cf66
commit
7098b70088
560 changed files with 8 additions and 100094 deletions
|
|
@ -1,11 +1,11 @@
|
|||
"use client"
|
||||
|
||||
import { useMemo, useState } from "react"
|
||||
import { useMemo } from "react"
|
||||
import Link from "next/link"
|
||||
import { useQuery } from "convex/react"
|
||||
import { formatDistanceToNow } from "date-fns"
|
||||
import { ptBR } from "date-fns/locale"
|
||||
import { Inbox, ChevronLeft, ChevronRight } from "lucide-react"
|
||||
import { Inbox } from "lucide-react"
|
||||
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
|
|
@ -13,25 +13,16 @@ import { useAuth } from "@/lib/auth-client"
|
|||
import { DEFAULT_TENANT_ID } from "@/lib/constants"
|
||||
import { mapTicketsFromServerList } from "@/lib/mappers/ticket"
|
||||
import type { Ticket } from "@/lib/schemas/ticket"
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardFooter,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { TicketStatusBadge } from "@/components/tickets/status-badge"
|
||||
import { TicketPriorityPill } from "@/components/tickets/priority-pill"
|
||||
|
||||
const PAGE_SIZE = 4
|
||||
const MAX_TICKETS = 3
|
||||
|
||||
export function MyTicketsPanel() {
|
||||
const { convexUserId, isStaff, session } = useAuth()
|
||||
const tenantId = session?.user?.tenantId ?? DEFAULT_TENANT_ID
|
||||
const [page, setPage] = useState(0)
|
||||
const enabled = Boolean(convexUserId && isStaff)
|
||||
const ticketsResult = useQuery(
|
||||
api.tickets.list,
|
||||
|
|
@ -52,9 +43,7 @@ export function MyTicketsPanel() {
|
|||
return parsed
|
||||
}, [ticketsResult])
|
||||
|
||||
const totalPages = Math.max(1, Math.ceil(tickets.length / PAGE_SIZE))
|
||||
const currentPage = Math.min(page, totalPages - 1)
|
||||
const paginated = tickets.slice(currentPage * PAGE_SIZE, currentPage * PAGE_SIZE + PAGE_SIZE)
|
||||
const visibleTickets = tickets.slice(0, MAX_TICKETS)
|
||||
|
||||
return (
|
||||
<Card className="rounded-3xl border border-border/60 shadow-sm">
|
||||
|
|
@ -82,47 +71,22 @@ export function MyTicketsPanel() {
|
|||
</div>
|
||||
) : ticketsResult === undefined ? (
|
||||
<div className="space-y-2">
|
||||
{Array.from({ length: PAGE_SIZE }).map((_, index) => (
|
||||
{Array.from({ length: MAX_TICKETS }).map((_, index) => (
|
||||
<Skeleton key={`mytickets-skeleton-${index}`} className="h-20 w-full rounded-2xl" />
|
||||
))}
|
||||
</div>
|
||||
) : paginated.length === 0 ? (
|
||||
) : visibleTickets.length === 0 ? (
|
||||
<div className="rounded-2xl border border-dashed border-border/60 bg-muted/40 px-4 py-6 text-center text-sm text-muted-foreground">
|
||||
Nenhum ticket atribuído para hoje. Aproveite para ajudar na triagem ou revisar filas em risco.
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{paginated.map((ticket) => (
|
||||
{visibleTickets.map((ticket) => (
|
||||
<TicketRow key={ticket.id} ticket={ticket} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
{enabled && tickets.length > PAGE_SIZE ? (
|
||||
<CardFooter className="flex items-center justify-between border-t border-border/60 px-6 py-4 text-sm text-muted-foreground">
|
||||
<span>
|
||||
Página {currentPage + 1} de {totalPages}
|
||||
</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => setPage((prev) => Math.max(0, prev - 1))}
|
||||
disabled={currentPage === 0}
|
||||
>
|
||||
<ChevronLeft className="size-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => setPage((prev) => Math.min(totalPages - 1, prev + 1))}
|
||||
disabled={currentPage >= totalPages - 1}
|
||||
>
|
||||
<ChevronRight className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</CardFooter>
|
||||
) : null}
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue