fix_object_to_edit_error
This commit is contained in:
parent
162194aa18
commit
e41db9c174
|
|
@ -25,7 +25,9 @@ const ViewPage: React.FC<TViewPage>= ({children,getInitialValues, getValidation
|
|||
|
||||
const navigateToParent = () => {
|
||||
navigate(-1)
|
||||
setObjectToEdit({})
|
||||
if(objectToEdit){
|
||||
setObjectToEdit([])
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
@ -41,7 +43,7 @@ const ViewPage: React.FC<TViewPage>= ({children,getInitialValues, getValidation
|
|||
<Formik
|
||||
enableReinitialize
|
||||
onSubmit={handleSubmit}
|
||||
initialValues={getInitialValues(objectToEdit)}
|
||||
initialValues={getInitialValues(objectToEdit ?? {})}
|
||||
validationSchema={getValidationSchema()}
|
||||
>
|
||||
{(formik) => (
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ function useAxios() {
|
|||
queryClient.invalidateQueries(key);
|
||||
toast.success(ResponseMessage);
|
||||
setValidation([{}]);
|
||||
setObjectToEdit({})
|
||||
setObjectToEdit([])
|
||||
}
|
||||
|
||||
return response;
|
||||
|
|
|
|||
|
|
@ -4,5 +4,6 @@ export interface KeyAndValue {
|
|||
}
|
||||
|
||||
export function objectToArray(obj: Record<string, any>): KeyAndValue[] {
|
||||
if(!obj){ return [] }
|
||||
return Object.keys(obj).map((key: string) => ({ key, value: obj[key] }));
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user