Compare commits

...

8 Commits

Author SHA1 Message Date
Hossein Rahmani d7e8b21fad Api changed 2024-01-29 23:14:30 +03:30
Hossein Rahmani 3e79297afc a bug fixed 2024-01-29 20:32:38 +03:30
Hossein Rahmani 4397e5141e packages v updated 2024-01-29 20:30:35 +03:30
Hossein Rahmani 13fafbf9a8 Bugs fixed 2024-01-29 20:29:26 +03:30
Hossein Rahmani 525cd00055 Bugs fixed 2024-01-29 12:42:48 +03:30
Hossein Rahmani 8e66dada93 Merge branch 'Kahdooei' 2024-01-29 10:56:32 +03:30
Hossein Rahmani e04ef37a75 Refresh Token bug fixed 2024-01-29 10:55:47 +03:30
Hossein Rahmani e71f4b92dc packages v updated 2024-01-27 15:53:26 +03:30
21 changed files with 291 additions and 168 deletions

2
.env
View File

@ -1 +1 @@
NEXT_PUBLIC_BASE_URL_APP="https://sootzaniapi.shetabdahi.ir/"
NEXT_PUBLIC_BASE_URL_APP="https://oyoonapi.yazd.ir/"

View File

@ -14,7 +14,7 @@ import Footer from "@/components/Footer";
import { Swiper, SwiperSlide } from "swiper/react";
// Import Swiper styles
import "swiper/css";
import 'swiper/css/navigation';
import "swiper/css/navigation";
// import required modules
import { Autoplay, Navigation } from "swiper/modules";
import { sliderItems } from "@/constants";
@ -148,6 +148,9 @@ export default function Landing() {
if (index == 0) {
localStorage.setItem("unknown", "true");
}
if (item.id == 2) {
localStorage.removeItemItem("unknown");
}
}}
>
<p className="text-xs text-center font-medium text-gray hidden group-hover:flex group-hover:text-white">

View File

