From 4763e8afbdba558412fa2bc5ecf4ffc2d6ffcf76 Mon Sep 17 00:00:00 2001 From: yasaman Date: Sun, 28 Jan 2024 15:19:22 +0330 Subject: [PATCH] Bugs Fixed + Cleaned Code --- app/components/Landing.tsx | 9 ++-- app/globals.css | 71 +++++++++++++++++++++--------- components/AboutUs.tsx | 1 - components/CitizenLogin.tsx | 2 - components/ComplainsDetails.tsx | 2 +- components/FollowUp.tsx | 11 +---- components/Footer.tsx | 2 +- components/InspectorOperations.tsx | 5 ++- components/Login.tsx | 1 - components/NavbarPanel.tsx | 1 - components/News.tsx | 2 +- components/Pagination.tsx | 12 ++--- components/Profile.tsx | 5 +-- components/ProfileDropDown.tsx | 3 +- components/RequestResult.tsx | 1 - components/RequestStep1.tsx | 3 -- components/RequestStep2.tsx | 9 +--- components/TabController.tsx | 8 +++- components/TableController.tsx | 3 +- components/Verify.tsx | 4 +- hooks/useDecrypt.tsx | 5 --- 21 files changed, 79 insertions(+), 81 deletions(-) diff --git a/app/components/Landing.tsx b/app/components/Landing.tsx index eef1b7c..5cccf6c 100644 --- a/app/components/Landing.tsx +++ b/app/components/Landing.tsx @@ -14,9 +14,9 @@ import Footer from "@/components/Footer"; import { Swiper, SwiperSlide } from "swiper/react"; // Import Swiper styles import "swiper/css"; -import "swiper/css/pagination"; +import 'swiper/css/navigation'; // import required modules -import { Autoplay, Pagination, Navigation } from "swiper/modules"; +import { Autoplay, Navigation } from "swiper/modules"; import { sliderItems } from "@/constants"; import { useQuery } from "@tanstack/react-query"; import { getSliders, getNews } from "@/utils/commonApi"; @@ -47,7 +47,6 @@ export default function Landing() { queryFn: () => getSliders(), refetchOnWindowFocus: false, }); - console.log(data); const { data: NewsData, @@ -66,6 +65,7 @@ export default function Landing() { {data?.length > 0 ? ( <> {data.map((item: any, index: number) => { - console.log(item); return ( getSingleWebContents(title), refetchOnWindowFocus: false, }); - console.log(data); useEffect(() => { refetch(); diff --git a/components/CitizenLogin.tsx b/components/CitizenLogin.tsx index 39b06d2..199f3a3 100644 --- a/components/CitizenLogin.tsx +++ b/components/CitizenLogin.tsx @@ -54,13 +54,11 @@ export default function CitizenLogin() { const loginMutation = useMutation({ mutationFn: logisterCitizen, onSuccess: (res: any | string) => { - console.log(res); router.push("/Verify"); localStorage.setItem("VerifyRole", "citizen"); localStorage.setItem("verificationToken", res); }, onError: (err: any | string) => { - console.log(err); toast(<>{err.response.data.detail}, { className: "!bg-red-500 !text-white", }); diff --git a/components/ComplainsDetails.tsx b/components/ComplainsDetails.tsx index 95386b8..a23865e 100644 --- a/components/ComplainsDetails.tsx +++ b/components/ComplainsDetails.tsx @@ -128,7 +128,7 @@ export default function ComplainsDetails({ const payload = { ...storeData, password: password }; getComplaintMutation.mutate({ Data: payload }); }; - console.log(storeData); + useEffect(() => { useData.persist.rehydrate(); if (state == "FollowResult") { diff --git a/components/FollowUp.tsx b/components/FollowUp.tsx index 145fb49..481d3bc 100644 --- a/components/FollowUp.tsx +++ b/components/FollowUp.tsx @@ -45,12 +45,7 @@ export default function FollowUp() { onSuccess: (res) => { const result = res; - console.log(res); - console.log(result); - - // alert("Success"); - console.log("Success FollowUp"); - + // router.push("/FollowResult"); router.push("/FollowResult", { data: JSON.stringify(result) }); }, @@ -78,9 +73,7 @@ export default function FollowUp() { // // ), // }); - - console.log(data); - + localStorage.setItem("trackingNumber2", data.trackingNumber); localStorage.setItem("password2", data.password); diff --git a/components/Footer.tsx b/components/Footer.tsx index 8bf76c8..3164921 100644 --- a/components/Footer.tsx +++ b/components/Footer.tsx @@ -15,7 +15,7 @@ export default function Footer() { refetchOnWindowFocus: false, }); const fetchedContent = data?.content || ""; - console.log(data); + return ( //
diff --git a/components/InspectorOperations.tsx b/components/InspectorOperations.tsx index 8ee4ac3..000b69c 100644 --- a/components/InspectorOperations.tsx +++ b/components/InspectorOperations.tsx @@ -94,7 +94,6 @@ export default function InspectorOperations({ }); function onSubmit(data: z.infer) { - console.log(data); const formData = new FormData(); formData.append("text", data.text); formData.append("trackingNumber", complaintData.trackingNumber); @@ -122,6 +121,8 @@ export default function InspectorOperations({ placeholder="متن خود را وارد نمایید" className="resize-none bg-white lg:min-h-[20em]" {...field} + // disabled={possibleOperations.length == 0} + readOnly={possibleOperations.length == 0} /> {/* @@ -147,10 +148,10 @@ export default function InspectorOperations({ type="file" onChange={(e) => { field.onChange(e.target.files ? e.target.files : null); - console.log(e.target.files); }} multiple className="bg-white " + disabled={possibleOperations.length == 0} /> diff --git a/components/Login.tsx b/components/Login.tsx index c44fe07..a770baf 100644 --- a/components/Login.tsx +++ b/components/Login.tsx @@ -62,7 +62,6 @@ export default function Login() { onSuccess: (res) => {}, onError: (err: any) => { if (err.response.status == 428) { - console.log(useData); router.push("/Verify"); } }, diff --git a/components/NavbarPanel.tsx b/components/NavbarPanel.tsx index 9722d50..73290a5 100644 --- a/components/NavbarPanel.tsx +++ b/components/NavbarPanel.tsx @@ -12,7 +12,6 @@ export default function NavbarPanel() { setRole(userRole); }, []); - console.log(role); const menus = { Admin: AdminMenuItems, Inspector: ControllerMenuItems, diff --git a/components/News.tsx b/components/News.tsx index e0a2b02..b8e491d 100644 --- a/components/News.tsx +++ b/components/News.tsx @@ -31,7 +31,7 @@ export default function News() { queryKey: ["News"], queryFn: () => getNews(), }); - console.log(data); + return (
diff --git a/components/Pagination.tsx b/components/Pagination.tsx index 5c884b2..5703e4e 100644 --- a/components/Pagination.tsx +++ b/components/Pagination.tsx @@ -25,23 +25,17 @@ export default function Pagination({ // (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; - // console.log(`Loading items from ${itemOffset} to ${endOffset}`); + 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; - console.log( - `User requested page number ${event.selected}, which is offset ${newOffset}` - ); setItemOffset(newOffset); - // console.log(event.selected); - console.log(event); Page(event.selected); }; - console.log(countPage); - // console.log(pageCount, "1111"); + return ( <> {/* */} @@ -55,7 +49,7 @@ export default function Pagination({ previousLabel={} 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 bottom-0 rounded-md p-1 bg-white/30 backdrop-blur-lg justify-center text-blue mt-5" + " 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" )} activeClassName=" bg-blue text-blue shadow-md shadow-main" activeLinkClassName=" text-white w-full p-1 h-full" diff --git a/components/Profile.tsx b/components/Profile.tsx index f275193..05b393a 100644 --- a/components/Profile.tsx +++ b/components/Profile.tsx @@ -68,6 +68,7 @@ export default function Profile() { toast("پروفایل شما با موفقیت ویرایش شد.", { className: "!bg-green-500 !text-white", }); + router.push("/") }, onError: (err: any | string) => { toast(<>{err.response.data.detail}, { @@ -88,13 +89,9 @@ export default function Profile() { } }, [profileData]); - console.log(form.getValues()); - function onSubmit(data: z.infer) { - console.log(data); const strNationalId = String(data.nationalId); const payload = { ...data, nationalId: strNationalId }; - console.log(data); editProfileMutation.mutate(payload); } diff --git a/components/ProfileDropDown.tsx b/components/ProfileDropDown.tsx index db91834..499b464 100644 --- a/components/ProfileDropDown.tsx +++ b/components/ProfileDropDown.tsx @@ -70,7 +70,8 @@ export default function ProfileDropDown() { diff --git a/components/RequestResult.tsx b/components/RequestResult.tsx index d68df69..7ad45e8 100644 --- a/components/RequestResult.tsx +++ b/components/RequestResult.tsx @@ -44,7 +44,6 @@ export default function Result() { queryFn: () => getSingleWebContents(title), refetchOnWindowFocus: false, }); - console.log(data); useEffect(() => { refetch(); diff --git a/components/RequestStep1.tsx b/components/RequestStep1.tsx index f674a8f..a3130b3 100644 --- a/components/RequestStep1.tsx +++ b/components/RequestStep1.tsx @@ -77,7 +77,6 @@ export default function RequestStep1() { resolver: zodResolver(FormSchema), }); if (profileData?.firstName) { - console.log(111); } useEffect(() => { if (profileData) { @@ -87,7 +86,6 @@ export default function RequestStep1() { } }, [profileData]); - console.log(form.getValues()); function onSubmit(data: z.infer) { // toast({ // title: "You submitted the following values:", @@ -99,7 +97,6 @@ export default function RequestStep1() { // }); const strNationalId = String(data.nationalId); const payload = { ...data, nationalId: strNationalId }; - console.log(data); editProfileMutation.mutate(payload); } diff --git a/components/RequestStep2.tsx b/components/RequestStep2.tsx index 576fe62..c9355e1 100644 --- a/components/RequestStep2.tsx +++ b/components/RequestStep2.tsx @@ -162,7 +162,6 @@ export default function RequestStep2() { queryKey: ["Captcha"], queryFn: () => getCaptcha(), }); - // console.log(captchaData); const srcForImage = CaptchaData ? URL.createObjectURL(CaptchaData.data) @@ -367,18 +366,14 @@ export default function RequestStep2() { render={({ field: { onChange }, ...field }) => { // Get current uploadFile value (always watched updated) const uploadFile = form.watch("uploadFile"); - { - console.log(uploadFile); - } + var filenames: string[] | undefined = undefined; if (uploadFile) { // 1. covert to File[] using Array.from const files: File[] = Array.from(uploadFile); // 2. now you can use array methods on files; filenames = files.map((file) => file?.name); - { - console.log(filenames); - } + } return ( diff --git a/components/TabController.tsx b/components/TabController.tsx index ce08ffe..881e1df 100644 --- a/components/TabController.tsx +++ b/components/TabController.tsx @@ -23,6 +23,7 @@ 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(null); @@ -41,7 +42,6 @@ export default function TabController() { refetchOnWindowFocus: false, }); - console.log(data); useEffect(() => { if (data) { const headersData = JSON.parse(data.headers["x-pagination"]); @@ -55,6 +55,12 @@ export default function TabController() { return (
+ + + + setSearch(data)} diff --git a/components/TableController.tsx b/components/TableController.tsx index 630efd9..ab54f11 100644 --- a/components/TableController.tsx +++ b/components/TableController.tsx @@ -52,7 +52,7 @@ interface Complaint { cipherKeyInspector: string; } export default function TableController({ data }: { data: Complaint[] }) { - console.log(data); + const saveData = useData((state) => state.saveData); const [selectedFile, setSelectedFile] = useState(null); const [open, setOpen] = useState(false); @@ -64,7 +64,6 @@ export default function TableController({ data }: { data: Complaint[] }) { const contents = e?.target?.result; // Process the contents of the file here setSelectedFile(contents); - console.log(contents); }; reader.readAsText(file); diff --git a/components/Verify.tsx b/components/Verify.tsx index 321b968..5ff9542 100644 --- a/components/Verify.tsx +++ b/components/Verify.tsx @@ -36,7 +36,7 @@ export default function Verify() { localStorage.setItem("Sootzani_Role", userRole); const justLogin = localStorage.getItem("Sootzani_Login_State"); if (justLogin) { - router.push("/"); + router.push("/Account/Complaints"); localStorage.removeItem("Sootzani_Login_State"); } else { router.push("/RequestStep1"); @@ -50,12 +50,10 @@ export default function Verify() { }); const handelVerify = () => { - console.log(otp); const payload = { otpToken: localStorage.getItem("verificationToken"), verificationCode: otp, }; - console.log(userData); CitizenVerifyMutation.mutate(payload); }; diff --git a/hooks/useDecrypt.tsx b/hooks/useDecrypt.tsx index c42161c..372e3f9 100644 --- a/hooks/useDecrypt.tsx +++ b/hooks/useDecrypt.tsx @@ -29,16 +29,11 @@ dEqG/38xFdYTFEekexcHnT/Vt1MW4/j76vBJHYWuAJU= try { const decryptor = new JSEncrypt(); decryptor.setPrivateKey(privateKey); - console.log(decryptor); - console.log(privateKey); - console.log(encryptedData); const decrypted = decryptor.decrypt( "FLjMFDdOUjeJDhBdTXjqkKDx81H6gWwXxvx0sQHTgDFiUoggMwCoJbn+eruMdjnppksh8zhm3rUPCIKeWe6SEuw1PX1MaKpDvZd7wNphKgWb6pLafTQTxsB0eLmTurYHkvtOyJkMHhdRravaEeoGSKmMeC9G2ahYpVYgobicBAU=" ); - console.log(decrypted); setDecryptedData(decrypted); } catch (error) { - console.log(error); setError(error); } }, [encryptedData]);