diff --git a/src/features/province/components/create-guilds/utils/formUtils.js b/src/features/province/components/create-guilds/utils/formUtils.js index 49a5fe1..233a00a 100644 --- a/src/features/province/components/create-guilds/utils/formUtils.js +++ b/src/features/province/components/create-guilds/utils/formUtils.js @@ -83,7 +83,13 @@ export const getInitialValues = (guildDataForEdit) => { gender: userDataFromEdit.gender || "", person_city: userDataFromEdit.city || cityDataFromEdit?.name || "", city: cityDataFromEdit?.id ?? cityDataFromEdit?.key ?? "", - is_alive: userDataFromEdit.isAlive || "", + is_alive: + userDataFromEdit.isAlive === true || userDataFromEdit.is_alive === true + ? "بلی" + : userDataFromEdit.isAlive === false || + userDataFromEdit.is_alive === false + ? "خیر" + : "", mobile: userDataFromEdit.mobile || "", // Guild Information Fields (from guild object in edit mode) @@ -99,7 +105,8 @@ export const getInitialValues = (guildDataForEdit) => { union_name: guildDataForEdit?.unionName || "", postal_code: addressDataFromEdit.postalCode || "", phone_number: guildDataForEdit?.phoneNumber || "", - license_number: guildDataForEdit?.licenseNumber || "", + license_number: + guildDataForEdit?.license_number ?? guildDataForEdit?.licenseNumber ?? "", // شناسه ملی شرکت: from company_identifier when dbRegister true guild_national_id: guildDataForEdit?.company_identifier ?? @@ -142,7 +149,7 @@ export const getInitialValues = (guildDataForEdit) => { company_identifier: guildDataForEdit?.companyIdentifier || "", type_activity_name: guildDataForEdit?.typeActivityName || "", - // Guilds array for validation (edit mode) + // Guilds array for validation (edit mode) – must include license_number for schema guilds: guildDataForEdit ? [ { @@ -158,6 +165,10 @@ export const getInitialValues = (guildDataForEdit) => { : typeof guildDataForEdit?.isGuild === "boolean" ? guildDataForEdit.isGuild : false, + license_number: + guildDataForEdit?.license_number ?? + guildDataForEdit?.licenseNumber ?? + "", }, ] : [], diff --git a/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsForm.js b/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsForm.js index c565ec2..cd9f007 100644 --- a/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsForm.js +++ b/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsForm.js @@ -229,6 +229,16 @@ const LegalGuildForm = ({ style={{ width: "100%" }} disablePortal id="province" + value={ + provinces?.find((p) => p.key === formik.values.province) + ? { + id: formik.values.province, + label: provinces.find( + (p) => p.key === formik.values.province + )?.name, + } + : null + } options={ provinces ? provinces.map((i) => ({ @@ -255,6 +265,16 @@ const LegalGuildForm = ({ disabled={!formik.values.province} disablePortal id="city" + value={ + cities?.find((c) => c.key === formik.values.city) + ? { + id: formik.values.city, + label: cities.find( + (c) => c.key === formik.values.city + )?.name, + } + : null + } options={ cities ? cities.map((i) => ({ id: i.key, label: i.name })) @@ -387,17 +407,17 @@ export const ProvinceLegalGuildsForm = ({ updateTable, item, userType }) => { national_id: item?.user?.nationalId || "", first_name: item?.user?.firstName || "", last_name: item?.user?.lastName || "", - province: item?.address?.province?.name || "", - city: item?.address?.city?.name || "", - address: item?.address?.address || "", + province: "", + city: "", + address: "", mobile: item?.user?.mobile || "", type_activity: item?.typeActivity || "", }; if (IS_STEWARD) { - userInitialValue["name"] = item?.name; + userInitialValue["name"] = item?.guilds_name || item?.name; } else { - userInitialValue["unit_name"] = item?.guildsName; + userInitialValue["unit_name"] = item?.guilds_name || item?.guildsName; } const dispatch = useDispatch(); @@ -602,6 +622,35 @@ export const ProvinceLegalGuildsForm = ({ updateTable, item, userType }) => { } }, [formik?.values?.province]); + useEffect(() => { + if (item && provinceData && !formik?.values?.province) { + const provinceName = item?.provinceName; + if (provinceName) { + const province = provinceData.find((p) => p?.name === provinceName); + if (province?.key) { + formik?.setFieldValue("province", province.key); + } + } + } + }, [item, provinceData]); + + useEffect(() => { + if ( + item && + cityData?.length && + formik?.values?.province && + !formik?.values?.city + ) { + const cityName = item?.cityName; + if (cityName) { + const city = cityData.find((c) => c?.name === cityName); + if (city?.key) { + formik?.setFieldValue("city", city.key); + } + } + } + }, [item, cityData, formik?.values?.province]); + if (!userData && !item) { return ( { (IS_STEWARD ? item?.name : item?.guildsName) || "-", `${item?.user?.fullname || "-"}`, item?.user?.mobile || "-", - item?.address?.province?.name || "-", - item?.address?.city?.name || "-", + item?.provinceName || "-", + item?.cityName || "-", item?.typeActivity || "-", item?.active ? "فعال" : "غیر فعال", { page: page, pageSize: perPage, searchValue: textValue, - buyer_type: IS_STEWARD ? "Steward" : "Guilds" + buyer_type: IS_STEWARD ? "Steward" : "Guilds", }); setData(response.data.results); setTotalRows(response.data.count); @@ -84,7 +84,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => { 0 ).toLocaleString(), (req?.total_quantity ?? req?.totalQuantity ?? 0).toLocaleString(), - (req?.total_weight ?? req?.totalWeight ?? 0).toLocaleString() + (req?.total_weight ?? req?.totalWeight ?? 0).toLocaleString(), ]; }) ?? []; dispatch( @@ -105,11 +105,11 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => { "شهر", "تعداد درخواست", "حجم (قطعه)", - "وزن (کیلوگرم)" + "وزن (کیلوگرم)", ]} customWidth={"80vw"} /> - ) + ), }) ); }; @@ -131,7 +131,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => { 0 ).toLocaleString(), (req?.total_quantity ?? req?.totalQuantity ?? 0).toLocaleString(), - (req?.total_weight ?? req?.totalWeight ?? 0).toLocaleString() + (req?.total_weight ?? req?.totalWeight ?? 0).toLocaleString(), ]; }) ?? []; dispatch( @@ -151,11 +151,11 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => { "شهر", "تعداد درخواست", "حجم (قطعه)", - "وزن (کیلوگرم)" + "وزن (کیلوگرم)", ]} customWidth={"80vw"} /> - ) + ), }) ); }; @@ -186,7 +186,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => { totalQuantity: acc.totalQuantity + (r?.total_quantity ?? r?.totalQuantity ?? 0), totalWeight: - acc.totalWeight + (r?.total_weight ?? r?.totalWeight ?? 0) + acc.totalWeight + (r?.total_weight ?? r?.totalWeight ?? 0), }; }, { numberOfRequests: 0, totalQuantity: 0, totalWeight: 0 } @@ -222,7 +222,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => { sx={{ minWidth: "fit-content", whiteSpace: "nowrap", - fontSize: "0.8125rem" + fontSize: "0.8125rem", }} variant="outlined" onClick={() => openKillHousesModal(khList)} @@ -240,8 +240,8 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => { borderColor: "#008f6b", "&:hover": { borderColor: "#006b52", - backgroundColor: "rgba(0, 143, 107, 0.08)" - } + backgroundColor: "rgba(0, 143, 107, 0.08)", + }, }} variant="outlined" onClick={() => openStewardsModal(stList)} @@ -270,7 +270,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => { userType={userType} item={item} updateTable={() => fetchApiData(page)} - /> + />, ]; }); @@ -301,7 +301,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => { diff --git a/src/features/steward/components/steward-add-buyer/hooks/useAddBuyer.js b/src/features/steward/components/steward-add-buyer/hooks/useAddBuyer.js index 2248d4b..7164a83 100644 --- a/src/features/steward/components/steward-add-buyer/hooks/useAddBuyer.js +++ b/src/features/steward/components/steward-add-buyer/hooks/useAddBuyer.js @@ -20,13 +20,16 @@ export const useAddBuyer = (page) => { }, []); useEffect(() => { - if (page === "admin_add_buyer") { - const d = inspectorGetKillHouses?.map((item) => { - return { name: item.name, key: item.key, killer: item.killer }; - }); - setKillhouses(d); + if (page === "admin_add_buyer" && inspectorGetKillHouses?.length) { + setKillhouses( + inspectorGetKillHouses.map((item) => ({ + name: item.name, + key: item.key, + killer: item.killer, + })) + ); } - }, [inspectorGetKillHouses]); + }, [page, inspectorGetKillHouses]); return { killHouses,