From e41db9c1740a7ce04d72020903d2a80d7352e2ae Mon Sep 17 00:00:00 2001 From: karimaldeen Date: Tue, 4 Jun 2024 11:03:55 +0300 Subject: [PATCH] fix_object_to_edit_error --- src/Layout/Dashboard/ViewPage.tsx | 6 ++++-- src/Pages/Setting/formUtil.ts | 4 +--- src/api/helper/useAxios.ts | 2 +- src/utils/object/objectToArray.ts | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Layout/Dashboard/ViewPage.tsx b/src/Layout/Dashboard/ViewPage.tsx index 3c84747..85a61b4 100644 --- a/src/Layout/Dashboard/ViewPage.tsx +++ b/src/Layout/Dashboard/ViewPage.tsx @@ -25,7 +25,9 @@ const ViewPage: React.FC= ({children,getInitialValues, getValidation const navigateToParent = () => { navigate(-1) - setObjectToEdit({}) + if(objectToEdit){ + setObjectToEdit([]) + } }; return ( @@ -41,7 +43,7 @@ const ViewPage: React.FC= ({children,getInitialValues, getValidation {(formik) => ( diff --git a/src/Pages/Setting/formUtil.ts b/src/Pages/Setting/formUtil.ts index 5338671..b1e2709 100644 --- a/src/Pages/Setting/formUtil.ts +++ b/src/Pages/Setting/formUtil.ts @@ -5,13 +5,11 @@ import { Restaurant } from "../../types/item"; export const getInitialValues = (objectToEdit: Restaurant ): any => { - - console.log(objectToEdit,"objectToEdit"); + const slogan: KeyAndValue[] = objectToArray(objectToEdit?.slogan); const contact_info: KeyAndValue[] = objectToArray(objectToEdit?.contact_info); const categories = objectToEdit?.categories?.map((item:any)=>(item.id)) || null; - console.log(categories,"categories"); return { id: objectToEdit?.id ?? null, diff --git a/src/api/helper/useAxios.ts b/src/api/helper/useAxios.ts index 2929e9a..d7d2b80 100644 --- a/src/api/helper/useAxios.ts +++ b/src/api/helper/useAxios.ts @@ -46,7 +46,7 @@ function useAxios() { queryClient.invalidateQueries(key); toast.success(ResponseMessage); setValidation([{}]); - setObjectToEdit({}) + setObjectToEdit([]) } return response; diff --git a/src/utils/object/objectToArray.ts b/src/utils/object/objectToArray.ts index c75d5a3..4c9d98d 100644 --- a/src/utils/object/objectToArray.ts +++ b/src/utils/object/objectToArray.ts @@ -4,5 +4,6 @@ export interface KeyAndValue { } export function objectToArray(obj: Record): KeyAndValue[] { + if(!obj){ return [] } return Object.keys(obj).map((key: string) => ({ key, value: obj[key] })); } \ No newline at end of file