
diff --git a/src/Pages/ReSeller/Sales/Model/ValidationModelForm.tsx b/src/Pages/ReSeller/Sales/Model/ValidationModelForm.tsx
index ffa30fb..0059aef 100644
--- a/src/Pages/ReSeller/Sales/Model/ValidationModelForm.tsx
+++ b/src/Pages/ReSeller/Sales/Model/ValidationModelForm.tsx
@@ -9,18 +9,20 @@ 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";
const Form = () => {
- const {values,setFieldValue} = useFormikContext
()
const [triggerApi, setTriggerApi] = useState(false)
- const phoneNumber : number = values?.phone_number
- const { isOpen, setIsOpen } = useModalState((state) => state);
- const { objectToEdit,setObjectToEdit } = useObjectToEdit();
+ const { setIsOpen } = useModalState((state) => state);
+ const { setObjectToEdit } = useObjectToEdit();
const {t} = useTranslation();
- const formik = useFormikContext();
- const {data,isError,isSuccess,status} = useGetStudentByPhone({
+ const formik = useFormikContext();
+ const {values,setFieldValue} = useFormikContext()
+ const phoneNumber : number = values?.phone_number
+
+ const { data,isError,status } = useGetStudentByPhone({
phone_number:phoneNumber,
},{
enabled: triggerApi
@@ -30,22 +32,13 @@ const Form = () => {
if(values?.phone_number && phoneNumber.toString().length === 10){
setTriggerApi(true)
}
- // if(values?.currentModalIndex == 0 && phoneNumber.toString().length === 10){
- // toast.error("phone number not found ")
- // }
}
- // console.log(status);
- // console.log(isSuccess);
- // console.log(isError);
- // console.log(data?.data);
- // console.log(triggerApi);
-
const handleCancel = () => {
- setIsOpen("");
- setObjectToEdit({});
+ setIsOpen("");
+ formik.resetForm();
};
-
+
useEffect(() => {
if(!!data?.data?.phone_number){
setFieldValue( "currentModalIndex" , values?.currentModalIndex + 1 )
@@ -55,49 +48,52 @@ const Form = () => {
else if(!data?.data){
setTriggerApi(false)
}
-
- }, [data?.data,triggerApi])
+ if(isError){
+ toast.error(t('toast.phone_number_not_found'))
+ }
+ }, [data?.data,triggerApi,isError])
return (
values?.currentModalIndex == 0 &&
-
-
-
- {t(`models.add_sales`)}{" "}
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ {t(`models.add_sales`)}{" "}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
);
};
diff --git a/src/Pages/ReSeller/Sales/Model/formUtil.ts b/src/Pages/ReSeller/Sales/Model/formUtil.ts
index f10799d..188fba5 100644
--- a/src/Pages/ReSeller/Sales/Model/formUtil.ts
+++ b/src/Pages/ReSeller/Sales/Model/formUtil.ts
@@ -1,16 +1,16 @@
import * as Yup from "yup";
-import { formatDate } from "../../../../utils/formatDate";
// Function to get the initial values
export const getInitialValues = (objectToEdit: any): any => {
-
+ console.log(objectToEdit);
+
return {
id: objectToEdit?.id ?? null,
phone_number: objectToEdit?.phone_number ?? null,
currentModalIndex: 0,
package_id: objectToEdit?.package_id ?? null,
- student_id: objectToEdit?.student_id ?? 0,
- coupon_id: objectToEdit?.coupon_id ?? 1,
+ student_id: objectToEdit?.student_id ?? null,
+ coupon_id: objectToEdit?.coupon_id ?? null,
};
};
diff --git a/src/Pages/ReSeller/Sales/Page.tsx b/src/Pages/ReSeller/Sales/Page.tsx
index cec13a9..6fe6b09 100644
--- a/src/Pages/ReSeller/Sales/Page.tsx
+++ b/src/Pages/ReSeller/Sales/Page.tsx
@@ -11,11 +11,14 @@ const Table = lazy(() => import("./Table"));
const AddModalForm = lazy(() => import("./Model/AddModel"));
const TableHeader = () => {
+
const [t] = useTranslation();
useSetPageTitle([
{name:`${t(`page_header.home`)}`, path:"/"},
{name:`${t(`page_header.sales`)}`, path:"sales"}
- ]); return (
+ ]);
+
+ return (
}>
{
+
const [searchQuery] = useSearchQuery("name");
const { filterState }:any = useFilterState();
diff --git a/src/Pages/ReSeller/Sales/index.tsx b/src/Pages/ReSeller/Sales/index.tsx
index 447f22d..f9646fc 100644
--- a/src/Pages/ReSeller/Sales/index.tsx
+++ b/src/Pages/ReSeller/Sales/index.tsx
@@ -4,14 +4,10 @@ import Table from "./Table";
import { FaPlus } from "react-icons/fa";
import AddModalForm from "./Model/AddModel";
-import EditModalForm from "./Model/EditModel";
-// import DeleteModalForm from "../../";
export {
Table,
useColumns,
AddModalForm,
- EditModalForm,
- // DeleteModalForm,
FaPlus,
};
diff --git a/src/Pages/ReSeller/Sales/useTableColumns.tsx b/src/Pages/ReSeller/Sales/useTableColumns.tsx
index 3895a09..62930d4 100644
--- a/src/Pages/ReSeller/Sales/useTableColumns.tsx
+++ b/src/Pages/ReSeller/Sales/useTableColumns.tsx
@@ -5,7 +5,6 @@ import { useTranslation } from "react-i18next";
export const useColumns = () => {
const [t] = useTranslation();
-
const columns: TableColumnsType = [
{
title: t("columns.id"),
diff --git a/src/enums/salesForms.ts b/src/enums/salesForms.ts
new file mode 100644
index 0000000..e52b861
--- /dev/null
+++ b/src/enums/salesForms.ts
@@ -0,0 +1,5 @@
+export enum salesModelEnum {
+ Number= 0,
+ Package= 1,
+ Submit= 2
+ }
\ No newline at end of file
diff --git a/src/translate/ar.json b/src/translate/ar.json
index 5477e93..d723b73 100644
--- a/src/translate/ar.json
+++ b/src/translate/ar.json
@@ -1018,6 +1018,12 @@
"reseller_profit":"نسبة الأرباح (10%)",
"total_sells":"إجمالي المبيعات"
},
+ "toast" : {
+ "phone_number_not_found":"رقم الهاتف غير موجود",
+ "error_while_trying_please_try_again":"حدث خطأ أثناء المحاولة، يرجى المحاولة مرة أخرى",
+ "Student Already Have this Package":"الطالب لديه هذه الحزمة بالفعل",
+ "The combination of student_id and package_id already exists.":"مجموعة الطالب والحزمة موجودة بالفعل."
+ },
"alphabet": {
"A": "A",
"B": "B",