"use client"; import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { ChevronLeft, ChevronRight, RefreshCw } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card"; import { Table, TableHead, TableBody, TableRow, Th, Td, EmptyState } from "@/components/ui/Table"; import { Badge } from "@/components/ui/Badge"; import { Button } from "@/components/ui/Button"; import { formatDate } from "@/lib/utils"; import api from "@/lib/api"; import type { Task, PaginatedResponse } from "@/types"; const statusVariant: Record = { done: "success", DONE: "success", completed: "success", COMPLETED: "success", in_progress: "default", IN_PROGRESS: "default", pending: "warning", PENDING: "warning", cancelled: "muted", CANCELLED: "muted", }; export default function TasksPage() { const [page, setPage] = useState(1); const { data, isLoading, refetch } = useQuery>({ queryKey: ["tasks", page], queryFn: async () => { const res = await api.get>(`/api/v1/tasks?page=${page}&limit=20`); return res.data; }, }); const tasks = data?.data ?? []; const meta = data?.meta; return (

Tasks

{meta?.total ?? 0} total tasks

All Tasks {isLoading ? ( Array.from({ length: 5 }).map((_, i) => ( {Array.from({ length: 6 }).map((_, j) => ( ))} )) ) : tasks.length === 0 ? ( ) : ( tasks.map((task) => ( )) )}
Title Type Status Assigned To Due Date Linked Ticket
{task.title} {task.type} {task.status} {task.assignedUser ? `${task.assignedUser.firstName} ${task.assignedUser.lastName}` : task.assignedTo ?? "—"} {task.dueDate ? formatDate(task.dueDate) : "—"} {task.ticket?.subject ?? (task.ticketId ? task.ticketId.slice(0, 8) : "—")}
{meta && meta.totalPages > 1 && (

Page {meta.page} of {meta.totalPages}

)}
); }