fix cache bug in sales page and some fixes
This commit is contained in:
parent
f053952b5f
commit
5f0624f20d
|
|
@ -10,8 +10,11 @@ const AddModel: React.FC = () => {
|
||||||
const { mutate, status } = useAddStudent();
|
const { mutate, status } = useAddStudent();
|
||||||
|
|
||||||
const handleSubmit = (values: any) => {
|
const handleSubmit = (values: any) => {
|
||||||
|
console.log(values);
|
||||||
|
|
||||||
mutate({
|
mutate({
|
||||||
...values,
|
...values,
|
||||||
|
grade_id:values.grade_id?.id
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ const EditModel: React.FC = () => {
|
||||||
getValidationSchema={getValidationSchema}
|
getValidationSchema={getValidationSchema}
|
||||||
isAddModal={false}
|
isAddModal={false}
|
||||||
>
|
>
|
||||||
<ModelForm />
|
<ModelForm isEdit={true} />
|
||||||
</LayoutModel>
|
</LayoutModel>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ const Form = ({ isEdit = false }: { isEdit?: boolean }) => {
|
||||||
{ name: "male", id: "male" },
|
{ name: "male", id: "male" },
|
||||||
{ name: "female", id: "female" },
|
{ name: "female", id: "female" },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row className="w-100">
|
<Row className="w-100">
|
||||||
<Col>
|
<Col>
|
||||||
|
|
@ -32,25 +34,28 @@ const Form = ({ isEdit = false }: { isEdit?: boolean }) => {
|
||||||
placeholder="last_name"
|
placeholder="last_name"
|
||||||
label="last_name"
|
label="last_name"
|
||||||
/>
|
/>
|
||||||
|
{!isEdit && (
|
||||||
|
<>
|
||||||
<ValidationField
|
<ValidationField
|
||||||
name="username"
|
name="username"
|
||||||
placeholder="username"
|
placeholder="username"
|
||||||
label="username"
|
label="username"
|
||||||
/>
|
/>
|
||||||
{!isEdit && (
|
|
||||||
<ValidationField
|
<ValidationField
|
||||||
name="password"
|
name="password"
|
||||||
placeholder="password"
|
placeholder="password"
|
||||||
label="password"
|
label="password"
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</Col>
|
|
||||||
<Col>
|
|
||||||
<ValidationField
|
<ValidationField
|
||||||
name="phone_number"
|
name="phone_number"
|
||||||
placeholder="contact_number1"
|
placeholder="contact_number1"
|
||||||
label="contact_number1"
|
label="contact_number1"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Col>
|
||||||
|
<Col>
|
||||||
<ValidationField
|
<ValidationField
|
||||||
searchBy="GradeName"
|
searchBy="GradeName"
|
||||||
name="grade_id"
|
name="grade_id"
|
||||||
|
|
|
||||||
60
src/Pages/Admin/Student/Model/ModelFormEdit.tsx
Normal file
60
src/Pages/Admin/Student/Model/ModelFormEdit.tsx
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
import { Col, Row } from "reactstrap";
|
||||||
|
import ValidationField from "../../../../Components/ValidationField/ValidationField";
|
||||||
|
import { useGetAllGrade } from "../../../../api/grade";
|
||||||
|
import { useValidationValidationParamState } from "../../../../Components/ValidationField/state/ValidationValidationParamState";
|
||||||
|
import { useObjectToEdit } from "../../../../zustand/ObjectToEditState";
|
||||||
|
|
||||||
|
const Form = ({ isEdit = false }: { isEdit?: boolean }) => {
|
||||||
|
const { ValidationParamState } = useValidationValidationParamState();
|
||||||
|
const { GradeName, GradeCurrentPage } = ValidationParamState;
|
||||||
|
|
||||||
|
const { data: Grade, isLoading: isLoadingGrade } = useGetAllGrade({
|
||||||
|
name: GradeName,
|
||||||
|
page: GradeCurrentPage,
|
||||||
|
});
|
||||||
|
const { objectToEdit } = useObjectToEdit((state) => state);
|
||||||
|
const GradeOption = Grade?.data ?? [];
|
||||||
|
const canChangeGradePage = !!Grade?.links?.next;
|
||||||
|
const GradePage = Grade?.meta?.current_page;
|
||||||
|
|
||||||
|
const sex = [
|
||||||
|
{ name: "male", id: "male" },
|
||||||
|
{ name: "female", id: "female" },
|
||||||
|
];
|
||||||
|
console.log(objectToEdit);
|
||||||
|
const GradeValue = GradeOption?.find((e:any) => e.id === objectToEdit?.grade_id)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Row className="w-100">
|
||||||
|
<Col>
|
||||||
|
<ValidationField
|
||||||
|
name="first_name"
|
||||||
|
placeholder="first_name"
|
||||||
|
label="first_name"
|
||||||
|
/>
|
||||||
|
<ValidationField
|
||||||
|
name="last_name"
|
||||||
|
placeholder="last_name"
|
||||||
|
label="last_name"
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
<Col>
|
||||||
|
<ValidationField
|
||||||
|
searchBy="GradeName"
|
||||||
|
name="grade_id"
|
||||||
|
label="grade"
|
||||||
|
type="Search"
|
||||||
|
option={GradeOption}
|
||||||
|
isLoading={isLoadingGrade}
|
||||||
|
canChangePage={canChangeGradePage}
|
||||||
|
PageName={"GradeCurrentPage"}
|
||||||
|
page={GradePage}
|
||||||
|
value={GradeValue?.name}
|
||||||
|
/>
|
||||||
|
<ValidationField type="Select" name="sex" option={sex} />
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Form;
|
||||||
|
|
@ -4,6 +4,8 @@ import { Student, StudentInitialValues } from "../../../../types/Student";
|
||||||
export const getInitialValues = (
|
export const getInitialValues = (
|
||||||
objectToEdit: Partial<Student>,
|
objectToEdit: Partial<Student>,
|
||||||
): StudentInitialValues => {
|
): StudentInitialValues => {
|
||||||
|
console.log(objectToEdit);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: objectToEdit?.user_id,
|
id: objectToEdit?.user_id,
|
||||||
first_name: objectToEdit?.first_name ?? "",
|
first_name: objectToEdit?.first_name ?? "",
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,15 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { getInitialValues, getValidationSchema } from "./formUtil";
|
import { getInitialValues, getValidationSchema } from "./formUtil";
|
||||||
import { ModalEnum } from "../../../../enums/Model";
|
import { ModalEnum } from "../../../../enums/Model";
|
||||||
import { QueryStatusEnum } from "../../../../enums/QueryStatus";
|
import { QueryStatusEnum } from "../../../../enums/QueryStatus"
|
||||||
import ValidationModelForm from "./ValidationModelForm";
|
|
||||||
import SalesModelForm from "./SalesModelForm";
|
|
||||||
import SubmitModelForm from "./SubmitModelForm";
|
|
||||||
import LayoutModel from "./LayoutModel";
|
import LayoutModel from "./LayoutModel";
|
||||||
|
import ModelBody from "./ModelBody";
|
||||||
import { useObjectToEdit } from "../../../../zustand/ObjectToEditState";
|
import { useObjectToEdit } from "../../../../zustand/ObjectToEditState";
|
||||||
import { salesModelEnum } from "../../../../enums/salesForms";
|
|
||||||
|
|
||||||
const AddModel: React.FC = () => {
|
const AddModel: React.FC = () => {
|
||||||
|
|
||||||
const { objectToEdit } = useObjectToEdit();
|
const { objectToEdit } = useObjectToEdit();
|
||||||
const handleSubmit = () => {};
|
const handleSubmit = () => {};
|
||||||
const Forms = {
|
|
||||||
[salesModelEnum.Number]: <ValidationModelForm /> ,
|
|
||||||
[salesModelEnum.Package] : <SalesModelForm /> ,
|
|
||||||
[salesModelEnum.Submit]: <SubmitModelForm />
|
|
||||||
}
|
|
||||||
console.log(objectToEdit);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -29,9 +20,7 @@ const AddModel: React.FC = () => {
|
||||||
getInitialValues={getInitialValues(objectToEdit)}
|
getInitialValues={getInitialValues(objectToEdit)}
|
||||||
getValidationSchema={getValidationSchema}
|
getValidationSchema={getValidationSchema}
|
||||||
>
|
>
|
||||||
{Forms[salesModelEnum.Number]}
|
<ModelBody/>
|
||||||
{Forms[salesModelEnum.Package]}
|
|
||||||
{Forms[salesModelEnum.Submit]}
|
|
||||||
</LayoutModel>
|
</LayoutModel>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
39
src/Pages/ReSeller/Sales/Model/ModelBody.tsx
Normal file
39
src/Pages/ReSeller/Sales/Model/ModelBody.tsx
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import ValidationModelForm from "./ValidationModelForm";
|
||||||
|
import SalesModelForm from "./SalesModelForm";
|
||||||
|
import SubmitModelForm from "./SubmitModelForm";
|
||||||
|
import { useObjectToEdit } from "../../../../zustand/ObjectToEditState";
|
||||||
|
import { salesModelEnum } from "../../../../enums/salesForms";
|
||||||
|
import { useFormikContext } from "formik";
|
||||||
|
import { useModalState } from "../../../../zustand/Modal";
|
||||||
|
import { useQueryClient } from "react-query";
|
||||||
|
|
||||||
|
const ModelBody = () => {
|
||||||
|
const { setObjectToEdit } = useObjectToEdit();
|
||||||
|
const formik = useFormikContext<any>();
|
||||||
|
const { setIsOpen } = useModalState((state) => state);
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const handleCloseModel = () => {
|
||||||
|
formik?.resetForm();
|
||||||
|
setIsOpen("");
|
||||||
|
formik?.setFieldValue( "currentModalIndex" , 0 );
|
||||||
|
setObjectToEdit({});
|
||||||
|
queryClient.resetQueries();
|
||||||
|
}
|
||||||
|
|
||||||
|
const Forms = {
|
||||||
|
[salesModelEnum.Number]: <ValidationModelForm handleCloseModel={handleCloseModel}/> ,
|
||||||
|
[salesModelEnum.Package] : <SalesModelForm handleCloseModel={handleCloseModel}/> ,
|
||||||
|
[salesModelEnum.Submit]: <SubmitModelForm handleCloseModel={handleCloseModel} />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{Forms[salesModelEnum.Number]}
|
||||||
|
{Forms[salesModelEnum.Package]}
|
||||||
|
{Forms[salesModelEnum.Submit]}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ModelBody
|
||||||
|
|
@ -1,35 +1,26 @@
|
||||||
import ValidationField from "../../../../Components/ValidationField/ValidationField";
|
import ValidationField from "../../../../Components/ValidationField/ValidationField";
|
||||||
import { useFormikContext } from "formik";
|
import { useFormikContext } from "formik";
|
||||||
import { useModalState } from "../../../../zustand/Modal";
|
|
||||||
import { useObjectToEdit } from "../../../../zustand/ObjectToEditState";
|
import { useObjectToEdit } from "../../../../zustand/ObjectToEditState";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { QueryStatusEnum } from "../../../../enums/QueryStatus";
|
import { QueryStatusEnum } from "../../../../enums/QueryStatus";
|
||||||
import { Button, Divider, Spin } from "antd";
|
import { Button, Divider, Spin } from "antd";
|
||||||
import { MdCancel } from "react-icons/md";
|
import { MdCancel } from "react-icons/md";
|
||||||
import { useQueryClient } from "react-query";
|
import { ModalBodyProps } from "../../../../types/Sales";
|
||||||
|
|
||||||
const Form = () => {
|
const Form = ({
|
||||||
|
handleCloseModel = () => {},
|
||||||
|
}:ModalBodyProps) => {
|
||||||
|
|
||||||
const { objectToEdit,setObjectToEdit } = useObjectToEdit();
|
const { objectToEdit } = useObjectToEdit();
|
||||||
const { setIsOpen } = useModalState((state) => state);
|
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
|
|
||||||
const formik = useFormikContext();
|
const formik = useFormikContext();
|
||||||
const { values, setFieldValue } = useFormikContext<any>()
|
const { values, setFieldValue } = useFormikContext<any>()
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
const handleNext = ()=>{
|
const handleNext = ()=>{
|
||||||
setFieldValue( "currentModalIndex" , values?.currentModalIndex + 1 )
|
setFieldValue( "currentModalIndex" , values?.currentModalIndex + 1 )
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCancel = () => {
|
|
||||||
setIsOpen("");
|
|
||||||
formik.resetForm();
|
|
||||||
queryClient.resetQueries();
|
|
||||||
|
|
||||||
};
|
|
||||||
console.log(objectToEdit);
|
|
||||||
|
|
||||||
const student_info = objectToEdit?.data?.data
|
const student_info = objectToEdit?.data?.data
|
||||||
const status = objectToEdit?.data?.status
|
const status = objectToEdit?.data?.status
|
||||||
const PackagesInfo = student_info?.packages.map((info:any) => ({
|
const PackagesInfo = student_info?.packages.map((info:any) => ({
|
||||||
|
|
@ -37,7 +28,6 @@ const Form = () => {
|
||||||
name: info.name + " " + `( ${info?.original_price} )`
|
name: info.name + " " + `( ${info?.original_price} )`
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
values?.currentModalIndex == 1 &&
|
values?.currentModalIndex == 1 &&
|
||||||
<div className="w-100">
|
<div className="w-100">
|
||||||
|
|
@ -46,13 +36,15 @@ const Form = () => {
|
||||||
<span>
|
<span>
|
||||||
{t(`models.add_sales`)}{" "}
|
{t(`models.add_sales`)}{" "}
|
||||||
</span>
|
</span>
|
||||||
<MdCancel onClick={handleCancel} />
|
<MdCancel onClick={handleCloseModel} />
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
<div className="sales_info_modal">
|
<div className="sales_info_modal">
|
||||||
<div className="info">
|
<div className="info">
|
||||||
<img src="/Image/faker_user.png" alt="" />
|
{/* <img src="/Image/faker_user.png" alt="" /> */}
|
||||||
<span>
|
<span className="mr-20">
|
||||||
<h5>{student_info?.first_name +" " + student_info?.last_name}</h5>
|
<h5>{student_info?.first_name +" " + student_info?.last_name}</h5>
|
||||||
<h5>{t("models.course")}: <p> {student_info?.grade_name}</p></h5>
|
<h5>{t("models.course")}: <p> {student_info?.grade_name}</p></h5>
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -65,8 +57,9 @@ const Form = () => {
|
||||||
option={PackagesInfo}
|
option={PackagesInfo}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="buttons">
|
<div className="buttons">
|
||||||
<Button className="back_button pointer" onClick={handleCancel}>
|
<Button className="back_button pointer" onClick={handleCloseModel}>
|
||||||
{t("practical.cancel")}
|
{t("practical.cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
|
@ -82,6 +75,7 @@ const Form = () => {
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,21 @@ import { MdCancel } from "react-icons/md";
|
||||||
import { useAddSales } from "../../../../api/sales";
|
import { useAddSales } from "../../../../api/sales";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
|
import { ModalBodyProps } from "../../../../types/Sales";
|
||||||
import { useQueryClient } from "react-query";
|
import { useQueryClient } from "react-query";
|
||||||
|
|
||||||
const Form = () => {
|
const Form = ({
|
||||||
|
handleCloseModel = () => {},
|
||||||
|
}:ModalBodyProps) => {
|
||||||
|
|
||||||
const { setObjectToEdit,objectToEdit } = useObjectToEdit();
|
const { setObjectToEdit , objectToEdit } = useObjectToEdit();
|
||||||
const { resetForm, values, setFieldValue , } = useFormikContext<any>();
|
const { values, setFieldValue } = useFormikContext<any>();
|
||||||
|
const formik = useFormikContext();
|
||||||
const { setIsOpen } = useModalState((state) => state);
|
const { setIsOpen } = useModalState((state) => state);
|
||||||
|
const queryClient = useQueryClient();
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
|
|
||||||
const {mutate,status,error,isSuccess} = useAddSales();
|
const { mutate, status, error,reset }:any = useAddSales();
|
||||||
const coupon_id_object = objectToEdit?.data?.data?.packages.find((e:any)=>(e.id === values?.package_id))
|
const coupon_id_object = objectToEdit?.data?.data?.packages.find((e:any)=>(e.id === values?.package_id))
|
||||||
const student_info = objectToEdit?.data?.data
|
const student_info = objectToEdit?.data?.data
|
||||||
const PackagesInfo = student_info?.packages.map((info:any) => ({
|
const PackagesInfo = student_info?.packages.map((info:any) => ({
|
||||||
|
|
@ -26,7 +31,6 @@ const Form = () => {
|
||||||
name: info.name + " " + `( ${info?.original_price} )`
|
name: info.name + " " + `( ${info?.original_price} )`
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const handleNext = ()=>{
|
const handleNext = ()=>{
|
||||||
mutate({
|
mutate({
|
||||||
package_id:values?.package_id,
|
package_id:values?.package_id,
|
||||||
|
|
@ -34,29 +38,25 @@ const Form = () => {
|
||||||
coupon_id:coupon_id_object?.coupon_id
|
coupon_id:coupon_id_object?.coupon_id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const handleCancel = () => {
|
|
||||||
resetForm();
|
|
||||||
setIsOpen("");
|
|
||||||
setFieldValue( "currentModalIndex" , 0 );
|
|
||||||
setObjectToEdit({});
|
|
||||||
queryClient.resetQueries();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(status === QueryStatusEnum.SUCCESS){
|
if(status === QueryStatusEnum.SUCCESS){
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
setObjectToEdit({});
|
setObjectToEdit({});
|
||||||
setFieldValue( "currentModalIndex" , values?.currentModalIndex - 2 )
|
setFieldValue( "currentModalIndex" , values?.currentModalIndex - 2 );
|
||||||
|
reset();
|
||||||
|
formik?.resetForm();
|
||||||
}
|
}
|
||||||
else if(status === QueryStatusEnum.ERROR){
|
else if(status === QueryStatusEnum.ERROR){
|
||||||
toast.error(t(`toast.${error?.response?.data?.message}` || `toast.error_while_trying_please_try_again`))
|
toast.error(t(`toast.${error?.response?.data?.message}` || `toast.error_while_trying_please_try_again`))
|
||||||
}
|
}
|
||||||
|
|
||||||
if(values?.currentModalIndex >= 3){
|
if(values?.currentModalIndex >= 3){
|
||||||
setIsOpen("")
|
setIsOpen("")
|
||||||
setObjectToEdit({})
|
setObjectToEdit({})
|
||||||
setFieldValue( "currentModalIndex" , 0 )
|
setFieldValue( "currentModalIndex" , 0 );
|
||||||
|
queryClient.resetQueries();
|
||||||
|
reset();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, [values?.currentModalIndex,status])
|
}, [values?.currentModalIndex,status])
|
||||||
|
|
@ -65,16 +65,19 @@ const Form = () => {
|
||||||
values?.currentModalIndex == 2 &&
|
values?.currentModalIndex == 2 &&
|
||||||
|
|
||||||
<div className="w-100">
|
<div className="w-100">
|
||||||
|
|
||||||
<header className="modal_title">
|
<header className="modal_title">
|
||||||
<span>
|
<span>
|
||||||
{t(`models.are_you_sure_about_sale`)}{" "}
|
{t(`models.are_you_sure_about_sale`)}{" "}
|
||||||
</span>
|
</span>
|
||||||
<MdCancel onClick={handleCancel} />
|
<MdCancel onClick={handleCloseModel} />
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
<div className="sales_info_modal">
|
<div className="sales_info_modal">
|
||||||
<div className="info">
|
<div className="info">
|
||||||
<img src="/Image/faker_user.png" alt="" />
|
{/* <img src="/Image/faker_user.png" alt="" /> */}
|
||||||
<span>
|
<span>
|
||||||
<h5>{student_info?.first_name +" " + student_info?.last_name}</h5>
|
<h5>{student_info?.first_name +" " + student_info?.last_name}</h5>
|
||||||
<h5>{t("models.course")}: <p> {student_info?.grade_name}</p></h5>
|
<h5>{t("models.course")}: <p> {student_info?.grade_name}</p></h5>
|
||||||
|
|
@ -90,8 +93,9 @@ const Form = () => {
|
||||||
allowClear={false}
|
allowClear={false}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="buttons">
|
<div className="buttons">
|
||||||
<Button className="back_button pointer" onClick={handleCancel}>
|
<Button className="back_button pointer" onClick={handleCloseModel}>
|
||||||
{t("practical.cancel")}
|
{t("practical.cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
|
@ -107,14 +111,9 @@ const Form = () => {
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Form;
|
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
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { Col, Row } from "reactstrap";
|
import { Col, Row } from "reactstrap";
|
||||||
import ValidationField from "../../../../Components/ValidationField/ValidationField";
|
import ValidationField from "../../../../Components/ValidationField/ValidationField";
|
||||||
import { useFormikContext } from "formik";
|
import { useFormikContext } from "formik";
|
||||||
import { useModalState } from "../../../../zustand/Modal";
|
|
||||||
import { useObjectToEdit } from "../../../../zustand/ObjectToEditState";
|
import { useObjectToEdit } from "../../../../zustand/ObjectToEditState";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { QueryStatusEnum } from "../../../../enums/QueryStatus";
|
import { QueryStatusEnum } from "../../../../enums/QueryStatus";
|
||||||
|
|
@ -9,13 +8,13 @@ import { Button, Divider, Spin } from "antd";
|
||||||
import { MdCancel } from "react-icons/md";
|
import { MdCancel } from "react-icons/md";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useGetStudentByPhone } from "../../../../api/sales";
|
import { useGetStudentByPhone } from "../../../../api/sales";
|
||||||
import { toast } from "react-toastify";
|
import { ModalBodyProps } from "../../../../types/Sales";
|
||||||
import { useQueryClient } from "react-query";
|
|
||||||
|
|
||||||
const Form = () => {
|
const Form = ({
|
||||||
|
handleCloseModel = () => {},
|
||||||
|
}:ModalBodyProps) => {
|
||||||
|
|
||||||
const [ triggerApi, setTriggerApi] = useState(false)
|
const [ triggerApi, setTriggerApi] = useState(false)
|
||||||
const { setIsOpen } = useModalState((state) => state);
|
|
||||||
const { setObjectToEdit } = useObjectToEdit();
|
const { setObjectToEdit } = useObjectToEdit();
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
|
|
||||||
|
|
@ -24,12 +23,11 @@ const Form = () => {
|
||||||
const {values,setFieldValue} = useFormikContext<any>()
|
const {values,setFieldValue} = useFormikContext<any>()
|
||||||
const phoneNumber : number = values?.phone_number
|
const phoneNumber : number = values?.phone_number
|
||||||
|
|
||||||
const { data,isError,status,isSuccess } = useGetStudentByPhone({
|
const { data, status, isSuccess } = useGetStudentByPhone({
|
||||||
phone_number:phoneNumber,
|
phone_number:phoneNumber,
|
||||||
},{
|
},{
|
||||||
enabled: triggerApi
|
enabled: triggerApi
|
||||||
});
|
});
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
const handleNext = ()=>{
|
const handleNext = ()=>{
|
||||||
if(values?.phone_number && phoneNumber.toString().length === 10 ){
|
if(values?.phone_number && phoneNumber.toString().length === 10 ){
|
||||||
|
|
@ -39,14 +37,6 @@ const Form = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const handleCancel = () => {
|
|
||||||
setIsOpen("");
|
|
||||||
formik.resetForm();
|
|
||||||
setTriggerApi(false);
|
|
||||||
setObjectToEdit({});
|
|
||||||
queryClient.resetQueries();
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(isSuccess){
|
if(isSuccess){
|
||||||
setTriggerApi(false);
|
setTriggerApi(false);
|
||||||
|
|
@ -56,23 +46,6 @@ const Form = () => {
|
||||||
}, [isSuccess]);
|
}, [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 (
|
return (
|
||||||
values?.currentModalIndex == 0 &&
|
values?.currentModalIndex == 0 &&
|
||||||
<div className="w-100">
|
<div className="w-100">
|
||||||
|
|
@ -81,8 +54,9 @@ const Form = () => {
|
||||||
<span>
|
<span>
|
||||||
{t(`models.add_sales`)}{" "}
|
{t(`models.add_sales`)}{" "}
|
||||||
</span>
|
</span>
|
||||||
<MdCancel onClick={handleCancel} />
|
<MdCancel onClick={handleCloseModel} />
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
<Row className="w-100">
|
<Row className="w-100">
|
||||||
|
|
@ -94,8 +68,9 @@ const Form = () => {
|
||||||
/>
|
/>
|
||||||
<Divider className="margin_auto"/>
|
<Divider className="margin_auto"/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<div className="buttons">
|
<div className="buttons">
|
||||||
<Button className="back_button pointer" onClick={handleCancel}>
|
<Button className="back_button pointer" onClick={handleCloseModel}>
|
||||||
{t("practical.cancel")}
|
{t("practical.cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
|
@ -111,7 +86,9 @@ const Form = () => {
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -112,3 +112,7 @@
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mr-20{
|
||||||
|
margin-right: 20px;
|
||||||
|
}
|
||||||
|
|
@ -10,11 +10,13 @@ const API = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const KEY = "sales";
|
const KEY = "sales";
|
||||||
|
const KEYSales = "sales_key";
|
||||||
|
|
||||||
const KEY2 = "Sale_Student_Data";
|
const KEY2 = "Sale_Student_Data";
|
||||||
const KEY3 = "collection_summery";
|
const KEY3 = "collection_summery";
|
||||||
|
|
||||||
|
|
||||||
export const useGetAllSales = (params?: any, options?: any) =>useGetQuery(KEY, API.GET, params, options);
|
export const useGetAllSales = (params?: any, options?: any) =>useGetQuery(KEYSales, API.GET, params, options);
|
||||||
export const useAddSales = () => useAddMutation(KEY, API.ADD);
|
export const useAddSales = () => useAddMutation(KEY, API.ADD);
|
||||||
export const useGetStudentByPhone = (params?: any, options?: any) => useGetQuery(KEY2, API.GET_BY_PHONE, params, options);
|
export const useGetStudentByPhone = (params?: any, options?: any) => useGetQuery(KEY2, API.GET_BY_PHONE, params, options);
|
||||||
export const useGetSummery = () => useGetQuery(KEY3, API.GET_SUMMERY);
|
export const useGetSummery = () => useGetQuery(KEY3, API.GET_SUMMERY);
|
||||||
3
src/types/Sales.ts
Normal file
3
src/types/Sales.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
export interface ModalBodyProps {
|
||||||
|
handleCloseModel?: (values: any) => void;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user