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 = () => {
|
const navigateToParent = () => {
|
||||||
navigate(-1)
|
navigate(-1)
|
||||||
setObjectToEdit({})
|
if(objectToEdit){
|
||||||
|
setObjectToEdit([])
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -41,7 +43,7 @@ const ViewPage: React.FC<TViewPage>= ({children,getInitialValues, getValidation
|
||||||
<Formik
|
<Formik
|
||||||
enableReinitialize
|
enableReinitialize
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
initialValues={getInitialValues(objectToEdit)}
|
initialValues={getInitialValues(objectToEdit ?? {})}
|
||||||
validationSchema={getValidationSchema()}
|
validationSchema={getValidationSchema()}
|
||||||
>
|
>
|
||||||
{(formik) => (
|
{(formik) => (
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,10 @@ import { Restaurant } from "../../types/item";
|
||||||
|
|
||||||
export const getInitialValues = (objectToEdit: Restaurant ): any => {
|
export const getInitialValues = (objectToEdit: Restaurant ): any => {
|
||||||
|
|
||||||
console.log(objectToEdit,"objectToEdit");
|
|
||||||
|
|
||||||
const slogan: KeyAndValue[] = objectToArray(objectToEdit?.slogan);
|
const slogan: KeyAndValue[] = objectToArray(objectToEdit?.slogan);
|
||||||
const contact_info: KeyAndValue[] = objectToArray(objectToEdit?.contact_info);
|
const contact_info: KeyAndValue[] = objectToArray(objectToEdit?.contact_info);
|
||||||
const categories = objectToEdit?.categories?.map((item:any)=>(item.id)) || null;
|
const categories = objectToEdit?.categories?.map((item:any)=>(item.id)) || null;
|
||||||
console.log(categories,"categories");
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: objectToEdit?.id ?? null,
|
id: objectToEdit?.id ?? null,
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ function useAxios() {
|
||||||
queryClient.invalidateQueries(key);
|
queryClient.invalidateQueries(key);
|
||||||
toast.success(ResponseMessage);
|
toast.success(ResponseMessage);
|
||||||
setValidation([{}]);
|
setValidation([{}]);
|
||||||
setObjectToEdit({})
|
setObjectToEdit([])
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,6 @@ export interface KeyAndValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function objectToArray(obj: Record<string, any>): KeyAndValue[] {
|
export function objectToArray(obj: Record<string, any>): KeyAndValue[] {
|
||||||
|
if(!obj){ return [] }
|
||||||
return Object.keys(obj).map((key: string) => ({ key, value: obj[key] }));
|
return Object.keys(obj).map((key: string) => ({ key, value: obj[key] }));
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user