Search and pagination bugs fixed
parent
d10cf03f98
commit
76e406efc2
|
|
@ -5,12 +5,14 @@ import { MdKeyboardArrowRight, MdKeyboardArrowLeft } from "react-icons/md";
|
||||||
import { twMerge } from "tailwind-merge";
|
import { twMerge } from "tailwind-merge";
|
||||||
|
|
||||||
export default function Pagination({
|
export default function Pagination({
|
||||||
|
TotalPages,
|
||||||
currentPage,
|
currentPage,
|
||||||
PageSize,
|
PageSize,
|
||||||
Page,
|
Page,
|
||||||
countPage,
|
countPage,
|
||||||
length,
|
length,
|
||||||
}: {
|
}: {
|
||||||
|
TotalPages?: any;
|
||||||
currentPage?: any;
|
currentPage?: any;
|
||||||
PageSize?: number;
|
PageSize?: number;
|
||||||
Page?: any;
|
Page?: any;
|
||||||
|
|
@ -30,11 +32,15 @@ export default function Pagination({
|
||||||
onPageChange={handlePageClick}
|
onPageChange={handlePageClick}
|
||||||
pageRangeDisplayed={3}
|
pageRangeDisplayed={3}
|
||||||
forcePage={currentPage}
|
forcePage={currentPage}
|
||||||
pageCount={Math.ceil(countPage / (PageSize ? PageSize : 5))}
|
pageCount={
|
||||||
|
TotalPages
|
||||||
|
? TotalPages
|
||||||
|
: Math.ceil(countPage / (PageSize ? PageSize : 5))
|
||||||
|
}
|
||||||
previousLabel={<MdKeyboardArrowRight className="w-5 h-5 " />}
|
previousLabel={<MdKeyboardArrowRight className="w-5 h-5 " />}
|
||||||
pageClassName=" w-10 h-10 grid place-content-center rounded-lg !text-blue shadow-md"
|
pageClassName=" w-10 h-10 grid place-content-center rounded-lg !text-blue shadow-md"
|
||||||
className={twMerge(
|
className={twMerge(
|
||||||
" flex flex-wrap gap-3 text-sm md:text-base w-full rounded-md p-1 bg-white/30 backdrop-blur-lg justify-center text-blue mt-5 absolute left-0 right-0 bottom-6"
|
" flex flex-wrap gap-3 text-sm md:text-base w-full rounded-md p-2 pb-3 bg-white/30 backdrop-blur-lg justify-center fixed text-blue mt-5 left-0 right-0 bottom-0"
|
||||||
)}
|
)}
|
||||||
activeClassName=" bg-blue text-blue shadow-md shadow-main"
|
activeClassName=" bg-blue text-blue shadow-md shadow-main"
|
||||||
activeLinkClassName=" text-white w-full p-1 h-full"
|
activeLinkClassName=" text-white w-full p-1 h-full"
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,50 @@
|
||||||
"use client";
|
"use client";
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect, useRef } from "react";
|
||||||
import { Input } from "./ui/input";
|
import { Input } from "./ui/input";
|
||||||
import { Label } from "./ui/label";
|
import { Label } from "./ui/label";
|
||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
import { CiSearch } from "react-icons/ci";
|
import { CiSearch } from "react-icons/ci";
|
||||||
|
import { XCircle } from "lucide-react";
|
||||||
|
|
||||||
export default function Search({
|
export default function Search({
|
||||||
mode,
|
mode,
|
||||||
value,
|
value,
|
||||||
action,
|
action,
|
||||||
|
Cancel,
|
||||||
changeValue,
|
changeValue,
|
||||||
}: {
|
}: {
|
||||||
mode?: string;
|
mode?: string;
|
||||||
value?: any;
|
value?: any;
|
||||||
action?: (any: any) => any;
|
action?: (any: any) => any;
|
||||||
changeValue?: (any: any) => any ;
|
Cancel: (any: any) => any;
|
||||||
|
changeValue?: (any: any) => any;
|
||||||
}) {
|
}) {
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const [cancel, setCancel] = useState<boolean>(false);
|
||||||
|
const handleSubmit = (e: any) => {
|
||||||
|
console.log(222);
|
||||||
|
e.preventDefault();
|
||||||
|
setCancel(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancelSearch = (e: any) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setCancel(false);
|
||||||
|
if (changeValue !== undefined) {
|
||||||
|
console.log(444);
|
||||||
|
changeValue("");
|
||||||
|
}
|
||||||
|
Cancel(true);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative flex items-center w-full bg-gray-300 lg:w-1/5 rounded-xl">
|
<form
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
className="relative flex items-center w-full bg-gray-300 lg:w-1/5 rounded-xl"
|
||||||
|
>
|
||||||
<Input
|
<Input
|
||||||
// type="search"
|
// type="search"
|
||||||
|
ref={inputRef}
|
||||||
id="default-search"
|
id="default-search"
|
||||||
className={`mb-0 h-8 bg-[#E9E9E9] border-none focus-visible:none rounded-lg
|
className={`mb-0 h-8 bg-[#E9E9E9] border-none focus-visible:none rounded-lg
|
||||||
block w-full min-w-[13rem] text-xs md:text-sm text-black
|
block w-full min-w-[13rem] text-xs md:text-sm text-black
|
||||||
|
|
@ -34,15 +58,28 @@ export default function Search({
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
if (changeValue) {
|
if (changeValue) {
|
||||||
|
setCancel(false);
|
||||||
changeValue(e.target.value);
|
changeValue(e.target.value);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
placeholder="جستجو..."
|
placeholder="جستجو..."
|
||||||
required
|
|
||||||
/>
|
/>
|
||||||
<button onClick={action} className="absolute left-3">
|
{cancel ? (
|
||||||
|
<button
|
||||||
|
onClick={cancelSearch}
|
||||||
|
type="button"
|
||||||
|
className="absolute left-3"
|
||||||
|
>
|
||||||
|
<XCircle className=" text-gray-600" />
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<button onClick={action} className="absolute left-3">
|
||||||
|
<CiSearch />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{/* <button onClick={action} className="absolute left-3">
|
||||||
<CiSearch />
|
<CiSearch />
|
||||||
</button>
|
</button> */}
|
||||||
</div>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,9 @@ export default function TabController() {
|
||||||
const [totalCount, setTotalCount] = useState<any>(0);
|
const [totalCount, setTotalCount] = useState<any>(0);
|
||||||
const [currentPage, setCurrentPage] = useState<any>(0);
|
const [currentPage, setCurrentPage] = useState<any>(0);
|
||||||
const [pageSize, setPageSize] = useState<any>(0);
|
const [pageSize, setPageSize] = useState<any>(0);
|
||||||
|
const [totalPages, setTotalPages] = useState<any>(0);
|
||||||
|
const [cancel, setCancel] = useState<boolean>(false);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [psblState, setPsblState] = useState(0);
|
const [psblState, setPsblState] = useState(0);
|
||||||
|
|
@ -61,13 +63,20 @@ export default function TabController() {
|
||||||
const handelSearch = (event: any) => {
|
const handelSearch = (event: any) => {
|
||||||
refetch();
|
refetch();
|
||||||
};
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
if (cancel) {
|
||||||
|
refetch();
|
||||||
|
}
|
||||||
|
}, [cancel]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
const headersData = JSON.parse(data.headers["x-pagination"]);
|
const headersData = JSON.parse(data.headers["x-pagination"]);
|
||||||
setTotalCount(headersData.TotalCount);
|
setTotalCount(headersData.TotalCount);
|
||||||
|
setTotalPages(headersData.TotalPages);
|
||||||
setCurrentPage(headersData.CurrentPage);
|
setCurrentPage(headersData.CurrentPage);
|
||||||
setPageSize(headersData.PageSize);
|
setPageSize(headersData.PageSize);
|
||||||
|
setCancel(false);
|
||||||
}
|
}
|
||||||
}, [data]);
|
}, [data]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -85,11 +94,7 @@ export default function TabController() {
|
||||||
<p className="my-2 text-xs font-bold 3xl:ml-6 sm:text-sm">
|
<p className="my-2 text-xs font-bold 3xl:ml-6 sm:text-sm">
|
||||||
لیست شکایت ها
|
لیست شکایت ها
|
||||||
</p>
|
</p>
|
||||||
<Tabs
|
<Tabs value={String(selectedTab)} className="" dir="rtl">
|
||||||
value={String(selectedTab)}
|
|
||||||
className=""
|
|
||||||
dir="rtl"
|
|
||||||
>
|
|
||||||
<div className="flex flex-col-reverse items-center justify-between w-full gap-4 mb-10 lg:flex-row lg:gap-2">
|
<div className="flex flex-col-reverse items-center justify-between w-full gap-4 mb-10 lg:flex-row lg:gap-2">
|
||||||
{/* Tab Title */}
|
{/* Tab Title */}
|
||||||
<TabsList className="flex w-full gap-1 h-a max-lg:flex-wrap max lg:w-4/5 md:gap-4 lg:gap-1 p-1">
|
<TabsList className="flex w-full gap-1 h-a max-lg:flex-wrap max lg:w-4/5 md:gap-4 lg:gap-1 p-1">
|
||||||
|
|
@ -108,7 +113,6 @@ export default function TabController() {
|
||||||
setPsblState(item.value);
|
setPsblState(item.value);
|
||||||
setSelectedTab(String(item.value));
|
setSelectedTab(String(item.value));
|
||||||
localStorage.setItem("ActiveTab", String(item.value));
|
localStorage.setItem("ActiveTab", String(item.value));
|
||||||
|
|
||||||
refetch();
|
refetch();
|
||||||
setPage(0);
|
setPage(0);
|
||||||
}}
|
}}
|
||||||
|
|
@ -127,6 +131,7 @@ export default function TabController() {
|
||||||
changeValue={(data: any) => setSearch(data)}
|
changeValue={(data: any) => setSearch(data)}
|
||||||
mode="controller"
|
mode="controller"
|
||||||
action={handelSearch}
|
action={handelSearch}
|
||||||
|
Cancel={() => setCancel(true)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -136,8 +141,8 @@ export default function TabController() {
|
||||||
{data ? (
|
{data ? (
|
||||||
<TableController
|
<TableController
|
||||||
data={data?.data}
|
data={data?.data}
|
||||||
currentPage ={currentPage}
|
currentPage={currentPage}
|
||||||
pageSize ={pageSize}
|
pageSize={pageSize}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
|
|
@ -150,6 +155,7 @@ export default function TabController() {
|
||||||
|
|
||||||
{!isZero ? (
|
{!isZero ? (
|
||||||
<Pagination
|
<Pagination
|
||||||
|
TotalPages={totalPages}
|
||||||
countPage={totalCount}
|
countPage={totalCount}
|
||||||
Page={(num: number) => setPage(num + 1)}
|
Page={(num: number) => setPage(num + 1)}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ export default function TableController({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Table className="border-[1px] border-solid border-muted rounded-md w-full min-w-[40rem] overflow-y-auto scrollbar-thumb-gray-600 scrollbar-track-gray-100 scrollbar-thin">
|
<Table className="border-[1px] border-solid border-muted rounded-md w-full min-w-[40rem] overflow-y-auto scrollbar-thumb-gray-600 scrollbar-track-gray-100 scrollbar-thin mb-20">
|
||||||
{/* <TableCaption>A list of your recent invoices.</TableCaption> */}
|
{/* <TableCaption>A list of your recent invoices.</TableCaption> */}
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
|
@ -110,7 +110,7 @@ export default function TableController({
|
||||||
</TableRow>
|
</TableRow>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
{data.length != 0 &&
|
{/* {data.length != 0 &&
|
||||||
[...Array(5 - data.length)].map(() => {
|
[...Array(5 - data.length)].map(() => {
|
||||||
return (
|
return (
|
||||||
<TableRow
|
<TableRow
|
||||||
|
|
@ -118,7 +118,7 @@ export default function TableController({
|
||||||
className="border border-t-0 border-b-0"
|
className="border border-t-0 border-b-0"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})} */}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||||
className={cn(
|
className={cn(
|
||||||
`flex w-full rounded-md border border-input px-3 py-2 ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50
|
`flex w-full rounded-md border border-input px-3 py-2 ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50
|
||||||
text-black text-opacity-50 text-xs font-normal bg-slate-200 mb-3
|
text-black text-opacity-50 text-xs font-normal bg-slate-200 mb-3
|
||||||
3xl:h-9 h-10 transition-all
|
h-10 transition-all
|
||||||
hover:bg-slate-300 hover:cursor-pointer focus:cursor-auto
|
hover:bg-slate-300 hover:cursor-pointer focus:cursor-auto
|
||||||
focus:outline-4 focus:outline-slate-300 focus:bg-slate-200
|
focus:outline-4 focus:outline-slate-300 focus:bg-slate-200
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "sootzani",
|
"name": "sootzani",
|
||||||
"version": "0.2.7",
|
"version": "0.2.8",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "sootzani",
|
"name": "sootzani",
|
||||||
"version": "0.2.7",
|
"version": "0.2.8",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hookform/resolvers": "^3.3.2",
|
"@hookform/resolvers": "^3.3.2",
|
||||||
"@radix-ui/react-alert-dialog": "^1.0.5",
|
"@radix-ui/react-alert-dialog": "^1.0.5",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "sootzani",
|
"name": "sootzani",
|
||||||
"version": "0.2.7",
|
"version": "0.2.8",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ export async function getComplaintsList({
|
||||||
states = 0,
|
states = 0,
|
||||||
TrackingNumber,
|
TrackingNumber,
|
||||||
PageNumber = 1,
|
PageNumber = 1,
|
||||||
PageSize = 5,
|
PageSize = 10,
|
||||||
}: {
|
}: {
|
||||||
states: number;
|
states: number;
|
||||||
TrackingNumber?: string;
|
TrackingNumber?: string;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue