Fix: Select box inside Steward Add Buyer

This commit is contained in:
2026-02-10 08:28:40 +03:30
parent cde12aa81a
commit 080d02ab21
7 changed files with 68 additions and 26 deletions

View File

@@ -73,7 +73,7 @@ export const ProvinceMandatorySlaughterhouseVerificationCode = () => {
container
alignItems="center"
isPolicy
gap={2}
gap={0.75}
sx={{
width: {
xs: "100%",
@@ -83,7 +83,14 @@ export const ProvinceMandatorySlaughterhouseVerificationCode = () => {
},
}}
>
<Typography variant="body1">اجباری بودن کد احراز کشتارگاه</Typography>
<Typography
variant="body1"
sx={{
textAlign: "left",
}}
>
اجباری بودن کد احراز فروش خارج استان کشتارگاه
</Typography>
<Grid xs={12} container justifyContent="space-between">
<FormControlLabel
control={

View File

@@ -72,7 +72,7 @@ export const ProvinceMandatorySuperVisorAuthenticationCode = () => {
container
alignItems="center"
isPolicy
gap={2}
gap={0.75}
sx={{
width: {
xs: "100%",
@@ -82,7 +82,14 @@ export const ProvinceMandatorySuperVisorAuthenticationCode = () => {
},
}}
>
<Typography variant="body1">اجباری بودن کد احراز مباشر</Typography>
<Typography
variant="body1"
sx={{
textAlign: "left",
}}
>
اجباری بودن کد احراز فروش خارج استان مباشر{" "}
</Typography>
<Grid xs={12} container justifyContent="space-between">
<FormControlLabel
control={

View File

@@ -72,6 +72,7 @@ import { ProvincePolicyDirectPurchaseBarLimitation } from "../province-policy-di
import { ManageEvacuations } from "../manage-evacuations/ManageEvacuations";
import { ProvincePolicyMarketDailyLimitation } from "../province-policy-market-daily-limitation/ProvincePolicyMarketDailyLimitation";
import { ProvinceHatchingArchivePercent } from "../province-hatching-archive-percent/ProvinceHatchingArchivePercent";
import { ProvinceMandatoryAllocationsRegisterCode } from "../province-mandatory-allocations-register-code/ProvinceMandatoryAllocationsRegisterCode";
export const ProvincePolicyCouncil = () => {
const [isFirstLoad, setIsFirstLoad] = useState(true);
@@ -439,6 +440,7 @@ export const ProvincePolicyCouncil = () => {
<ProvincePolicyTradeTimeRange />
<ProvinceMandatorySuperVisorAuthenticationCode />
<ProvinceMandatorySlaughterhouseVerificationCode />
<ProvinceMandatoryAllocationsRegisterCode />
<ProvincePolicyDirectPurchaseBarLimitation />
<ProvincePolicyMarketDailyLimitation />
<ProvinceHatchingArchivePercent />

View File

@@ -139,10 +139,10 @@ export const handleSubmitForAdminAddBuyer = (
}
};
const extractStewardKeysFromInfo = (steward_info) => {
if (!Array.isArray(steward_info)) return [];
return steward_info
.map((item) => item?.Steward?.key ?? item?.key)
const extractStewardKeysFromInfo = (stewardInfo) => {
if (!Array.isArray(stewardInfo)) return [];
return stewardInfo
.map((item) => item?.stewards?.key ?? item?.Steward?.key ?? item?.key)
.filter(Boolean);
};
@@ -157,21 +157,21 @@ export const handleSetFormDataFromTableDataForAdminAddBuyer = (
formik
) => {
const steward_keys =
item?.steward_keys ??
item?.stewardKeys ??
extractStewardKeysFromInfo(item?.stewardInfo) ??
formik.values?.steward_keys ??
[];
const kill_house_keys =
extractKillHouseKeysFromInfo(item?.killHouseInfo) ?? [];
const killHouseInfoArray = item?.killHouseInfo ?? [];
const kill_house_keys = extractKillHouseKeysFromInfo(killHouseInfoArray);
const formData = {
mobile: item.mobile || "",
firstName: item.firstName || "",
lastName: item.lastName || "",
province: item.province || "",
city: item.city || "",
nationalId: item.nationalId || "",
unit_name: item?.unitName || "",
mobile: item.mobile ?? "",
firstName: item.firstName ?? "",
lastName: item.lastName ?? "",
province: item.province ?? "",
city: item.city ?? "",
nationalId: item.nationalId ?? "",
unit_name: item?.unitName ?? "",
steward_keys,
kill_house_keys,
};
@@ -395,11 +395,16 @@ export const AdminAddBuyerForm = ({
item?.user?.mobile || ""
})`;
const fromEdit = (editData?.stewardInfo || []).find(
(s) => s?.Steward?.key === key || s?.key === key
(s) =>
s?.stewards?.key === key || s?.Steward?.key === key || s?.key === key
);
if (fromEdit)
return (
fromEdit?.Steward?.name || fromEdit?.fullname || fromEdit?.name || null
fromEdit?.stewards?.name ||
fromEdit?.Steward?.name ||
fromEdit?.fullname ||
fromEdit?.name ||
null
);
return null;
};

View File

@@ -42,6 +42,7 @@ import {
} from "./InquiryForAdminAddBuyer";
import { inspectorGetKillHousesService } from "../../../inspector/services/inspector-get-kill-houses";
import { slaughterGetStewardsForAllocateService } from "../../../slaughter-house/services/slaughter-get-guilds-for-allocate";
import { objectKeysToCamel } from "../../../../utils/toCamelCase";
const PAGE_STEWARD = "steward_add_buyer";
const PAGE_SLAUGHTER = "slaughter_add_buyer";
@@ -109,7 +110,8 @@ const setFormDataFromTableData = (page, data, formik) => {
} else if (page === PAGE_SLAUGHTER || page === PAGE_SLAUGHTER_MANAGE) {
handleSetFormDataFromTableDataForSlaughterAddBuyer(data, formik);
} else if (page === PAGE_ADMIN) {
handleSetFormDataFromTableDataForAdminAddBuyer(data, formik);
const dataCamel = objectKeysToCamel(data);
handleSetFormDataFromTableDataForAdminAddBuyer(dataCamel, formik);
}
};

View File

@@ -1,6 +1,7 @@
import { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { slaughterGetProvinceService } from "../../../../slaughter-house/services/slaughter-get-provinces";
import { objectKeysToCamel } from "../../../../../utils/toCamelCase";
export const useAddBuyer = (page) => {
const dispatch = useDispatch();
@@ -22,11 +23,14 @@ export const useAddBuyer = (page) => {
useEffect(() => {
if (page === "admin_add_buyer" && inspectorGetKillHouses?.length) {
setKillhouses(
inspectorGetKillHouses.map((item) => ({
name: item.name,
key: item.key,
killer: item.killer,
}))
inspectorGetKillHouses.map((item) => {
const camel = objectKeysToCamel(item);
return {
name: camel.name,
key: camel.key,
killer: camel.killer,
};
})
);
}
}, [page, inspectorGetKillHouses]);

View File

@@ -4,6 +4,21 @@ export function toCamelCase(str) {
});
}
/**
* Recursively converts object keys from snake_case to camelCase.
* e.g. { kill_house_info: [...] } => { killHouseInfo: [...] }
*/
export function objectKeysToCamel(obj) {
if (obj === null || typeof obj !== "object") return obj;
if (Array.isArray(obj)) return obj.map(objectKeysToCamel);
return Object.keys(obj).reduce((acc, key) => {
const camelKey = toCamelCase(key);
const camelKeyLower = camelKey.charAt(0).toLowerCase() + camelKey.slice(1);
acc[camelKeyLower] = objectKeysToCamel(obj[key]);
return acc;
}, {});
}
export function toUnderscore(str) {
return str.replace(/[A-Z]/g, function (match) {
return "_" + match.toLowerCase();