Fix: Select box inside Steward Add Buyer
This commit is contained in:
@@ -73,7 +73,7 @@ export const ProvinceMandatorySlaughterhouseVerificationCode = () => {
|
|||||||
container
|
container
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
isPolicy
|
isPolicy
|
||||||
gap={2}
|
gap={0.75}
|
||||||
sx={{
|
sx={{
|
||||||
width: {
|
width: {
|
||||||
xs: "100%",
|
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">
|
<Grid xs={12} container justifyContent="space-between">
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={
|
control={
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export const ProvinceMandatorySuperVisorAuthenticationCode = () => {
|
|||||||
container
|
container
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
isPolicy
|
isPolicy
|
||||||
gap={2}
|
gap={0.75}
|
||||||
sx={{
|
sx={{
|
||||||
width: {
|
width: {
|
||||||
xs: "100%",
|
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">
|
<Grid xs={12} container justifyContent="space-between">
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={
|
control={
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ import { ProvincePolicyDirectPurchaseBarLimitation } from "../province-policy-di
|
|||||||
import { ManageEvacuations } from "../manage-evacuations/ManageEvacuations";
|
import { ManageEvacuations } from "../manage-evacuations/ManageEvacuations";
|
||||||
import { ProvincePolicyMarketDailyLimitation } from "../province-policy-market-daily-limitation/ProvincePolicyMarketDailyLimitation";
|
import { ProvincePolicyMarketDailyLimitation } from "../province-policy-market-daily-limitation/ProvincePolicyMarketDailyLimitation";
|
||||||
import { ProvinceHatchingArchivePercent } from "../province-hatching-archive-percent/ProvinceHatchingArchivePercent";
|
import { ProvinceHatchingArchivePercent } from "../province-hatching-archive-percent/ProvinceHatchingArchivePercent";
|
||||||
|
import { ProvinceMandatoryAllocationsRegisterCode } from "../province-mandatory-allocations-register-code/ProvinceMandatoryAllocationsRegisterCode";
|
||||||
|
|
||||||
export const ProvincePolicyCouncil = () => {
|
export const ProvincePolicyCouncil = () => {
|
||||||
const [isFirstLoad, setIsFirstLoad] = useState(true);
|
const [isFirstLoad, setIsFirstLoad] = useState(true);
|
||||||
@@ -439,6 +440,7 @@ export const ProvincePolicyCouncil = () => {
|
|||||||
<ProvincePolicyTradeTimeRange />
|
<ProvincePolicyTradeTimeRange />
|
||||||
<ProvinceMandatorySuperVisorAuthenticationCode />
|
<ProvinceMandatorySuperVisorAuthenticationCode />
|
||||||
<ProvinceMandatorySlaughterhouseVerificationCode />
|
<ProvinceMandatorySlaughterhouseVerificationCode />
|
||||||
|
<ProvinceMandatoryAllocationsRegisterCode />
|
||||||
<ProvincePolicyDirectPurchaseBarLimitation />
|
<ProvincePolicyDirectPurchaseBarLimitation />
|
||||||
<ProvincePolicyMarketDailyLimitation />
|
<ProvincePolicyMarketDailyLimitation />
|
||||||
<ProvinceHatchingArchivePercent />
|
<ProvinceHatchingArchivePercent />
|
||||||
|
|||||||
@@ -139,10 +139,10 @@ export const handleSubmitForAdminAddBuyer = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const extractStewardKeysFromInfo = (steward_info) => {
|
const extractStewardKeysFromInfo = (stewardInfo) => {
|
||||||
if (!Array.isArray(steward_info)) return [];
|
if (!Array.isArray(stewardInfo)) return [];
|
||||||
return steward_info
|
return stewardInfo
|
||||||
.map((item) => item?.Steward?.key ?? item?.key)
|
.map((item) => item?.stewards?.key ?? item?.Steward?.key ?? item?.key)
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -157,21 +157,21 @@ export const handleSetFormDataFromTableDataForAdminAddBuyer = (
|
|||||||
formik
|
formik
|
||||||
) => {
|
) => {
|
||||||
const steward_keys =
|
const steward_keys =
|
||||||
item?.steward_keys ??
|
item?.stewardKeys ??
|
||||||
extractStewardKeysFromInfo(item?.stewardInfo) ??
|
extractStewardKeysFromInfo(item?.stewardInfo) ??
|
||||||
formik.values?.steward_keys ??
|
formik.values?.steward_keys ??
|
||||||
[];
|
[];
|
||||||
const kill_house_keys =
|
const killHouseInfoArray = item?.killHouseInfo ?? [];
|
||||||
extractKillHouseKeysFromInfo(item?.killHouseInfo) ?? [];
|
const kill_house_keys = extractKillHouseKeysFromInfo(killHouseInfoArray);
|
||||||
|
|
||||||
const formData = {
|
const formData = {
|
||||||
mobile: item.mobile || "",
|
mobile: item.mobile ?? "",
|
||||||
firstName: item.firstName || "",
|
firstName: item.firstName ?? "",
|
||||||
lastName: item.lastName || "",
|
lastName: item.lastName ?? "",
|
||||||
province: item.province || "",
|
province: item.province ?? "",
|
||||||
city: item.city || "",
|
city: item.city ?? "",
|
||||||
nationalId: item.nationalId || "",
|
nationalId: item.nationalId ?? "",
|
||||||
unit_name: item?.unitName || "",
|
unit_name: item?.unitName ?? "",
|
||||||
steward_keys,
|
steward_keys,
|
||||||
kill_house_keys,
|
kill_house_keys,
|
||||||
};
|
};
|
||||||
@@ -395,11 +395,16 @@ export const AdminAddBuyerForm = ({
|
|||||||
item?.user?.mobile || ""
|
item?.user?.mobile || ""
|
||||||
})`;
|
})`;
|
||||||
const fromEdit = (editData?.stewardInfo || []).find(
|
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)
|
if (fromEdit)
|
||||||
return (
|
return (
|
||||||
fromEdit?.Steward?.name || fromEdit?.fullname || fromEdit?.name || null
|
fromEdit?.stewards?.name ||
|
||||||
|
fromEdit?.Steward?.name ||
|
||||||
|
fromEdit?.fullname ||
|
||||||
|
fromEdit?.name ||
|
||||||
|
null
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import {
|
|||||||
} from "./InquiryForAdminAddBuyer";
|
} from "./InquiryForAdminAddBuyer";
|
||||||
import { inspectorGetKillHousesService } from "../../../inspector/services/inspector-get-kill-houses";
|
import { inspectorGetKillHousesService } from "../../../inspector/services/inspector-get-kill-houses";
|
||||||
import { slaughterGetStewardsForAllocateService } from "../../../slaughter-house/services/slaughter-get-guilds-for-allocate";
|
import { slaughterGetStewardsForAllocateService } from "../../../slaughter-house/services/slaughter-get-guilds-for-allocate";
|
||||||
|
import { objectKeysToCamel } from "../../../../utils/toCamelCase";
|
||||||
|
|
||||||
const PAGE_STEWARD = "steward_add_buyer";
|
const PAGE_STEWARD = "steward_add_buyer";
|
||||||
const PAGE_SLAUGHTER = "slaughter_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) {
|
} else if (page === PAGE_SLAUGHTER || page === PAGE_SLAUGHTER_MANAGE) {
|
||||||
handleSetFormDataFromTableDataForSlaughterAddBuyer(data, formik);
|
handleSetFormDataFromTableDataForSlaughterAddBuyer(data, formik);
|
||||||
} else if (page === PAGE_ADMIN) {
|
} else if (page === PAGE_ADMIN) {
|
||||||
handleSetFormDataFromTableDataForAdminAddBuyer(data, formik);
|
const dataCamel = objectKeysToCamel(data);
|
||||||
|
handleSetFormDataFromTableDataForAdminAddBuyer(dataCamel, formik);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { slaughterGetProvinceService } from "../../../../slaughter-house/services/slaughter-get-provinces";
|
import { slaughterGetProvinceService } from "../../../../slaughter-house/services/slaughter-get-provinces";
|
||||||
|
import { objectKeysToCamel } from "../../../../../utils/toCamelCase";
|
||||||
|
|
||||||
export const useAddBuyer = (page) => {
|
export const useAddBuyer = (page) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -22,11 +23,14 @@ export const useAddBuyer = (page) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (page === "admin_add_buyer" && inspectorGetKillHouses?.length) {
|
if (page === "admin_add_buyer" && inspectorGetKillHouses?.length) {
|
||||||
setKillhouses(
|
setKillhouses(
|
||||||
inspectorGetKillHouses.map((item) => ({
|
inspectorGetKillHouses.map((item) => {
|
||||||
name: item.name,
|
const camel = objectKeysToCamel(item);
|
||||||
key: item.key,
|
return {
|
||||||
killer: item.killer,
|
name: camel.name,
|
||||||
}))
|
key: camel.key,
|
||||||
|
killer: camel.killer,
|
||||||
|
};
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [page, inspectorGetKillHouses]);
|
}, [page, inspectorGetKillHouses]);
|
||||||
|
|||||||
@@ -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) {
|
export function toUnderscore(str) {
|
||||||
return str.replace(/[A-Z]/g, function (match) {
|
return str.replace(/[A-Z]/g, function (match) {
|
||||||
return "_" + match.toLowerCase();
|
return "_" + match.toLowerCase();
|
||||||
|
|||||||
Reference in New Issue
Block a user