diff --git a/src/features/province/components/create-guilds/CreateGuilds.js b/src/features/province/components/create-guilds/CreateGuilds.js index 7c3e131..0cb3884 100644 --- a/src/features/province/components/create-guilds/CreateGuilds.js +++ b/src/features/province/components/create-guilds/CreateGuilds.js @@ -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 }) => { 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, diff --git a/src/features/province/components/create-guilds/components/FormActions.js b/src/features/province/components/create-guilds/components/FormActions.js index 51d9b3d..fe6989a 100644 --- a/src/features/province/components/create-guilds/components/FormActions.js +++ b/src/features/province/components/create-guilds/components/FormActions.js @@ -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 = ({ > ثبت - {isKillHouse && !isAreaActivityValid && ( + {blockingErrors.length > 0 && ( - رسته واحد صنفی باید شامل کلمه "مرغ" باشد - - )} - {hasGuildsError && ( - - {typeof formik.errors.guilds === "string" - ? formik.errors.guilds - : "برای هر واحد صنفی، حداقل یکی از گزینه‌های مباشر یا صنف باید انتخاب شود"} + {blockingErrors.map((msg, i) => ( + + • {msg} + + ))} )} diff --git a/src/features/province/components/create-guilds/utils/dataMapping.js b/src/features/province/components/create-guilds/utils/dataMapping.js index a936edb..caaa016 100644 --- a/src/features/province/components/create-guilds/utils/dataMapping.js +++ b/src/features/province/components/create-guilds/utils/dataMapping.js @@ -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 }; }; diff --git a/src/features/province/components/create-guilds/utils/formUtils.js b/src/features/province/components/create-guilds/utils/formUtils.js index 8785854..6702291 100644 --- a/src/features/province/components/create-guilds/utils/formUtils.js +++ b/src/features/province/components/create-guilds/utils/formUtils.js @@ -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 + } ] - : [], + : [] }; }; diff --git a/src/features/province/components/manage-guilds/ManageGuilds.js b/src/features/province/components/manage-guilds/ManageGuilds.js index 1466f54..a2a71b0 100644 --- a/src/features/province/components/manage-guilds/ManageGuilds.js +++ b/src/features/province/components/manage-guilds/ManageGuilds.js @@ -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( - + (item?.stewards?.length || 0) === 0 ? ( + "ندارد" + ) : ( + + ) ); commonData.push( - + (item?.killHouse?.length || 0) === 0 ? ( + "ندارد" + ) : ( + + ) ); } @@ -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: , + content: }) ); }} @@ -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} diff --git a/src/features/slaughter-house/services/slaughter-get-provinces.js b/src/features/slaughter-house/services/slaughter-get-provinces.js index fecdc3d..52a6760 100644 --- a/src/features/slaughter-house/services/slaughter-get-provinces.js +++ b/src/features/slaughter-house/services/slaughter-get-provinces.js @@ -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 }; } ); diff --git a/src/features/steward/components/steward-add-buyer/StewardAddBuyer.js b/src/features/steward/components/steward-add-buyer/StewardAddBuyer.js index 2b9290a..c94911e 100644 --- a/src/features/steward/components/steward-add-buyer/StewardAddBuyer.js +++ b/src/features/steward/components/steward-add-buyer/StewardAddBuyer.js @@ -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 || []); diff --git a/src/features/steward/components/steward-purchase-out-province-add-buyer/StewardSellOutOfProvinceAddBuyer.js b/src/features/steward/components/steward-purchase-out-province-add-buyer/StewardSellOutOfProvinceAddBuyer.js index 304f9fe..d92c593 100644 --- a/src/features/steward/components/steward-purchase-out-province-add-buyer/StewardSellOutOfProvinceAddBuyer.js +++ b/src/features/steward/components/steward-purchase-out-province-add-buyer/StewardSellOutOfProvinceAddBuyer.js @@ -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" }); } }); diff --git a/src/features/steward/components/steward-sell-out-of-province-buyers-edit-buyer/StewardSellOutOfProvinceBuyersEditBuyer.js b/src/features/steward/components/steward-sell-out-of-province-buyers-edit-buyer/StewardSellOutOfProvinceBuyersEditBuyer.js index 06c5705..e8d9cb9 100644 --- a/src/features/steward/components/steward-sell-out-of-province-buyers-edit-buyer/StewardSellOutOfProvinceBuyersEditBuyer.js +++ b/src/features/steward/components/steward-sell-out-of-province-buyers-edit-buyer/StewardSellOutOfProvinceBuyersEditBuyer.js @@ -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" }); } }); diff --git a/src/features/steward/components/steward-submit-free-bar/StewardSubmitFreeBar.js b/src/features/steward/components/steward-submit-free-bar/StewardSubmitFreeBar.js index 3efcd0b..293678a 100644 --- a/src/features/steward/components/steward-submit-free-bar/StewardSubmitFreeBar.js +++ b/src/features/steward/components/steward-submit-free-bar/StewardSubmitFreeBar.js @@ -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 }} > { 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: ( - قطعه - ), + endAdornment: قطعه }} value={formik.values.number_of_carcasses} onChange={formik.handleChange} @@ -325,7 +323,7 @@ export const StewardSubmitFreeBar = ({ updateTable, item }) => { InputProps={{ endAdornment: ( کیلوگرم - ), + ) }} value={formik.values.weight_of_carcasses} onChange={formik.handleChange}