Compare commits

...

3 Commits

Author SHA1 Message Date
Hossein Rahmani a190f8c301 Bugs fixed 2024-01-29 13:48:16 +03:30
Hossein Rahmani dc03495f73 a bug fixed 2024-01-28 17:49:49 +03:30
Hossein Rahmani 76e406efc2 Search and pagination bugs fixed 2024-01-28 17:32:06 +03:30
10 changed files with 85 additions and 36 deletions

View File

@ -35,7 +35,7 @@ export default function AdminUserManagement() {
<div className="w-full flex flex-col lg:flex-row justify-center items-center gap-6 "> <div className="w-full flex flex-col lg:flex-row justify-center items-center gap-6 ">
<div className="w-full lg:w-3/5 h-11 bg-white rounded-[5px] block"> <div className="w-full lg:w-3/5 h-11 bg-white rounded-[5px] block">
<Search mode="admin" /> {/* <Search Cancel={} mode="admin" /> */}
</div> </div>
<div className="w-full lg:w-2/5 flex flex-row justify-between items-center gap-2 "> <div className="w-full lg:w-2/5 flex flex-row justify-between items-center gap-2 ">

View File

@ -247,7 +247,7 @@ export default function ComplainsDetails({
</AlertDialog> </AlertDialog>
{getComplaintMutation.data && !getComplaintMutation.isPending ? ( {getComplaintMutation.data && !getComplaintMutation.isPending ? (
<> <>
<button {/* <button
onClick={() => onClick={() =>
router.push("/UserPanel/ControllerDashboard/Complaints") router.push("/UserPanel/ControllerDashboard/Complaints")
} }
@ -257,7 +257,7 @@ export default function ComplainsDetails({
<ArrowRight /> <ArrowRight />
</span> </span>
<p>بازگشت</p> <p>بازگشت</p>
</button> </button> */}
<div className="flex items-start w-full gap-2 mt-2 max-lg:flex-col"> <div className="flex items-start w-full gap-2 mt-2 max-lg:flex-col">
{/* 1 */} {/* 1 */}
@ -277,7 +277,7 @@ export default function ComplainsDetails({
</div> </div>
{/* 2 */} {/* 2 */}
<div className="flex flex-col self-stretch w-full gap-2 rounded-lg lg:w-2/3 "> <div className="flex flex-col self-stretch w-full gap-2 rounded-lg lg:w-2/3 ">
<div className=" bg-[#E9E9E9] rounded-md py-4 px-10 flex flex-col md:flex-row gap-2 items-center justify-center lg:sticky top-28"> <div className=" bg-[#E9E9E9] rounded-md py-4 px-10 flex flex-col md:flex-row gap-2 items-center justify-center">
{data.user == null ? ( {data.user == null ? (
<> <>
<div className="relative flex flex-col w-full p-5 mt-2 border border-gray-400 rounded-md gap-y-1"> <div className="relative flex flex-col w-full p-5 mt-2 border border-gray-400 rounded-md gap-y-1">

View File

@ -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"

View File

@ -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 { X, 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);
};
console.log(value);
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"
>
<X className=" text-gray-600 h-5 w-5" />
</button>
) : (
<button onClick={action} className="absolute left-3">
<CiSearch className="h-4 w-4" />
</button>
)}
{/* <button onClick={action} className="absolute left-3">
<CiSearch /> <CiSearch />
</button> </button> */}
</div> </form>
); );
} }

View File

@ -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);
@ -59,15 +61,23 @@ export default function TabController() {
}); });
const handelSearch = (event: any) => { const handelSearch = (event: any) => {
setPage(1);
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(() => {
@ -77,20 +87,13 @@ export default function TabController() {
setPsblState(Number(activeTab)); setPsblState(Number(activeTab));
} }
}, []); }, []);
console.log(currentPage);
const isZero = totalCount === 0; const isZero = totalCount === 0;
return ( return (
<div className="w-[95vw] lg:w-[82vw] xl:w-[70vw] 3xl:w-[65vw] mt-16 pt-9 mx-auto"> <div className="w-[95vw] lg:w-[82vw] xl:w-[70vw] 3xl:w-[65vw] mt-16 pt-9 mx-auto">
<p className="my-2 text-xs font-bold 3xl:ml-6 sm:text-sm"> <Tabs value={String(selectedTab)} className="" dir="rtl">
لیست شکایت ها <div className="flex flex-col-reverse items-center justify-between w-full gap-4 mb-5 lg:flex-row lg:gap-2">
</p>
<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 */} {/* 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">
{/* <p className="text-xs font-bold 3xl:ml-6 sm:text-sm max-xl:hidden"> {/* <p className="text-xs font-bold 3xl:ml-6 sm:text-sm max-xl:hidden">
@ -108,9 +111,9 @@ 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); setSearch("");
setPage(1);
}} }}
> >
<div className="relative w-full "> <div className="relative w-full ">
@ -127,6 +130,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 +140,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 +154,8 @@ export default function TabController() {
{!isZero ? ( {!isZero ? (
<Pagination <Pagination
TotalPages={totalPages}
currentPage={currentPage - 1}
countPage={totalCount} countPage={totalCount}
Page={(num: number) => setPage(num + 1)} Page={(num: number) => setPage(num + 1)}
/> />

View File

@ -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>

View File

@ -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

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "sootzani", "name": "sootzani",
"version": "0.2.7", "version": "0.2.9",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "sootzani", "name": "sootzani",
"version": "0.2.7", "version": "0.2.9",
"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",

View File

@ -1,6 +1,6 @@
{ {
"name": "sootzani", "name": "sootzani",
"version": "0.2.7", "version": "0.2.9",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev",

View File

@ -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;