78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
"use client";
|
||
import React, { useEffect, useState } from "react";
|
||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||
import TableController from "./TableController";
|
||
import Search from "./Search";
|
||
import { useQuery } from "@tanstack/react-query";
|
||
import { getComplaintsList } from "@/utils/inspectorApi";
|
||
import { Button } from "@/components/ui/button";
|
||
import {
|
||
Dialog,
|
||
DialogClose,
|
||
DialogContent,
|
||
DialogDescription,
|
||
DialogFooter,
|
||
DialogHeader,
|
||
DialogTitle,
|
||
DialogTrigger,
|
||
} from "@/components/ui/dialog";
|
||
import { Input } from "./ui/input";
|
||
import { useRouter } from "next/navigation";
|
||
import { Decrypt } from "@/lib/utils";
|
||
import useData from "@/store/useData";
|
||
import { toast } from "sonner";
|
||
import { getComplaints } from "@/utils/citizenApi";
|
||
import Pagination from "./Pagination";
|
||
import Link from "next/link";
|
||
export default function TabController() {
|
||
const saveData = useData((state) => state.saveData);
|
||
const [selectedFile, setSelectedFile] = useState<any>(null);
|
||
const [page, setPage] = useState<any>(1);
|
||
const [totalCount, setTotalCount] = useState<any>(0);
|
||
const router = useRouter();
|
||
const [search, setSearch] = useState<any>(null);
|
||
|
||
const { data, isLoading, refetch } = useQuery({
|
||
queryKey: ["CitizenList", page],
|
||
queryFn: () =>
|
||
getComplaints({
|
||
TrackingNumber: search,
|
||
PageNumber: page,
|
||
}),
|
||
refetchOnWindowFocus: false,
|
||
});
|
||
|
||
useEffect(() => {
|
||
if (data) {
|
||
const headersData = JSON.parse(data.headers["x-pagination"]);
|
||
setTotalCount(headersData.TotalCount);
|
||
}
|
||
}, [data]);
|
||
|
||
const handelSearch = (event: any) => {
|
||
refetch();
|
||
};
|
||
|
||
return (
|
||
<div className="w-[95vw] lg:w-[82vw] xl:w-[70vw] 3xl:w-[65vw] mt-16 pt-9">
|
||
<Link href="/RequestStep2">
|
||
<Button className=" bg-blue hover:bg-blue/90 rounded-lg max-sm:text-xs">
|
||
ثبت درخواست
|
||
</Button>
|
||
</Link>
|
||
|
||
<Search
|
||
value={search}
|
||
changeValue={(data: any) => setSearch(data)}
|
||
mode="controller"
|
||
action={handelSearch}
|
||
/>
|
||
<TableController data={data?.data} />
|
||
<Pagination
|
||
countPage={totalCount}
|
||
Page={(num: number) => setPage(num + 1)}
|
||
/>
|
||
</div>
|
||
);
|
||
}
|