fix: create guilds fix some

This commit is contained in:
2026-02-02 17:06:25 +03:30
parent 4b651f51c6
commit 199ffa7163
10 changed files with 282 additions and 191 deletions

View File

@@ -8,7 +8,7 @@ import {
Dialog,
DialogTitle,
DialogContent,
DialogActions,
DialogActions
} from "@mui/material";
import { Add as AddIcon } from "@mui/icons-material";
import { Grid } from "../../../../components/grid/Grid";
@@ -22,8 +22,10 @@ import { provinceGetFieldOfWorks } from "../../services/ProvinceGetFieldOfWorks"
import { provinceGetTypeActivity } from "../../services/provinceGetTypeActivity";
import { provinceGetRegisterCodeStateService } from "../../services/province-get-register-code-state";
import { mainGetGuildsForUpdateOrCreateService } from "../../services/main-get-guilds-for-update-or-create";
import { cityGetProvinces } from "../../../city/services/CityGetProvinces";
import { cityGetCity } from "../../../city/services/city-get-city";
import {
slaughterGetProvinceService,
slaughterGetCitiesService
} from "../../../slaughter-house/services/slaughter-get-provinces";
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
import { PersonalInfoSection } from "./components/PersonalInfoSection";
import { InquiryForm } from "./components/InquiryForm";
@@ -34,7 +36,7 @@ import { GuildInfoAccordionItem } from "./components/GuildInfoAccordionItem";
import { getValidationSchema, getInitialValues } from "./utils/formUtils";
import {
mapResponseDataToFormFields,
prepareSubmitData,
prepareSubmitData
} from "./utils/dataMapping";
import { handleSubmitSuccess, handleSubmitError } from "./utils/submitHandlers";
@@ -121,7 +123,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
is_alive: values?.is_alive,
birth_date: values?.birth_date,
father_name: values?.father_name,
mobile: values?.mobile,
mobile: values?.mobile
};
return prepareSubmitData(
combinedValues,
@@ -146,7 +148,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
}
}
);
},
}
});
useEffect(() => {
@@ -165,7 +167,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
setTypeActivities(r.payload.data || []);
});
// Fetch provinces for province/city selection
dispatch(cityGetProvinces()).then((r) => {
dispatch(slaughterGetProvinceService()).then((r) => {
if (r?.payload?.data) {
setProvinces(r.payload.data);
}
@@ -178,13 +180,13 @@ export const CreateGuilds = ({ guild, updateTable }) => {
const guildsForFormik = guildsList.map((guildItem) => {
const combinedGuild = {
...guildItem,
user: guild?.user || {},
user: guild?.user || {}
};
const initialValues = getInitialValues(combinedGuild);
return {
steward: initialValues.steward || false,
guild: initialValues.guild || false,
license_number: initialValues.license_number ?? "",
license_number: initialValues.license_number ?? ""
};
});
formik.setFieldValue("guilds", guildsForFormik, false).then(() => {
@@ -208,10 +210,13 @@ export const CreateGuilds = ({ guild, updateTable }) => {
}
}, [provinces, formik.values.state, formik.values.province]);
// Fetch cities when province is selected
// Fetch cities when province is selected (slaughter API uses province name)
useEffect(() => {
if (formik.values.province) {
dispatch(cityGetCity(formik.values.province)).then((r) => {
const provinceName =
provinces.find((p) => p.key === formik.values.province)?.name ||
formik.values.province;
dispatch(slaughterGetCitiesService(provinceName)).then((r) => {
if (r?.payload?.data) {
setProvinceCities(r.payload.data);
}
@@ -219,7 +224,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
} else {
setProvinceCities([]);
}
}, [formik.values.province, dispatch]);
}, [formik.values.province, provinces, dispatch]);
// Set city ID from person_city name when provinceCities are loaded
useEffect(() => {
@@ -262,7 +267,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
const initialGuildValues = guildsData.map((guildItem) => {
const combinedGuild = {
...guildItem,
user: responseData.user || {},
user: responseData.user || {}
};
return getInitialValues(combinedGuild);
});
@@ -272,7 +277,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
const guildsForFormik = initialGuildValues.map((g) => ({
steward: g.steward ?? false,
guild: g.guild ?? false,
license_number: g.license_number ?? "",
license_number: g.license_number ?? ""
}));
formik.setFieldValue("guilds", guildsForFormik, true).then(() => {
formik.validateField("guilds");
@@ -302,7 +307,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
vertical: "top",
horizontal: "center",
msg: "لطفا کد ملی را وارد کنید",
severity: "error",
severity: "error"
});
return;
}
@@ -312,7 +317,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
vertical: "top",
horizontal: "center",
msg: "لطفا کد ملی 10 رقمی معتبر وارد کنید",
severity: "error",
severity: "error"
});
return;
}
@@ -320,7 +325,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
dispatch(
mainGetGuildsForUpdateOrCreateService({
national_code: inquiryNationalCode,
update: false,
update: false
})
).then((r) => {
if (r.payload.error) {
@@ -333,7 +338,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
vertical: "top",
horizontal: "center",
msg: r.payload.error,
severity: "error",
severity: "error"
});
if (!isAdmin) {
return;
@@ -357,7 +362,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
vertical: "top",
horizontal: "center",
msg: successMsg,
severity: "success",
severity: "success"
});
} else {
setHasInquiry(false);
@@ -373,7 +378,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
openNotif,
mapResponseToFormFields,
isAdmin,
formik,
formik
]);
const handleUpdateFromExternal = useCallback(() => {
@@ -382,7 +387,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
vertical: "top",
horizontal: "center",
msg: "لطفا کد ملی 10 رقمی معتبر وارد کنید",
severity: "error",
severity: "error"
});
return;
}
@@ -390,7 +395,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
dispatch(
mainGetGuildsForUpdateOrCreateService({
national_code: formik.values.national_id,
update: true,
update: true
})
).then((r) => {
if (r.payload.error) {
@@ -399,7 +404,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
vertical: "top",
horizontal: "center",
msg: r.payload.error,
severity: "error",
severity: "error"
});
return;
}
@@ -407,7 +412,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
if (r.payload.data) {
const updateResponse = {
...r.payload.data,
dbRegister: false,
dbRegister: false
};
mapResponseToFormFields(updateResponse);
setHasInquiry(true);
@@ -416,7 +421,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
vertical: "top",
horizontal: "center",
msg: "اطلاعات از سامانه خارجی بروزرسانی شد",
severity: "success",
severity: "success"
});
} else {
setHasInquiry(false);
@@ -492,14 +497,14 @@ export const CreateGuilds = ({ guild, updateTable }) => {
vertical: "top",
horizontal: "center",
msg: r.payload.error,
severity: "error",
severity: "error"
});
} else {
openNotif({
vertical: "top",
horizontal: "center",
msg: "صنف با موفقیت حذف شد",
severity: "success",
severity: "success"
});
// Remove from list after successful deletion
if (guildsList.length > 1) {
@@ -551,7 +556,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
}
newValues[index] = {
...newValues[index],
[fieldName]: value,
[fieldName]: value
};
return newValues;
});
@@ -569,7 +574,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
}
updatedGuilds[index] = {
...updatedGuilds[index],
[fieldName]: value,
[fieldName]: value
};
formik.setFieldValue("guilds", updatedGuilds, true).then(() => {
formik.validateField("guilds");
@@ -610,8 +615,8 @@ export const CreateGuilds = ({ guild, updateTable }) => {
: {
xs: "96vw",
md: "90vw",
nlg: "1280px",
},
nlg: "1280px"
}
}}
>
{shouldShowUpdateButton && (
@@ -718,6 +723,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
<FormActions
formik={formik}
onClose={() => dispatch(CLOSE_MODAL())}
guildsCount={guildsList.length}
showCloseButton={
!guild &&
hasInquiry === true &&
@@ -728,7 +734,7 @@ export const CreateGuilds = ({ guild, updateTable }) => {
formData={guildsList.map((guildItem, index) => {
const guildValues = guildsFormValues[index];
const combinedValues = {
...guildValues, // Guild-specific info (overrides if same keys exist)
...guildValues // Guild-specific info (overrides if same keys exist)
};
return prepareSubmitData(
combinedValues,

View File

@@ -2,12 +2,75 @@ import React from "react";
import { Button, Typography, Checkbox, FormControlLabel } from "@mui/material";
import { Grid } from "../../../../../components/grid/Grid";
/**
* Extracts the appropriate error message from formik.errors.guilds.
* guilds can be: string (array-level) | array of guild error objects
*/
const getGuildsErrorMessage = (guildsError) => {
if (!guildsError) return null;
if (typeof guildsError === "string") return guildsError;
if (Array.isArray(guildsError)) {
for (let i = 0; i < guildsError.length; i++) {
const guildError = guildsError[i];
if (!guildError) continue;
if (typeof guildError === "string") return guildError;
if (typeof guildError === "object") {
const firstValue = Object.values(guildError)[0];
if (typeof firstValue === "string") return firstValue;
if (typeof firstValue === "object" && firstValue?.message)
return firstValue.message;
}
}
}
return null;
};
const MIN_GUILDS_ERROR = "حداقل یک واحد صنفی باید وجود داشته باشد";
/**
* Collects all blocking error messages to show under submit button.
* Suppresses "حداقل یک واحد صنفی..." when we have guild data (race condition:
* formik.values.guilds may lag behind guildsList after inquiry).
*/
const getBlockingErrors = (
formik,
isKillHouse,
isAreaActivityValid,
guildsCount = 0
) => {
const errors = [];
if (formik.errors.isAccepted) {
errors.push(formik.errors.isAccepted);
}
if (formik.errors.national_id) {
errors.push(formik.errors.national_id);
}
if (formik.errors.mobile) {
errors.push(formik.errors.mobile);
}
if (isKillHouse && !isAreaActivityValid) {
errors.push('رسته واحد صنفی باید شامل کلمه "مرغ" باشد');
}
const guildsMsg = getGuildsErrorMessage(formik.errors.guilds);
if (guildsMsg) {
if (guildsMsg === MIN_GUILDS_ERROR && guildsCount > 0) {
// User has guilds from inquiry/edit - suppress stale "no guilds" error
} else {
errors.push(guildsMsg);
}
}
return errors;
};
export const FormActions = ({
formik,
onClose,
showCloseButton,
isKillHouse,
onSubmit,
guildsCount = 0
}) => {
if (showCloseButton) {
return (
@@ -23,9 +86,21 @@ export const FormActions = ({
? formik.values.area_activity && formik.values.area_activity.includes("مرغ")
: true;
// Check if guilds validation has errors
const hasGuildsError = formik.errors.guilds;
const hasGuilds = formik.values.guilds && formik.values.guilds.length > 0;
const guildsErrorRaw = formik.errors.guilds;
const isStaleMinGuildsError =
guildsCount > 0 &&
typeof guildsErrorRaw === "string" &&
guildsErrorRaw === MIN_GUILDS_ERROR;
const hasGuildsError = guildsErrorRaw && !isStaleMinGuildsError;
const hasGuilds =
(formik.values.guilds && formik.values.guilds.length > 0) ||
guildsCount > 0;
const blockingErrors = getBlockingErrors(
formik,
isKillHouse,
isAreaActivityValid,
guildsCount
);
return (
<>
@@ -59,24 +134,18 @@ export const FormActions = ({
>
ثبت
</Button>
{isKillHouse && !isAreaActivityValid && (
{blockingErrors.length > 0 && (
<Typography
component="div"
variant="caption"
color="error"
sx={{ mt: 1, display: "block" }}
>
رسته واحد صنفی باید شامل کلمه &quot;مرغ&quot; باشد
</Typography>
)}
{hasGuildsError && (
<Typography
variant="caption"
color="error"
sx={{ mt: 1, display: "block" }}
>
{typeof formik.errors.guilds === "string"
? formik.errors.guilds
: "برای هر واحد صنفی، حداقل یکی از گزینه‌های مباشر یا صنف باید انتخاب شود"}
{blockingErrors.map((msg, i) => (
<span key={i} style={{ display: "block" }}>
{msg}
</span>
))}
</Typography>
)}
</Grid>

View File

@@ -87,7 +87,7 @@ export const prepareSubmitData = (
title: values.guild_name || "",
role: getRoleFromUrl(),
has_inquiry: hasInquiry !== null ? hasInquiry : false,
...(values.active !== null && { active: values.active }),
...(values.active !== null && { active: values.active })
};
if (guild) {
@@ -159,12 +159,12 @@ const extractFormFieldsFromDatabaseInquiry = (
guild_national_id: firstGuildFromDb.nationalCode || "",
corporation_name: firstGuildFromDb.companyName || "",
// Status Fields
// Status Fields (is_foreign_national is at guild level in API response)
is_foreigner:
responseDataFromDb.isForeignNational === false
? false
: responseDataFromDb.isForeignNational === true
? true
firstGuildFromDb.isForeignNational === true
? "بلی"
: firstGuildFromDb.isForeignNational === false
? "خیر"
: "",
has_steward:
responseDataFromDb.steward === false
@@ -187,7 +187,7 @@ const extractFormFieldsFromDatabaseInquiry = (
// Additional Database Fields
company_name: firstGuildFromDb.companyName || "",
company_identifier: firstGuildFromDb.companyIdentifier || "",
type_activity_name: firstGuildFromDb.typeActivity || "",
type_activity_name: firstGuildFromDb.typeActivity || ""
};
};
@@ -279,7 +279,7 @@ const extractFormFieldsFromExternalApi = (
guild:
typeof firstGuildFromExternalApi.guild === "boolean"
? firstGuildFromExternalApi.guild
: false,
: false
};
};

View File

@@ -48,14 +48,14 @@ export const getValidationSchema = (isEditMode) =>
license_number: yup.string().required("شماره مجوز الزامی است"),
steward: yup.boolean(),
guild: yup.boolean(),
guild: yup.boolean()
})
.test(
"steward-guild-required",
"برای هر واحد صنفی، حداقل یکی از گزینه‌های مباشر یا صنف باید انتخاب شود",
(value) => value?.steward === true || value?.guild === true
)
),
)
});
/**
@@ -110,7 +110,12 @@ export const getInitialValues = (guildDataForEdit) => {
),
// Status Fields (from guild object in edit mode)
is_foreigner: guildDataForEdit?.is_foreign_national || "",
is_foreigner:
guildDataForEdit?.isForeignNational === true
? "بلی"
: guildDataForEdit?.isForeignNational === false
? "خیر"
: "",
has_steward: guildDataForEdit?.hasSteward || "",
has_partner: guildDataForEdit?.hasPartner || "",
steward:
@@ -149,9 +154,9 @@ export const getInitialValues = (guildDataForEdit) => {
? guildDataForEdit.guild
: typeof guildDataForEdit?.isGuild === "boolean"
? guildDataForEdit.isGuild
: false,
},
: false
}
]
: [],
: []
};
};

View File

@@ -49,7 +49,7 @@ export const ManageGuilds = ({ userType }) => {
is_real_person: true,
role_key: checkPathStartsWith("province")
? selectedSubUser?.key || ""
: "",
: ""
})
: provinceGetTotalGuildsService({
search: "filter",
@@ -61,7 +61,7 @@ export const ManageGuilds = ({ userType }) => {
is_real_person: true,
role_key: checkPathStartsWith("province")
? selectedSubUser?.key || ""
: "",
: ""
})
);
@@ -119,64 +119,78 @@ export const ManageGuilds = ({ userType }) => {
item?.limitationAllocation ? "دارد" : "ندارد",
item?.allocationLimit ? item?.allocationLimit : "-",
item?.getPosStatus?.hasActivePons ? "دارد" : "ندارد",
item?.getPosStatus?.lenActiveSessions || "-",
item?.getPosStatus?.lenActiveSessions || "-"
];
if (getRoleFromUrl() !== "KillHouse") {
commonData.push(
<Button
key={`stewards-${i}`}
onClick={() => {
const tableData = item?.stewards?.map((option, index) => [
index + 1,
option?.guildsName || "-",
option?.user?.mobile || "-",
]);
dispatch(
OPEN_MODAL({
title: IS_STEWARD ? "مباشرین" : "اصناف",
content: (
<SimpleTable
paginated
title={IS_STEWARD ? "مباشرین" : "اصناف"}
columns={["ردیف", "نام و نام خانوادگی", "تلفن"]}
data={tableData}
/>
),
})
);
}}
>
نمایش ({item?.stewards?.length || 0})
</Button>
(item?.stewards?.length || 0) === 0 ? (
"ندارد"
) : (
<Button
key={`stewards-${i}`}
variant="outlined"
size="small"
sx={{ whiteSpace: "nowrap", fontSize: "0.8125rem" }}
onClick={() => {
const tableData = item?.stewards?.map((option, index) => [
index + 1,
option?.guildsName || "-",
option?.user?.mobile || "-"
]);
dispatch(
OPEN_MODAL({
title: IS_STEWARD ? "مباشرین" : "اصناف",
content: (
<SimpleTable
paginated
title={IS_STEWARD ? "مباشرین" : "اصناف"}
columns={["ردیف", "نام و نام خانوادگی", "تلفن"]}
data={tableData}
/>
)
})
);
}}
>
نمایش ({item?.stewards?.length || 0})
</Button>
)
);
commonData.push(
<Button
key={`killHouse-${i}`}
onClick={() => {
const tableData = item?.killHouse?.map((option, index) => [
index + 1,
option?.name || "-",
option?.killHouseOperator?.user?.mobile || "-",
]);
dispatch(
OPEN_MODAL({
title: "کشتارگاه ها",
content: (
<SimpleTable
paginated
title={"کشتارگاه ها"}
columns={["ردیف", "نام و نام خانوادگی", "تلفن"]}
data={tableData}
/>
),
})
);
}}
>
نمایش ({item?.killHouse?.length || 0})
</Button>
(item?.killHouse?.length || 0) === 0 ? (
"ندارد"
) : (
<Button
key={`killHouse-${i}`}
variant="outlined"
size="small"
sx={{ whiteSpace: "nowrap", fontSize: "0.8125rem" }}
onClick={() => {
const tableData = item?.killHouse?.map((option, index) => [
index + 1,
option?.name || "-",
option?.killHouseOperator?.user?.mobile || "-"
]);
dispatch(
OPEN_MODAL({
title: "کشتارگاه ها",
content: (
<SimpleTable
paginated
title={"کشتارگاه ها"}
columns={["ردیف", "نام و نام خانوادگی", "تلفن"]}
data={tableData}
/>
)
})
);
}}
>
نمایش ({item?.killHouse?.length || 0})
</Button>
)
);
}
@@ -242,7 +256,7 @@ export const ManageGuilds = ({ userType }) => {
is_real_person: true,
role_key: checkPathStartsWith("province")
? selectedSubUser?.key || ""
: "",
: ""
})
: provinceGetTotalGuildsService({
search: "filter",
@@ -254,7 +268,7 @@ export const ManageGuilds = ({ userType }) => {
is_real_person: true,
role_key: checkPathStartsWith("province")
? selectedSubUser?.key || ""
: "",
: ""
})
);
@@ -295,7 +309,7 @@ export const ManageGuilds = ({ userType }) => {
bottom: window.innerWidth <= 600,
size: window.innerWidth <= 600 ? "small" : "auto",
title: `ثبت ${IS_STEWARD ? "مباشر" : "صنف"} جدید`,
content: <CreateGuilds updateTable={updateTable} />,
content: <CreateGuilds updateTable={updateTable} />
})
);
}}
@@ -394,7 +408,7 @@ export const ManageGuilds = ({ userType }) => {
"مباشرین",
"وضعیت فعالیت",
"وضعیت",
"کشتارگاه ها",
"کشتارگاه ها"
]
: getRoleFromUrl() === "KillHouse"
? [
@@ -415,7 +429,7 @@ export const ManageGuilds = ({ userType }) => {
"وضعیت کارتخوان",
"تعداد کارتخوان ",
"وضعیت فعالیت",
"وضعیت",
"وضعیت"
// "عملیات",
]
: [
@@ -442,7 +456,7 @@ export const ManageGuilds = ({ userType }) => {
"کشتارگاه ها",
"وضعیت فعالیت",
"وضعیت",
"عملیات",
"عملیات"
]
}
handlePageChange={handlePageChange}

View File

@@ -18,7 +18,6 @@ export const slaughterGetCitiesService = createAsyncThunk(
dispatch(LOADING_START());
const { data, status } = await axios.get("iran_city/?name=" + d);
dispatch(LOADING_END());
return { data, status };
}
);

View File

@@ -14,14 +14,14 @@ import {
ROUTE_ADMINX_ROUTE_OUT_PROVINCE_TRUE_GUILDS,
ROUTE_SLAUGHTER_INVENTORY_SELL_CARCASS_OUT_PROVINCE,
ROUTE_SLAUGHTER_MANAGE_GUILDS_OUT_PROVINCE_TRUE,
ROUTE_STEWARD_SALE_OUT_PROVINCE,
ROUTE_STEWARD_SALE_OUT_PROVINCE
} from "../../../../routes/routes";
import {
handleSetFormDataFromTableDataForStewardAddBuyer,
handleSubmitForStewardAddBuyer,
InquiryForStewardAddBuyer,
StewardAddBuyerForm,
validationSchemaForStewardAddBuyer,
validationSchemaForStewardAddBuyer
} from "./InquiryForStewardAddBuyer";
import { useAddBuyer } from "./hooks/useAddBuyer";
import { slaughterGetCitiesService } from "../../../slaughter-house/services/slaughter-get-provinces";
@@ -30,7 +30,7 @@ import {
handleSubmitForSlaughterAddBuyer,
InquiryForSlaughterAddBuyer,
SlaughterAddBuyerForm,
validationSchemaForSlaughterAddBuyer,
validationSchemaForSlaughterAddBuyer
} from "./InquiryForSlaughterAddBuyer";
import { useFormik } from "formik";
import {
@@ -38,7 +38,7 @@ import {
handleSetFormDataFromTableDataForAdminAddBuyer,
handleSubmitForAdminAddBuyer,
InquiryForAdminAddBuyer,
validationSchemaForAdminAddBuyer,
validationSchemaForAdminAddBuyer
} from "./InquiryForAdminAddBuyer";
import { inspectorGetKillHousesService } from "../../../inspector/services/inspector-get-kill-houses";
import { slaughterGetStewardsForAllocateService } from "../../../slaughter-house/services/slaughter-get-guilds-for-allocate";
@@ -64,7 +64,7 @@ const getCurrentPage = (role, pathname) => {
ROUTE_ADMINX_ROUTE_OUT_PROVINCE_TRUE_GUILDS,
ROUTE_ADMINX_ROUTE_OUT_PROVINCE_LEGAL_GUILDS,
ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL,
ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_TRUE,
ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_TRUE
];
if (routes.some((r) => r === pathname)) {
return "admin_add_buyer";
@@ -79,20 +79,20 @@ const getInitialValues = (page) => {
lastName: "",
unit_name: "",
province: "",
city: "",
city: ""
};
if (page === "steward_add_buyer" || page === "slaughter_manage_add_buyer") {
return initialValues;
} else if (page === "slaughter_add_buyer") {
return {
...initialValues,
nationalId: "",
nationalId: ""
};
} else if (page === "admin_add_buyer") {
return {
...initialValues,
role_key: "",
type: "",
type: ""
};
}
return initialValues;
@@ -103,7 +103,7 @@ export const StewardAddBuyer = ({
isEdit = false,
data,
isRealPerson,
buyerType = "",
buyerType = ""
// buyerYype => "Guilds" | "Steward"
}) => {
const role = getRoleFromUrl();
@@ -124,7 +124,7 @@ export const StewardAddBuyer = ({
cityData,
setCityData,
userData,
setUserData,
setUserData
} = useAddBuyer(page);
const { selectedSubUser } = useSelector((state) => state.userSlice);
@@ -141,7 +141,7 @@ export const StewardAddBuyer = ({
? validationSchemaForSlaughterAddBuyer(isRealPerson, isEdit)
: IS_ADMIN_ADD_BUYER
? validationSchemaForAdminAddBuyer(isRealPerson, isEdit)
: Yup.object({}),
: Yup.object({})
});
useEffect(() => {
@@ -157,7 +157,7 @@ export const StewardAddBuyer = ({
} else {
dispatch(
slaughterGetStewardsForAllocateService({
free: true,
free: true
})
).then((r) => {
setStewards(r.payload.data || []);

View File

@@ -6,19 +6,19 @@ import {
Button,
IconButton,
TextField,
Typography,
Typography
} from "@mui/material";
import SearchIcon from "@mui/icons-material/Search";
import { Yup } from "../../../../lib/yup/yup";
import {
slaughterGetCitiesService,
slaughterGetProvinceService,
slaughterGetProvinceService
} from "../../../slaughter-house/services/slaughter-get-provinces";
import { Grid } from "../../../../components/grid/Grid";
import { SPACING } from "../../../../data/spacing";
import {
stewardSellOutGetBuyers,
stewatdSubmitBuyerDataService,
stewatdSubmitBuyerDataService
} from "../../../guild/services/steward-sell-out-get-buyers";
import { DRAWER, LOADING_END } from "../../../../lib/redux/slices/appSlice";
import { slaughterEditBuyerDataService } from "../../../slaughter-house/services/slaughter-house-submit-buyer";
@@ -29,7 +29,7 @@ import { checkPathStartsWith } from "../../../../utils/checkPathStartsWith";
export const StewardSellOutOfProvinceAddBuyer = ({
updateTable,
isEdit,
data,
data
}) => {
const [openNotif] = useContext(AppContext);
const [userData, setUserData] = useState(null);
@@ -48,7 +48,7 @@ export const StewardSellOutOfProvinceAddBuyer = ({
lastName: "",
unitName: "",
province: "",
city: "",
city: ""
},
validationSchema: Yup.object({
mobile: Yup.string()
@@ -70,22 +70,22 @@ export const StewardSellOutOfProvinceAddBuyer = ({
.typeError("لطفا فیلد را به درستی وارد کنید!"),
city: Yup.string()
.required("این فیلد اجباری است!")
.typeError("لطفا فیلد را به درستی وارد کنید!"),
}),
.typeError("لطفا فیلد را به درستی وارد کنید!")
})
});
const formik2 = useFormik({
initialValues: {
userInfoCheck: "",
userInfoCheck: ""
},
validationSchema: Yup.object({
userInfoCheck: Yup.string()
.required("این فیلد اجباری است!")
.min(11, "شماره موبایل باید 11 رقم باشد")
.max(11, "شماره موبایل باید 11 رقم باشد")
.matches(/^09\d{9}$/, "شماره موبایل باید با 09 شروع شود و 11 رقم باشد"),
.matches(/^09\d{9}$/, "شماره موبایل باید با 09 شروع شود و 11 رقم باشد")
}),
validateOnMount: true,
validateOnMount: true
});
useEffect(() => {
@@ -100,7 +100,7 @@ export const StewardSellOutOfProvinceAddBuyer = ({
lastName: userData.lastName || "",
unitName: userData.unitName || "",
province: userData.province || "",
city: userData.city || "",
city: userData.city || ""
});
setTimeout(() => {
formik.validateForm();
@@ -116,7 +116,7 @@ export const StewardSellOutOfProvinceAddBuyer = ({
lastName: data.lastName || "",
unitName: data.unitName || "",
province: data.province || "",
city: data.city || "",
city: data.city || ""
});
setTimeout(() => {
formik.validateForm();
@@ -194,7 +194,7 @@ export const StewardSellOutOfProvinceAddBuyer = ({
mobile: formik2.values.userInfoCheck,
role_key: checkPathStartsWith("steward")
? selectedSubUser?.key || ""
: "",
: ""
})
).then((r) => {
dispatch(LOADING_END());
@@ -205,7 +205,7 @@ export const StewardSellOutOfProvinceAddBuyer = ({
vertical: "top",
horizontal: "center",
msg: "خریدار یافت نشد، یک خریدار جدید ثبت کنید!",
severity: "error",
severity: "error"
});
} else {
const responseData = r.payload?.data;
@@ -351,7 +351,7 @@ export const StewardSellOutOfProvinceAddBuyer = ({
last_name: formik.values.lastName,
unit_name: formik.values.unitName,
city: formik.values.city,
province: formik.values.province,
province: formik.values.province
})
).then((r) => {
updateTable();
@@ -360,7 +360,7 @@ export const StewardSellOutOfProvinceAddBuyer = ({
vertical: "top",
horizontal: "center",
msg: r.payload.error,
severity: "error",
severity: "error"
});
} else {
dispatch(
@@ -371,7 +371,7 @@ export const StewardSellOutOfProvinceAddBuyer = ({
vertical: "top",
horizontal: "center",
msg: "عملیات با موفقیت انجام شد.",
severity: "success",
severity: "success"
});
}
});
@@ -384,7 +384,7 @@ export const StewardSellOutOfProvinceAddBuyer = ({
last_name: formik.values.lastName,
unit_name: formik.values.unitName,
city: formik.values.city,
province: formik.values.province,
province: formik.values.province
})
).then((r) => {
updateTable();
@@ -393,7 +393,7 @@ export const StewardSellOutOfProvinceAddBuyer = ({
vertical: "top",
horizontal: "center",
msg: r.payload.error,
severity: "error",
severity: "error"
});
} else {
dispatch(
@@ -404,7 +404,7 @@ export const StewardSellOutOfProvinceAddBuyer = ({
vertical: "top",
horizontal: "center",
msg: "عملیات با موفقیت انجام شد.",
severity: "success",
severity: "success"
});
}
});

View File

@@ -6,21 +6,21 @@ import {
Button,
IconButton,
TextField,
Typography,
Typography
} from "@mui/material";
import SearchIcon from "@mui/icons-material/Search";
import { AppContext } from "../../../../contexts/AppContext";
import { Yup } from "../../../../lib/yup/yup";
import {
slaughterGetCitiesService,
slaughterGetProvinceService,
slaughterGetProvinceService
} from "../../../slaughter-house/services/slaughter-get-provinces";
import { Grid } from "../../../../components/grid/Grid";
import { SPACING } from "../../../../data/spacing";
import {
slaughterEditBuyerDataService,
slaughterGetBuyerDataService,
slaughterSubmitBuyerDataService,
slaughterSubmitBuyerDataService
} from "../../../slaughter-house/services/slaughter-house-submit-buyer";
import { DRAWER, LOADING_END } from "../../../../lib/redux/slices/appSlice";
import { fetchStewardBroadcastAndProducts } from "../../services/handle-fetch-steward-products";
@@ -28,7 +28,7 @@ import { fetchStewardBroadcastAndProducts } from "../../services/handle-fetch-st
export const StewardSellOutOfProvinceBuyersEditBuyer = ({
updateTable,
isEdit,
data,
data
}) => {
const [openNotif] = useContext(AppContext);
const [userData, setUserData] = useState(null);
@@ -44,7 +44,7 @@ export const StewardSellOutOfProvinceBuyersEditBuyer = ({
lastName: "",
unitName: "",
province: "",
city: "",
city: ""
},
validationSchema: Yup.object({
mobile: Yup.string()
@@ -66,22 +66,22 @@ export const StewardSellOutOfProvinceBuyersEditBuyer = ({
.typeError("لطفا فیلد را به درستی وارد کنید!"),
city: Yup.string()
.required("این فیلد اجباری است!")
.typeError("لطفا فیلد را به درستی وارد کنید!"),
}),
.typeError("لطفا فیلد را به درستی وارد کنید!")
})
});
const formik2 = useFormik({
initialValues: {
userInfoCheck: "",
userInfoCheck: ""
},
validationSchema: Yup.object({
userInfoCheck: Yup.string()
.required("این فیلد اجباری است!")
.min(11, "شماره موبایل باید 11 رقم باشد")
.max(11, "شماره موبایل باید 11 رقم باشد")
.matches(/^09\d{9}$/, "شماره موبایل باید با 09 شروع شود و 11 رقم باشد"),
.matches(/^09\d{9}$/, "شماره موبایل باید با 09 شروع شود و 11 رقم باشد")
}),
validateOnMount: true,
validateOnMount: true
});
useEffect(() => {
@@ -96,7 +96,7 @@ export const StewardSellOutOfProvinceBuyersEditBuyer = ({
lastName: userData.lastName || "",
unitName: userData.unitName || "",
province: userData.province || "",
city: userData.city || "",
city: userData.city || ""
});
setTimeout(() => {
formik.validateForm();
@@ -112,7 +112,7 @@ export const StewardSellOutOfProvinceBuyersEditBuyer = ({
lastName: data.lastName || "",
unitName: data.unitName || "",
province: data.province || "",
city: data.city || "",
city: data.city || ""
});
setTimeout(() => {
formik.validateForm();
@@ -189,7 +189,7 @@ export const StewardSellOutOfProvinceBuyersEditBuyer = ({
vertical: "top",
horizontal: "center",
msg: "خریدار یافت نشد، یک خریدار جدید ثبت کنید!",
severity: "error",
severity: "error"
});
} else {
setUserData(r.payload.data);
@@ -317,7 +317,7 @@ export const StewardSellOutOfProvinceBuyersEditBuyer = ({
last_name: formik.values.lastName,
unit_name: formik.values.unitName,
city: formik.values.city,
province: formik.values.province,
province: formik.values.province
})
).then((r) => {
updateTable();
@@ -327,7 +327,7 @@ export const StewardSellOutOfProvinceBuyersEditBuyer = ({
vertical: "top",
horizontal: "center",
msg: r.payload.error,
severity: "error",
severity: "error"
});
} else {
dispatch(
@@ -338,7 +338,7 @@ export const StewardSellOutOfProvinceBuyersEditBuyer = ({
vertical: "top",
horizontal: "center",
msg: "عملیات با موفقیت انجام شد.",
severity: "success",
severity: "success"
});
}
});
@@ -350,7 +350,7 @@ export const StewardSellOutOfProvinceBuyersEditBuyer = ({
last_name: formik.values.lastName,
unit_name: formik.values.unitName,
city: formik.values.city,
province: formik.values.province,
province: formik.values.province
})
).then((r) => {
updateTable();
@@ -360,7 +360,7 @@ export const StewardSellOutOfProvinceBuyersEditBuyer = ({
vertical: "top",
horizontal: "center",
msg: r.payload.error,
severity: "error",
severity: "error"
});
} else {
dispatch(
@@ -371,7 +371,7 @@ export const StewardSellOutOfProvinceBuyersEditBuyer = ({
vertical: "top",
horizontal: "center",
msg: "عملیات با موفقیت انجام شد.",
severity: "success",
severity: "success"
});
}
});

View File

@@ -8,13 +8,13 @@ import { AppContext } from "../../../../contexts/AppContext";
import { slaughterGetProductsService } from "../../../slaughter-house/services/slaughter-inventory-gets";
import {
slaughterGetCitiesService,
slaughterGetProvinceService,
slaughterGetProvinceService
} from "../../../slaughter-house/services/slaughter-get-provinces";
import { fixBase64 } from "../../../../utils/toBase64";
import { DRAWER } from "../../../../lib/redux/slices/appSlice";
import {
stewardEditFreeBarService,
stewardSubmitFreeBarService,
stewardSubmitFreeBarService
} from "../../../guild/services/steward-submit-free-bar-service";
import { Grid } from "../../../../components/grid/Grid";
import { SPACING } from "../../../../data/spacing";
@@ -32,7 +32,7 @@ const ValidationSchema = Yup.object().shape({
bar_image: Yup.string().when("$isEdit", {
is: true,
then: Yup.string(),
otherwise: Yup.string().required("عکس بار الزامی است"),
otherwise: Yup.string().required("عکس بار الزامی است")
}),
number_of_carcasses: Yup.number()
.required("حجم لاشه الزامی است")
@@ -40,7 +40,7 @@ const ValidationSchema = Yup.object().shape({
weight_of_carcasses: Yup.number()
.required("وزن لاشه الزامی است")
.min(0.01, "وزن باید بیشتر از 0 باشد"),
product_key: Yup.string().required("انتخاب محصول الزامی است"),
product_key: Yup.string().required("انتخاب محصول الزامی است")
});
export const StewardSubmitFreeBar = ({ updateTable, item }) => {
@@ -59,7 +59,7 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => {
slaughterGetProductsService({
role_key: checkPathStartsWith("steward")
? selectedSubUser?.key || ""
: "",
: ""
})
).then((r) => {
// Handle both direct array response and nested data response
@@ -90,7 +90,7 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => {
role_key: checkPathStartsWith("steward")
? selectedSubUser?.key || ""
: "",
...(item?.key && { key: item.key }),
...(item?.key && { key: item.key })
},
validationSchema: ValidationSchema,
onSubmit: (values) => {
@@ -107,7 +107,7 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => {
vertical: "top",
horizontal: "center",
msg: r.payload.error,
severity: "error",
severity: "error"
});
} else {
updateTable();
@@ -118,7 +118,7 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => {
msg: item?.key
? "اطلاعات خرید با موفقیت ویرایش شد"
: "اطلاعات خرید جدید با موفقیت ثبت شد",
severity: "success",
severity: "success"
});
}
};
@@ -128,7 +128,7 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => {
} else {
dispatch(stewardSubmitFreeBarService(values)).then(thenCallback);
}
},
}
});
const factorPaymentHandler = (imageList) => {
@@ -164,7 +164,7 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => {
Array.isArray(productData) && productData.length > 0
? productData.map((i) => ({
id: i.key,
label: i.name || "",
label: i.name || ""
}))
: []
}
@@ -199,7 +199,7 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => {
style={{
display: "flex",
flexDirection: "column",
gap: SPACING.LARGE,
gap: SPACING.LARGE
}}
>
<TextField
@@ -240,13 +240,13 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => {
id="province"
options={provinceData.map((i) => ({
id: i.name,
label: i.name,
label: i.name
}))}
value={
formik.values.province
? {
id: formik.values.province,
label: formik.values.province,
label: formik.values.province
}
: null
}
@@ -276,7 +276,7 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => {
formik.values.city
? {
id: formik.values.city,
label: formik.values.city,
label: formik.values.city
}
: null
}
@@ -300,9 +300,7 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => {
label="حجم لاشه"
type="number"
InputProps={{
endAdornment: (
<InputAdornment position="end">قطعه</InputAdornment>
),
endAdornment: <InputAdornment position="end">قطعه</InputAdornment>
}}
value={formik.values.number_of_carcasses}
onChange={formik.handleChange}
@@ -325,7 +323,7 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => {
InputProps={{
endAdornment: (
<InputAdornment position="end">کیلوگرم</InputAdornment>
),
)
}}
value={formik.values.weight_of_carcasses}
onChange={formik.handleChange}