diff --git a/src/features/province/components/province-mandatory-slaughterhouse-verification-code/ProvinceMandatorySlaughterhouseVerificationCode.js b/src/features/province/components/province-mandatory-slaughterhouse-verification-code/ProvinceMandatorySlaughterhouseVerificationCode.js
index 96354a4..cea90f1 100644
--- a/src/features/province/components/province-mandatory-slaughterhouse-verification-code/ProvinceMandatorySlaughterhouseVerificationCode.js
+++ b/src/features/province/components/province-mandatory-slaughterhouse-verification-code/ProvinceMandatorySlaughterhouseVerificationCode.js
@@ -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 = () => {
},
}}
>
- اجباری بودن کد احراز کشتارگاه
+
+ اجباری بودن کد احراز فروش خارج استان کشتارگاه
+
{
container
alignItems="center"
isPolicy
- gap={2}
+ gap={0.75}
sx={{
width: {
xs: "100%",
@@ -82,7 +82,14 @@ export const ProvinceMandatorySuperVisorAuthenticationCode = () => {
},
}}
>
- اجباری بودن کد احراز مباشر
+
+ اجباری بودن کد احراز فروش خارج استان مباشر{" "}
+
{
const [isFirstLoad, setIsFirstLoad] = useState(true);
@@ -439,6 +440,7 @@ export const ProvincePolicyCouncil = () => {
+
diff --git a/src/features/steward/components/steward-add-buyer/InquiryForAdminAddBuyer.js b/src/features/steward/components/steward-add-buyer/InquiryForAdminAddBuyer.js
index 9c1e169..6cb3c57 100644
--- a/src/features/steward/components/steward-add-buyer/InquiryForAdminAddBuyer.js
+++ b/src/features/steward/components/steward-add-buyer/InquiryForAdminAddBuyer.js
@@ -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;
};
diff --git a/src/features/steward/components/steward-add-buyer/StewardAddBuyer.js b/src/features/steward/components/steward-add-buyer/StewardAddBuyer.js
index a461cca..07457d8 100644
--- a/src/features/steward/components/steward-add-buyer/StewardAddBuyer.js
+++ b/src/features/steward/components/steward-add-buyer/StewardAddBuyer.js
@@ -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);
}
};
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 7164a83..c337c1f 100644
--- a/src/features/steward/components/steward-add-buyer/hooks/useAddBuyer.js
+++ b/src/features/steward/components/steward-add-buyer/hooks/useAddBuyer.js
@@ -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]);
diff --git a/src/utils/toCamelCase.js b/src/utils/toCamelCase.js
index 166e4ba..dbcfb17 100644
--- a/src/utils/toCamelCase.js
+++ b/src/utils/toCamelCase.js
@@ -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();