@ -14,16 +14,21 @@ import { useQuery } from "@tanstack/react-query";
export default function CallUs(props: any) {
const { position, zoom } = props;
const { data, isLoading, isError, refetch } = useQuery({
queryKey: ["WebContents", "CallUs"],
queryFn: () => getSingleWebContents("CallUs"),
refetchOnWindowFocus: false,
});
console.log(data);
const fetchedContent = data?.content || "";
return (
<div className="bg-white dark:bg-gray-900 w-screen">
<div className="bg-white dark:bg-gray-900 pt-8 3xl:w-[60%] w-[80%] ">
<div className="w-full">
{/* <div className="w-full mt-6"> */}
{/* <Map /> */}
{/* </div> */}
<div className="container flex items-center h-[90vh]">
<div dangerouslySetInnerHTML={{ __html: fetchedContent }} />
{/* <div className="container flex items-center h-[90vh]">
<div className="grid gap-8 md:gap-0 grid-cols-1 md:grid-cols-2 md:h-[40vh] h-full w-full lg:px-32 xl:px-52 md:py-8 py-12">
{callUsItems.map((item) => {
return (
@ -59,7 +64,7 @@ export default function CallUs(props: any) {
);
})}
</div>
</div>
</div> */}
</div>
</div>
);

View File

@ -59,6 +59,7 @@ export default function CitizenLogin() {
localStorage.setItem("verificationToken", res);
},
onError: (err: any | string) => {
refetch();
toast(<>{err.response.data.detail}</>, {
className: "!bg-red-500 !text-white",
});
@ -77,7 +78,6 @@ export default function CitizenLogin() {
value: data.captcha,
},
};
refetch();
loginMutation.mutateAsync(payload);
saveData({
phoneNumber: data.phoneNumber,

View File

@ -42,7 +42,7 @@ export default function ComplainsDetails({
const [open, setOpen] = useState<boolean>(
state == "FollowResult" ? false : true
);
const [password, setPassword] = useState<any>(true);
const [password, setPassword] = useState<any>(null);
const router = useRouter();
const storeData = useData((state) => state.data);
let data;
@ -116,6 +116,8 @@ export default function ComplainsDetails({
mutationFn: postComplaintTracking,
onSuccess: (res) => {
setOpen(false);
localStorage.removeItem("trackingNumber2");
localStorage.removeItem("password2");
},
onError: (err: any | string) => {
toast(<>{err.response.data.detail}</>, {
@ -136,11 +138,17 @@ export default function ComplainsDetails({
}
}, []);
if (getComplaintMutation.isSuccess && !Data) {
data = getComplaintMutation.data;
} else {
data = Data;
useEffect(() => {
const tk = localStorage.getItem("trackingNumber2");
const pw = localStorage.getItem("password2");
if (tk && pw) {
getComplaintMutation.mutate({
Data: { trackingNumber: tk, password: pw },
});
}
}, []);
data = getComplaintMutation?.data;
return (
<>
@ -178,9 +186,9 @@ export default function ComplainsDetails({
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
{data ? (
{getComplaintMutation.data && !getComplaintMutation.isPending ? (
<>
{state !== "FollowResult" && (
{/* {state !== "FollowResult" && (
<button
onClick={() => router.push("/Account/Complaints")}
className="flex gap-1 my-2 cursor-pointer text-blue"
@ -190,7 +198,7 @@ export default function ComplainsDetails({
</span>
<p>بازگشت</p>
</button>
)}
)} */}
{/* Editt */}
<div className="flex items-start w-full gap-2 mt-2 max-lg:flex-col">
@ -202,17 +210,20 @@ export default function ComplainsDetails({
انجام عملیات
</p>
<InspectorOperations
updateData={() => getComplaintMutation.mutate(storeData)}
updateData={(payload) =>
getComplaintMutation.mutate({ Data: payload })
}
role={role}
complaintData={data}
password={password}
/>
</div>
</div>
{/* 2 */}
<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">
{data.user == null ? (
<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 ? (
<>
<div className="relative flex flex-col w-full p-5 mt-2 border border-gray-400 rounded-md gap-y-1">
<p className=" absolute -top-3 right-2 bg-[#E9E9E9] px-2 text-sm text-gray-500">

View File

@ -61,14 +61,12 @@ export default function FollowResult() {
},
});
const printableContent = "This is the content to be printed.";
return (
<>
<div className="w-[90vw] sm:w-[90vw] lg:w-[85vw] xl:w-[75vw] 3xl:w-[70vw] pt-6 mx-auto">
{complaintPrintMutation?.data ? (
<>
<button
{/* <button
onClick={() => router.push("/FollowUp")}
className="flex gap-1 cursor-pointer text-blue"
>
@ -76,16 +74,12 @@ export default function FollowResult() {
<ArrowRight />
</span>
<p>بازگشت</p>
</button>
</button> */}
<ComplainsDetails
role="Citizen"
state="FollowResult"
Data={complaintPrintMutation?.data}
/>
</>
) : (
""
)}
</div>
</>
);

View File

@ -38,22 +38,17 @@ export default function InspectorOperations({
complaintData,
role,
updateData,
password,
}: {
complaintData: any;
role: string;
updateData: () => any;
updateData: (data: any) => any;
password?: string;
}) {
const FormSchema = z.object({
text: z
.string({ required_error: "لطفا متن خود را وارد نمایید." })
.min(8, {
message: "Bio must be at least 8 characters.",
})
.max(260, {
message: "Bio must not be longer than 30 characters.",
}),
text: z.string({ required_error: "لطفا متن خود را وارد نمایید." }),
operation: z.string({
required_error: "Please select an email to display.",
required_error: "لطفا نوع عملیات را انتخاب نمایید.",
}),
media: z
.custom<FileList>((val) => val instanceof FileList, "Required")
@ -61,12 +56,7 @@ export default function InspectorOperations({
.refine((files) => files.length <= 5, `Maximum of 5 File are allowed.`)
.nullish(),
});
const password = useData((state) => state.data.password);
const possibleOperations = complaintData?.possibleOperationsWithDescription;
const selectOptions = Operations.filter((item, index) =>
possibleOperations.includes(index)
);
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
@ -79,12 +69,19 @@ export default function InspectorOperations({
const OperationMutation = useMutation({
mutationKey: ["Operation"],
mutationFn:
role == "Inspector" ? OperateByInspector : postComplaintsDetails,
mutationFn: postComplaintsDetails,
onSuccess: (res) => {
toast("عملیات شما با موفقیت انجام شد. ", {
className: "!bg-green-500 !text-white",
});
console.log(complaintData.trackingNumber);
console.log(localStorage.getItem("password2") as string);
updateData({
trackingNumber: complaintData.trackingNumber,
password: password
? password
: (localStorage.getItem("password2") as string),
});
},
onError: (err: any | string) => {
toast(<>{err.response.data.detail}</>, {
@ -98,7 +95,10 @@ export default function InspectorOperations({
formData.append("text", data.text);
formData.append("trackingNumber", complaintData.trackingNumber);
formData.append("Operation", data.operation);
formData.append("password", localStorage.getItem("password2") as string);
formData.append(
"password",
password ? password : (localStorage.getItem("password2") as string)
);
if (data?.media && data?.media?.length > 0) {
for (let i = 0; i < data.media.length; i++) {
formData.append("Medias", data.media[i]);

View File

@ -3,13 +3,13 @@
import React, { useEffect, useState } from "react";
import { Input } from "./ui/input";
import Image from "next/image";
import { menuItems } from "@/constants";
import { authorizedMenuItems, menuItems } from "@/constants";
import Link from "next/link";
import Login from "./Login";
import { Button } from "./ui/button";
import { usePathname } from "next/navigation";
import TopNav from "./TopNav";
import { isAuthorized } from "@/lib/utils";
import { cn, isAuthorized } from "@/lib/utils";
import useToken from "@/store/useToken";
import { DropdownMenu } from "@radix-ui/react-dropdown-menu";
import ProfileDropDown from "./ProfileDropDown";
@ -30,7 +30,7 @@ export default function Navbar() {
setAuth(false);
}
}, [isAuth, token]);
console.log(pathname);
return (
<div className={` left-0 right-0 top-0 z-20 fixed`}>
{/* <TopNav /> */}
@ -53,6 +53,41 @@ export default function Navbar() {
className="fixed z-[100] left-0 shadow-4xl right-0 top-[4rem] p-5 bg-white border-b-2 shadow-md"
>
<ul className="grid gap-2 ">
{auth ? (
<>
{authorizedMenuItems.map((item, idx, array) => {
// const { Icon } = item;
const lastItem = array.length - 1;
return (
<motion.li
initial={{ scale: 0, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
transition={{
type: "spring",
stiffness: 260,
damping: 20,
delay: 0.1 + idx / 10,
}}
key={item.name}
className=" w-full p-[0.08rem] rounded-xl bg-gradient-to-tr from-neutral-800 via-white to-neutral-700"
>
<Link
onClick={() => setOpen((prev) => !prev)}
className={`flex items-center justify-between w-full p-3 rounded-xl text-white
${lastItem === idx ? "bg-yellow" : "bg-blue"} `}
href={item.href}
>
<span className="flex gap-1 text-sm">
{item.name}
</span>
{/* <Icon className="text-xl" /> */}
</Link>
</motion.li>
);
})}
</>
) : (
<>
{menuItems.map((item, idx, array) => {
// const { Icon } = item;
const lastItem = array.length - 1;
@ -83,6 +118,8 @@ export default function Navbar() {
</motion.li>
);
})}
</>
)}
</ul>
</motion.div>
)}
@ -107,17 +144,45 @@ export default function Navbar() {
</div>
</div>
<div className=" flex gap-5 items-center mr-8 max-md:hidden">
{menuItems.map((item, index, array) => {
if (array.length - 1 !== index) {
{auth ? (
<>
{authorizedMenuItems.map((item, index, array) => {
return (
<Link key={item.id} href={item.href}>
<Link
className={cn(
" p-2 rounded-md",
pathname == item.href && "bg-gray-200"
)}
key={item.id}
href={item.href}
>
<div className=" text-sm font-bold">{item.name}</div>
</Link>
);
} else {
return <></>;
})}
</>
) : (
<>
{menuItems.map((item, index, array) => {
if (array.length - 1 !== index) {
return (
<Link
className={cn(
" p-1 rounded-md",
pathname == item.href && "bg-gray-200"
)}
key={item.id}
href={item.href}
>
<div className=" text-sm font-bold p-2">
{item.name}
</div>
</Link>
);
}
})}
</>
)}
</div>
</div>
{auth ? (

View File

@ -6,6 +6,7 @@ import { useQuery } from "@tanstack/react-query";
import Image from "next/image";
import Link from "next/link";
import { convertFullTime } from "@/lib/utils";
import { useRouter } from "next/navigation";
interface News {
id: string;
image: {
@ -27,12 +28,12 @@ interface News {
}
export default function News() {
const router = useRouter();
const { data, isLoading, isError, refetch } = useQuery({
queryKey: ["News"],
queryFn: () => getNews(),
});
return (
<div className="bg-white dark:bg-gray-900 pt-8 3xl:w-[60%] w-[80%] ">
<h2 className=" w-full font-bold mb-2">اخبار</h2>
@ -44,8 +45,9 @@ export default function News() {
return (
<div
key={item.id}
onClick={() => router.push(`/News/${item.id}`)}
className="w-full lg:w-[48%] border rounded-lg flex flex-row shadow-md hover:shadow-none transition-all
h-[20em] sm:h-[15em] max-sm:flex-col max-sm:gap-[3px]"
h-[20em] sm:h-[15em] max-sm:flex-col max-sm:gap-[3px] cursor-pointer"
>
<div className="w-1/2 h-full rounded-r-lg max-sm:h-1/2 max-md:w-1/3 max-sm:w-full">
<Image

View File

@ -7,49 +7,38 @@ import { twMerge } from "tailwind-merge";
const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
export default function Pagination({
itemsPerPage,
TotalPages,
currentPage,
PageSize,
Page,
countPage,
length,
}: {
itemsPerPage?: any;
TotalPages?: any;
currentPage?: any;
PageSize?: number;
Page?: any;
countPage?: any;
length?: any;
}) {
// Here we use item offsets; we could also use page offsets
// following the API or data you're working with.
const [itemOffset, setItemOffset] = useState(0);
// Simulate fetching items from another resources.
// (This could be items from props; or items loaded in a local state
// from an API endpoint with useEffect and useState)
const endOffset = itemOffset + itemsPerPage;
const currentItems = items.slice(itemOffset, endOffset);
const pageCount = Math.ceil(items.length / itemsPerPage);
// Invoke when user click to request another page.
const handlePageClick = (event: any) => {
const newOffset = (event.selected * itemsPerPage) % items.length;
setItemOffset(newOffset);
Page(event.selected);
};
return (
<>
{/* <Items currentItems={currentItems} /> */}
<ReactPaginate
breakLabel="..."
onPageActive={(e) => console.log(e)}
nextLabel={<MdKeyboardArrowLeft className="w-5 h-5 " />}
onPageChange={handlePageClick}
pageRangeDisplayed={3}
pageCount={Math.ceil(countPage / 5)}
forcePage={currentPage}
pageCount={TotalPages}
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 text-blue mt-5 fixed left-0 right-0 bottom-0"
)}
activeClassName=" bg-blue text-blue shadow-md shadow-main"
activeLinkClassName=" text-white w-full p-1 h-full"

View File

@ -63,15 +63,25 @@ export default function ProfileDropDown() {
saveToken(false);
deleteCookie("Sootzani_Refresh_Token");
deleteCookie("Sootzani_Token");
localStorage.removeItem("password2");
localStorage.removeItem("trackingNumber2");
router.push("/");
};
const saveToken = useToken((state) => state.saveToken);
return (
<DropdownMenu dir="rtl">
<DropdownMenuTrigger className=" max-sm:-mr-8 max-sm:text-xs" asChild>
<Button variant="outline">
<DropdownMenuTrigger
className=" max-sm:-mr-8 max-sm:text-xs w-12"
asChild
>
<Button variant="outline" className=" truncate w-32 grid place-content-center">
{/* {profileData?.title ? profileData?.title : profileData?.userName} */}
{profileData?.firstName || profileData?.lastName ? profileData?.firstName +" "+ profileData?.lastName : profileData?.userName}
<p className=" truncate w-full">
{" "}
{profileData?.firstName || profileData?.lastName
? profileData?.firstName + " " + profileData?.lastName
: profileData?.userName}
</p>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56 sm:ml-10">

View File

@ -111,7 +111,7 @@ export default function Result() {
onClick={handlePrint}
className="w-full sm:w-fit bg-blue text-white p-2 rounded-xl text-center "
>
پرینت درخواست
پرینت
</Button>
</div>
{/* <Image

View File

@ -116,9 +116,11 @@ export default function RequestStep2() {
onSuccess: (res) => {
localStorage.setItem("trackingNumber", res.trackingNumber);
localStorage.setItem("password", res.password);
localStorage.removeItem("unknown");
router.push("/RequestResult");
},
onError: (err: any | string) => {
refetch();
toast(<>{err.response.data.detail}</>, {
className: "!bg-red-500 !text-white",
});
@ -133,9 +135,11 @@ export default function RequestStep2() {
localStorage.setItem("password", res.password);
localStorage.setItem("registeredAt", res.registeredAt);
localStorage.removeItem("authorized");
localStorage.removeItem("unknown");
router.push("/RequestResult");
},
onError: (err: any | string) => {
refetch();
toast(<>{err.response.data.detail}</>, {
className: "!bg-red-500 !text-white",
});
@ -204,7 +208,6 @@ export default function RequestStep2() {
});
}
refetch();
resetField("Title");
resetField("Text");
resetField("Medias");
@ -373,7 +376,6 @@ export default function RequestStep2() {
const files: File[] = Array.from(uploadFile);
// 2. now you can use array methods on files;
filenames = files.map((file) => file?.name);
}
return (

View File

@ -29,6 +29,9 @@ export default function TabController() {
const [selectedFile, setSelectedFile] = useState<any>(null);
const [page, setPage] = useState<any>(1);
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 router = useRouter();
const [search, setSearch] = useState<any>(null);
@ -46,6 +49,9 @@ export default function TabController() {
if (data) {
const headersData = JSON.parse(data.headers["x-pagination"]);
setTotalCount(headersData.TotalCount);
setTotalPages(headersData.TotalPages);
setCurrentPage(headersData.CurrentPage);
setPageSize(headersData.PageSize);
}
}, [data]);
@ -55,11 +61,15 @@ export default function TabController() {
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
onClick={() => {
router.push("/RequestStep2");
localStorage.removeItemItem("unknown");
}}
className=" bg-blue hover:bg-blue/90 rounded-lg max-sm:text-xs"
>
ثبت درخواست
</Button>
</Link>
<Search
value={search}
@ -69,6 +79,8 @@ export default function TabController() {
/>
<TableController data={data?.data} />
<Pagination
TotalPages={totalPages}
currentPage={currentPage - 1}
countPage={totalCount}
Page={(num: number) => setPage(num + 1)}
/>

View File

@ -21,7 +21,7 @@ import {
} from "@/components/ui/dialog";
import { ControllerTableItems } from "@/constants";
import Link from "next/link";
import { Decrypt, convertDate } from "@/lib/utils";
import { Decrypt, convertDate, convertFullTime } from "@/lib/utils";
import useData from "@/store/useData";
import { Label } from "./ui/label";
import { Input } from "./ui/input";
@ -71,13 +71,14 @@ export default function TableController({ data }: { data: Complaint[] }) {
return (
<div>
<Table className="border-[1px] border-solid border-muted rounded-md ">
<Table className="border-[1px] border-solid border-muted rounded-md mb-20">
{/* <TableCaption>A list of your recent invoices.</TableCaption> */}
<TableHeader>
<TableRow>
<TableHead>ردیف</TableHead>
<TableHead>تاریخ</TableHead>
<TableHead>کد پیگیری</TableHead>
<TableHead>تاریخ ثبت</TableHead>
<TableHead>تاریخ آخرین تغییر</TableHead>
<TableHead>موضوع</TableHead>
<TableHead>وضعیت</TableHead>
<TableHead>دستگاه مربوطه</TableHead>
@ -104,25 +105,27 @@ export default function TableController({ data }: { data: Complaint[] }) {
<TableCell className="w-1/12 font-medium ">
{index + 1}
</TableCell>
<TableCell className="w-1/12">{item.trackingNumber}</TableCell>
<TableCell className="w-2/12">
{convertDate(item.registeredAt)}
{convertFullTime(item.registeredAt)}
</TableCell>
<TableCell className="w-2/12">{item.trackingNumber}</TableCell>
<TableCell className="w-2/12">
{convertFullTime(item.lastChanged)}
</TableCell>
<TableCell className="w-1/12">
{item?.title ? item.title : "-"}
</TableCell>
<TableCell className="w-2/12">
<TableCell className="w-3/12">
{item?.statusWithDescription
? item.statusWithDescription.description
: "-"}
</TableCell>
<TableCell className="w-3/12">
<TableCell className="w-4/12">
{item?.complaintOrganization
? item?.complaintOrganization.title
: "-"}
</TableCell>
{/* </Link> */}
</TableRow>
);
})}

View File

@ -5,12 +5,20 @@ import bgimg from "../public/img/bg.png";
export const menuItems = [
{ id: 1, name: "صفحه اصلی", href: "/" },
{ id: 2, name: "اخبار", href: "/News" },
{ id: 3, name: "تماس با ما", href: "/CallUs" },
{ id: 4, name: "پیگیری", href: "/FollowUp" },
{ id: 2, name: "پیگیری", href: "/FollowUp" },
{ id: 3, name: "اخبار", href: "/News" },
{ id: 4, name: "تماس با ما", href: "/CallUs" },
{ id: 5, name: "ورود به پنل کاربری", href: "/Login" },
];
export const authorizedMenuItems = [
{ id: 1, name: "صفحه اصلی", href: "/" },
{ id: 2, name: "پیگیری", href: "/FollowUp" },
{ id: 3, name: "درخواست های من", href: "/Account/Complaints" },
{ id: 4, name: "اخبار", href: "/News" },
{ id: 5, name: "تماس با ما", href: "/CallUs" },
];
export const sliderItems = [
{ id: 1, img: bgimg },
{ id: 2, img: bgimg },

View File

@ -2,7 +2,7 @@
const nextConfig = {
output: "standalone",
images: {
domains: ["sootzaniapi.shetabdahi.ir"],
domains: ["sootzaniapi.shetabdahi.ir", "oyoonapi.yazd.ir"],
},
};

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "sootzani",
"version": "0.1.8",
"version": "0.1.13",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sootzani",
"version": "0.1.8",
"version": "0.1.13",
"dependencies": {
"@hookform/resolvers": "^3.3.2",
"@radix-ui/react-alert-dialog": "^1.0.5",

View File

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

View File

@ -7,27 +7,46 @@ import {
} from "cookies-next";
axios.defaults.baseURL = process.env.NEXT_PUBLIC_BASE_URL_APP;
let isRefreshing = false;
axios.interceptors.response.use(
(response) => {
return response;
},
async function (error) {
console.log(error);
const originalRequest = error.config;
if (error.response.status === 401) {
if (!originalRequest._retry) {
originalRequest._retry = true;
const accessToken = getCookie("Sootzani_Token");
const refreshToken = getCookie("Sootzani_Refresh_Token");
if (accessToken && refreshToken && !isRefreshing) {
isRefreshing = true;
try {
// Perform token refresh
const data = await RefreshToken({
token: accessToken,
refreshToken: refreshToken,
});
// Retry the original request
return axios(originalRequest);
} catch (refreshError) {
console.error("Token refresh failed", refreshError);
// Handle refresh error, e.g., redirect to login page
return Promise.reject(refreshError);
} finally {
isRefreshing = false;
}
// if (error.response.status === 403 && !originalRequest._retry) {
// originalRequest._retry = true;
// const access_token = await refreshAccessToken();
// axios.defaults.headers.common["Authorization"] = "Bearer " + access_token;
// return axiosApiInstance(originalRequest);
// }
}
}
}
// For other errors or if refresh token logic is not applicable
return Promise.reject(error);
}
);

View File

@ -48,7 +48,7 @@ export async function getComplaints({
states = 0,
TrackingNumber,
PageNumber = 1,
PageSize = 5,
PageSize = 10,
}: {
states?: number;
TrackingNumber?: string;