);
};
export default Form;
-
-
-// in this files in my react project i am trying to handle to apis that one for getting student by phone number and check if this number is exist or not and the second file named salesModel for choosing package for this student and third model is for submitting the values and hit the api request but i am facing some problems i think from caching the values
-// first problem if i choose a number and submit it and return successfully if i close the model in second level and try to re do the method from begginning the previous phone number is being cached i mean if ijust type and valid phone number it take me to the next step named salesModel without even hitting a new request for the new phone number
-//
-// second problem if in the 3rd step in submitting the values happen an error it close the model and try to do the method from beggining it happen the same this the phone number is being cached and it does not hit anew request
\ No newline at end of file
diff --git a/src/Pages/ReSeller/Sales/Model/ValidationModelForm.tsx b/src/Pages/ReSeller/Sales/Model/ValidationModelForm.tsx
index c19df46..30700a1 100644
--- a/src/Pages/ReSeller/Sales/Model/ValidationModelForm.tsx
+++ b/src/Pages/ReSeller/Sales/Model/ValidationModelForm.tsx
@@ -1,7 +1,6 @@
import { Col, Row } from "reactstrap";
import ValidationField from "../../../../Components/ValidationField/ValidationField";
import { useFormikContext } from "formik";
-import { useModalState } from "../../../../zustand/Modal";
import { useObjectToEdit } from "../../../../zustand/ObjectToEditState";
import { useTranslation } from "react-i18next";
import { QueryStatusEnum } from "../../../../enums/QueryStatus";
@@ -9,13 +8,13 @@ import { Button, Divider, Spin } from "antd";
import { MdCancel } from "react-icons/md";
import { useEffect, useState } from "react";
import { useGetStudentByPhone } from "../../../../api/sales";
-import { toast } from "react-toastify";
-import { useQueryClient } from "react-query";
-
-const Form = () => {
+import { ModalBodyProps } from "../../../../types/Sales";
+const Form = ({
+ handleCloseModel = () => {},
+}:ModalBodyProps) => {
+
const [ triggerApi, setTriggerApi] = useState(false)
- const { setIsOpen } = useModalState((state) => state);
const { setObjectToEdit } = useObjectToEdit();
const {t} = useTranslation();
@@ -24,12 +23,11 @@ const Form = () => {
const {values,setFieldValue} = useFormikContext()
const phoneNumber : number = values?.phone_number
- const { data,isError,status,isSuccess } = useGetStudentByPhone({
+ const { data, status, isSuccess } = useGetStudentByPhone({
phone_number:phoneNumber,
},{
enabled: triggerApi
});
- const queryClient = useQueryClient();
const handleNext = ()=>{
if(values?.phone_number && phoneNumber.toString().length === 10 ){
@@ -38,14 +36,6 @@ const Form = () => {
}
}
-
- const handleCancel = () => {
- setIsOpen("");
- formik.resetForm();
- setTriggerApi(false);
- setObjectToEdit({});
- queryClient.resetQueries();
- };
useEffect(() => {
if(isSuccess){
@@ -56,23 +46,6 @@ const Form = () => {
}, [isSuccess]);
- // useEffect(() => {
- // if(!!data?.data?.phone_number){
- // // setFieldValue( "currentModalIndex" , values?.currentModalIndex + 1 )
- // setObjectToEdit({data})
- // setTriggerApi(false)
- // }
- // else if(!data?.data){
- // setTriggerApi(false)
- // }
- // if(isError){
- // toast.error(t('toast.phone_number_not_found'))
- // }
- // if(values?.phone_number === null){
- // setTriggerApi(false);
- // }
- // }, [data?.data,triggerApi,isError,status])
-
return (
values?.currentModalIndex == 0 &&