From 19f1031c37526b8ffb331aa5b81e2e6f8dc2f825 Mon Sep 17 00:00:00 2001 From: Hossein Rahmani Date: Tue, 23 Jan 2024 10:07:54 +0330 Subject: [PATCH] Response Errors handled + ProgressBar added --- app/layout.tsx | 3 +- components/AdminCategories.tsx | 92 +++++++++++++---------------- components/AdminKeysManagement.tsx | 73 ++++++++++------------- components/AdminNews.tsx | 93 +++++++++++++----------------- components/AdminOrganizations.tsx | 85 ++++++++++++--------------- components/AdminSlider.tsx | 93 +++++++++++++----------------- components/AdminWebContents.tsx | 46 +++++++-------- components/ComplainsDetails.tsx | 42 ++++++++------ components/InspectorOperations.tsx | 22 ++++--- components/Login.tsx | 4 +- components/PrograssBar.tsx | 19 ++++++ components/Search.tsx | 30 +++++++--- components/TabController.tsx | 41 +++++++------ components/Verify.tsx | 57 ++++++++---------- package-lock.json | 9 +++ package.json | 1 + utils/authenticateApi.ts | 4 +- utils/inspectorApi.ts | 14 +++-- 18 files changed, 356 insertions(+), 372 deletions(-) create mode 100644 components/PrograssBar.tsx diff --git a/app/layout.tsx b/app/layout.tsx index b5718d6..22aa2d6 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -8,6 +8,7 @@ import Provider from "../utils/Provider"; import { Toaster as SonnerToaster } from "@/components/ui/sonner"; const inter = Inter({ subsets: ["latin"] }); import { Suspense } from "react"; +import ProgressBarProviders from "@/components/PrograssBar"; export const metadata: Metadata = { title: "عیون", @@ -24,7 +25,7 @@ export default function RootLayout({ {/* }>{children} */} - {children} + {children} diff --git a/components/AdminCategories.tsx b/components/AdminCategories.tsx index 6b37d9c..3b5f4b7 100644 --- a/components/AdminCategories.tsx +++ b/components/AdminCategories.tsx @@ -89,7 +89,7 @@ export default function AdminCategories() { queryKey: ["CategoriesList"], queryFn: () => GetAllCategories(), // refetchOnWindowFocus: false, - }); + }); // Edit const handleClickEdit = (id: string, title: string, description: string) => { @@ -149,14 +149,9 @@ export default function AdminCategories() { className: "!bg-green-500 !text-white", }); }, - onError: (error) => { - console.log(error); - console.log(error?.message); - - setOpenEdit(false); - - toast(error?.message, { - className: "!bg-red-500 !text-black", + onError: (err: any | string) => { + toast(<>{err.response.data.detail}, { + className: "!bg-red-500 !text-white", }); }, }); @@ -174,12 +169,9 @@ export default function AdminCategories() { className: "!bg-green-500 !text-white", }); }, - onError: (error) => { - console.log(error); - console.log(error?.message); - - toast(error?.message, { - className: "!bg-red-500 !text-black", + onError: (err: any | string) => { + toast(<>{err.response.data.detail}, { + className: "!bg-red-500 !text-white", }); }, }); @@ -200,14 +192,9 @@ export default function AdminCategories() { className: "!bg-green-500 !text-white", }); }, - onError: (error) => { - console.log(error); - console.log(error?.message); - - setOpenAdd(false); - - toast(error?.message, { - className: "!bg-red-500 !text-black", + onError: (err: any | string) => { + toast(<>{err.response.data.detail}, { + className: "!bg-red-500 !text-white", }); }, }); @@ -219,20 +206,20 @@ export default function AdminCategories() { title: data.titleCat, description: data.description, }, - }); + }); } function onSubmitAdd(data: AddCatFormValues) { AddCatMutation.mutate({ title: data.titleCategory, description: data.description, - }); + }); } return (
-
+
{/* 1 */} -
+
لیست دسته بندی ها
{/* 2 */} @@ -243,7 +230,7 @@ export default function AdminCategories() { - + بستن
@@ -335,7 +322,7 @@ export default function AdminCategories() {
-
+
@@ -343,7 +330,7 @@ export default function AdminCategories() {

تغییر دسته بندی

- + @@ -352,20 +339,20 @@ export default function AdminCategories() {
( - + عنوان @@ -377,12 +364,12 @@ export default function AdminCategories() { control={formEdit.control} name="description" render={({ field }) => ( - + توضیحات