Done
This commit is contained in:
parent
5f67441d9d
commit
162194aa18
|
|
@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom'
|
|||
|
||||
|
||||
function useNavigateOnSuccess(isSuccess :boolean , to_path:string , callbackAfterSuccess?:any) {
|
||||
|
||||
|
||||
const navigate = useNavigate()
|
||||
useEffect(()=>{
|
||||
|
||||
|
|
|
|||
|
|
@ -18,17 +18,14 @@ type TViewPage ={
|
|||
|
||||
const ViewPage: React.FC<TViewPage>= ({children,getInitialValues, getValidationSchema,handleSubmit,IsloadingButton})=> {
|
||||
|
||||
const {objectToEdit} = usePageState()
|
||||
const {objectToEdit,setObjectToEdit} = usePageState()
|
||||
const {t} = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
// console.log(BarStatus);
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
|
||||
|
||||
const navigateToParent = () => {
|
||||
navigate(-1)
|
||||
setObjectToEdit({})
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
@ -42,6 +39,7 @@ const ViewPage: React.FC<TViewPage>= ({children,getInitialValues, getValidation
|
|||
<CardBody>
|
||||
{
|
||||
<Formik
|
||||
enableReinitialize
|
||||
onSubmit={handleSubmit}
|
||||
initialValues={getInitialValues(objectToEdit)}
|
||||
validationSchema={getValidationSchema()}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const AddCategoriesPage = () => {
|
|||
|
||||
useNavigateOnSuccess(isSuccess, '/Categories')
|
||||
|
||||
|
||||
|
||||
|
||||
const ViewProps = { getInitialValues, getValidationSchema, handleSubmit,IsloadingButton };
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import useFormatToSelect from '../../../Hooks/useFormatToSelect';
|
|||
function Form() {
|
||||
const {data:Restaurant} = useGetRestaurant()
|
||||
const SelectRestaurantData = useFormatToSelect(Restaurant?.data)
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<Row xs={1} sm={1} md={1} lg={2} xl={2}>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { useGetMeal, useUpdateMeal } from '../../../api/Meal';
|
|||
import useNavigateOnSuccess from '../../../Hooks/useNavigateOnSuccess';
|
||||
import Form from './EditForm';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { isItArrayOfString } from '../../../utils/Array/isItArrayOfString';
|
||||
|
||||
const EditPage = () => {
|
||||
const { setObjectToEdit, objectToEdit } = usePageState()
|
||||
|
|
@ -20,12 +21,20 @@ const EditPage = () => {
|
|||
show:id
|
||||
})
|
||||
const { mutate, isSuccess,isLoading:IsloadingButton } = useUpdateMeal()
|
||||
|
||||
|
||||
|
||||
const handleSubmit = (values: any) => {
|
||||
|
||||
if( typeof values?.image === "string" ){
|
||||
delete values["video"]
|
||||
const data_to_send = {...values}
|
||||
|
||||
if( typeof values?.video === "string" ){
|
||||
delete data_to_send["video"]
|
||||
}
|
||||
mutate({...values, _method : "put"});
|
||||
if(isItArrayOfString(values?.images)){
|
||||
delete data_to_send["images"]
|
||||
}
|
||||
|
||||
mutate(data_to_send);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@ import { useNavigate } from "react-router-dom";
|
|||
import useAuthState from "../../lib/statemangment/AuthState";
|
||||
import { useValidationState } from "../../Components/ValidationField/utils/ValidationState";
|
||||
import { AxiosQueryEnum, AxiosStatusEnum } from "../../enums/Axios";
|
||||
import { usePageState } from "../../lib/statemangment/LayoutPagestate";
|
||||
|
||||
function useAxios() {
|
||||
const { isAuthenticated, token } = useAuthState();
|
||||
|
||||
const { setValidation } = useValidationState((state) => state);
|
||||
const {setObjectToEdit} = usePageState()
|
||||
const [t] = useTranslation();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
|
@ -44,7 +46,9 @@ function useAxios() {
|
|||
queryClient.invalidateQueries(key);
|
||||
toast.success(ResponseMessage);
|
||||
setValidation([{}]);
|
||||
setObjectToEdit({})
|
||||
}
|
||||
|
||||
return response;
|
||||
},
|
||||
function (error) {
|
||||
|
|
|
|||
0
src/utils/Array/Equal.ts
Normal file
0
src/utils/Array/Equal.ts
Normal file
12
src/utils/Array/isItArrayOfString.ts
Normal file
12
src/utils/Array/isItArrayOfString.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
export const isItArrayOfString = (data:any[])=>{
|
||||
if(data?.length < 1){
|
||||
return true
|
||||
}
|
||||
|
||||
const filteredArray = data?.filter((item:any)=>{ return typeof item !== "string"})
|
||||
if(filteredArray?.length < 1){
|
||||
return true
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user