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";
|
||||
|
||||
export default function Pagination({
|
||||
TotalPages,
|
||||
currentPage,
|
||||
PageSize,
|
||||
Page,
|
||||
countPage,
|
||||
length,
|
||||
}: {
|
||||
TotalPages?: any;
|
||||
currentPage?: any;
|
||||
PageSize?: number;
|
||||
Page?: any;
|
||||
|
|
@ -30,11 +32,15 @@ export default function Pagination({
|
|||
onPageChange={handlePageClick}
|
||||
pageRangeDisplayed={3}
|
||||
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 " />}
|
||||
pageClassName=" w-10 h-10 grid place-content-center rounded-lg !text-blue shadow-md"
|
||||
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"
|
||||
activeLinkClassName=" text-white w-full p-1 h-full"
|
||||
|
|
|
|||
|
|
@ -1,26 +1,50 @@
|
|||
"use client";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import { Input } from "./ui/input";
|
||||
import { Label } from "./ui/label";
|
||||
import { Button } from "./ui/button";
|
||||
import { CiSearch } from "react-icons/ci";
|
||||
import { XCircle } from "lucide-react";
|
||||
|
||||
export default function Search({
|
||||
mode,
|
||||
value,
|
||||
action,
|
||||
Cancel,
|
||||
changeValue,
|
||||
}: {
|
||||
mode?: string;
|
||||
value?: any;
|
||||
action?: (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 (
|
||||
<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
|
||||
// type="search"
|
||||
ref={inputRef}
|
||||
id="default-search"
|
||||
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
|
||||
|
|
@ -34,15 +58,28 @@ export default function Search({
|
|||
value={value}
|
||||
onChange={(e) => {
|
||||
if (changeValue) {
|
||||
setCancel(false);
|
||||
changeValue(e.target.value);
|
||||
}
|
||||
}}
|
||||
placeholder="جستجو..."
|
||||
required
|
||||
/>
|
||||
{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>
|
||||
</div>
|
||||
)}
|
||||
{/* <button onClick={action} className="absolute left-3">
|
||||
<CiSearch />
|
||||
</button> */}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ export default function TabController() {
|
|||
const [totalCount, setTotalCount] = useState<any>(0);
|
||||
const [currentPage, setCurrentPage] = useState<any>(0);
|
||||
const [pageSize, setPageSize] = useState<any>(0);
|
||||
const [totalPages, setTotalPages] = useState<any>(0);
|
||||
const [cancel, setCancel] = useState<boolean>(false);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
|
|
@ -61,13 +63,20 @@ export default function TabController() {
|
|||
const handelSearch = (event: any) => {
|
||||
refetch();
|
||||
};
|
||||
useEffect(() => {
|
||||
if (cancel) {
|
||||
refetch();
|
||||
}
|
||||
}, [cancel]);
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
const headersData = JSON.parse(data.headers["x-pagination"]);
|
||||
setTotalCount(headersData.TotalCount);
|
||||
setTotalPages(headersData.TotalPages);
|
||||
setCurrentPage(headersData.CurrentPage);
|
||||
setPageSize(headersData.PageSize);
|
||||
setCancel(false);
|
||||
}
|
||||
}, [data]);
|
||||
useEffect(() => {
|
||||
|
|
@ -85,11 +94,7 @@ export default function TabController() {
|
|||
<p className="my-2 text-xs font-bold 3xl:ml-6 sm:text-sm">
|
||||
لیست شکایت ها
|
||||
</p>
|
||||
<Tabs
|
||||
value={String(selectedTab)}
|
||||
className=""
|
||||
dir="rtl"
|
||||
>
|
||||
<Tabs 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">
|
||||
{/* 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">
|
||||
|
|
@ -108,7 +113,6 @@ export default function TabController() {
|
|||
setPsblState(item.value);
|
||||
setSelectedTab(String(item.value));
|
||||
localStorage.setItem("ActiveTab", String(item.value));
|
||||
|
||||
refetch();
|
||||
setPage(0);
|
||||
}}
|
||||
|
|
@ -127,6 +131,7 @@ export default function TabController() {
|
|||
changeValue={(data: any) => setSearch(data)}
|
||||
mode="controller"
|
||||
action={handelSearch}
|
||||
Cancel={() => setCancel(true)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
|
@ -150,6 +155,7 @@ export default function TabController() {
|
|||
|
||||
{!isZero ? (
|
||||
<Pagination
|
||||
TotalPages={totalPages}
|
||||
countPage={totalCount}
|
||||
Page={(num: number) => setPage(num + 1)}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ export default function TableController({
|
|||
|
||||
return (
|
||||
<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> */}
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
|
|
@ -110,7 +110,7 @@ export default function TableController({
|
|||
</TableRow>
|
||||
);
|
||||
})}
|
||||
{data.length != 0 &&
|
||||
{/* {data.length != 0 &&
|
||||
[...Array(5 - data.length)].map(() => {
|
||||
return (
|
||||
<TableRow
|
||||
|
|
@ -118,7 +118,7 @@ export default function TableController({
|
|||
className="border border-t-0 border-b-0"
|
||||
/>
|
||||
);
|
||||
})}
|
||||
})} */}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|||
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
|
||||
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
|
||||
focus:outline-4 focus:outline-slate-300 focus:bg-slate-200
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "sootzani",
|
||||
"version": "0.2.7",
|
||||
"version": "0.2.8",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "sootzani",
|
||||
"version": "0.2.7",
|
||||
"version": "0.2.8",
|
||||
"dependencies": {
|
||||
"@hookform/resolvers": "^3.3.2",
|
||||
"@radix-ui/react-alert-dialog": "^1.0.5",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "sootzani",
|
||||
"version": "0.2.7",
|
||||
"version": "0.2.8",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export async function getComplaintsList({
|
|||
states = 0,
|
||||
TrackingNumber,
|
||||
PageNumber = 1,
|
||||
PageSize = 5,
|
||||
PageSize = 10,
|
||||
}: {
|
||||
states: number;
|
||||
TrackingNumber?: string;
|
||||
|
|
|
|||
Loading…
Reference in New Issue