before killhouses options
This commit is contained in:
@@ -12,7 +12,7 @@ import { useDispatch } from "react-redux";
|
||||
import { RiSearchLine } from "react-icons/ri";
|
||||
import { fetchOutProvinceLegalBuyers } from "../../services/province-out-province-buyers";
|
||||
import { ProvinceTrueGuildsOutProvinceOperations } from "../province-true-guilds-out-province/ProvinceTrueGuildsOutProvinceOperations";
|
||||
import { SlaughterSellCarcassOutProvinceAddBuyer } from "../../../slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer";
|
||||
import { StewardAddBuyer } from "../../../steward/components/steward-add-buyer/StewardAddBuyer";
|
||||
|
||||
export const ProvinceLegalGuildsOutProvince = ({ userType }) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
@@ -120,13 +120,12 @@ export const ProvinceLegalGuildsOutProvince = ({ userType }) => {
|
||||
bottom: window.innerWidth <= 600,
|
||||
size: 340,
|
||||
content: (
|
||||
<SlaughterSellCarcassOutProvinceAddBuyer
|
||||
<StewardAddBuyer
|
||||
updateTable={() => {
|
||||
setPage(1);
|
||||
fetchApiData(1);
|
||||
}}
|
||||
defaultPersonType={"legal"}
|
||||
userType={userType}
|
||||
buyerType={IS_STEWARD ? "Steward" : "Guilds"}
|
||||
/>
|
||||
),
|
||||
title: `افزودن ${IS_STEWARD ? "مباشر" : "صنف"} خارج از استان`,
|
||||
|
||||
@@ -13,8 +13,8 @@ import { useDispatch } from "react-redux";
|
||||
import { RiSearchLine } from "react-icons/ri";
|
||||
import { fetchOutProvinceRealBuyers } from "../../services/province-out-province-buyers";
|
||||
import { ProvinceTrueGuildsOutProvinceOperations } from "./ProvinceTrueGuildsOutProvinceOperations";
|
||||
import { SlaughterSellCarcassOutProvinceAddBuyer } from "../../../slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
import { StewardAddBuyer } from "../../../steward/components/steward-add-buyer/StewardAddBuyer";
|
||||
|
||||
export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
@@ -164,17 +164,17 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||
const d = data?.map((item, i) => {
|
||||
const khList = killHouseList(item);
|
||||
const stList = stewardList(item);
|
||||
const firstKillHouse = khList?.[0];
|
||||
const kh = firstKillHouse?.Kill_house ?? firstKillHouse?.KillHouse ?? {};
|
||||
const killHouseName = kh?.name ?? item?.KillHouse?.name ?? "-";
|
||||
const killHouseOperator =
|
||||
firstKillHouse?.fullname ??
|
||||
item?.KillHouse?.killHouseOperator?.user?.fullname ??
|
||||
"";
|
||||
const killHouseDisplay =
|
||||
killHouseOperator && killHouseOperator !== "-"
|
||||
? `${killHouseName} (${killHouseOperator})`
|
||||
: killHouseName;
|
||||
// const firstKillHouse = khList?.[0];
|
||||
// const kh = firstKillHouse?.Kill_house ?? firstKillHouse?.KillHouse ?? {};
|
||||
// const killHouseName = kh?.name ?? item?.KillHouse?.name ?? "-";
|
||||
// const killHouseOperator =
|
||||
// firstKillHouse?.fullname ??
|
||||
// item?.KillHouse?.killHouseOperator?.user?.fullname ??
|
||||
// "";
|
||||
// const killHouseDisplay =
|
||||
// killHouseOperator && killHouseOperator !== "-"
|
||||
// ? `${killHouseName} (${killHouseOperator})`
|
||||
// : killHouseName;
|
||||
|
||||
const totalRequests = khList.reduce(
|
||||
(acc, entry) => {
|
||||
@@ -257,8 +257,9 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
`${item?.fullname ?? ""} (${item?.mobile ?? ""})`,
|
||||
item?.nationalId ?? "-",
|
||||
item?.unit_name ?? item?.unitName ?? "-",
|
||||
killHouseDisplay,
|
||||
// killHouseDisplay,
|
||||
item?.province ?? "-",
|
||||
item?.city ?? "-",
|
||||
listButtons,
|
||||
@@ -310,13 +311,13 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||
bottom: window.innerWidth <= 600,
|
||||
size: 340,
|
||||
content: (
|
||||
<SlaughterSellCarcassOutProvinceAddBuyer
|
||||
<StewardAddBuyer
|
||||
updateTable={() => {
|
||||
setPage(1);
|
||||
fetchApiData(1);
|
||||
}}
|
||||
defaultPersonType={"real"}
|
||||
userType={userType}
|
||||
isRealPerson
|
||||
buyerType={IS_STEWARD ? "Steward" : "Guilds"}
|
||||
/>
|
||||
),
|
||||
title: `افزودن ${
|
||||
@@ -353,8 +354,8 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||
columns={[
|
||||
"ردیف",
|
||||
"مشخصات خریدار",
|
||||
"کد ملی",
|
||||
"نام واحد",
|
||||
"کشتارگاه",
|
||||
"استان",
|
||||
"شهر",
|
||||
"کشتارگاه ها / مباشرین",
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import DeleteIcon from "@mui/icons-material/Delete";
|
||||
import { deleteOutProvinceTrueGuilds } from "../../services/delete-out-province-true-guilds";
|
||||
import { SlaughterSellCarcassOutProvinceAddBuyer } from "../../../slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer";
|
||||
import { StewardAddBuyer } from "../../../steward/components/steward-add-buyer/StewardAddBuyer";
|
||||
|
||||
export const ProvinceTrueGuildsOutProvinceOperations = ({
|
||||
item,
|
||||
@@ -90,21 +90,12 @@ export const ProvinceTrueGuildsOutProvinceOperations = ({
|
||||
right: !(window.innerWidth <= 600),
|
||||
bottom: window.innerWidth <= 600,
|
||||
content: (
|
||||
<SlaughterSellCarcassOutProvinceAddBuyer
|
||||
<StewardAddBuyer
|
||||
updateTable={updateTable}
|
||||
isEdit
|
||||
data={item}
|
||||
defaultPersonType={
|
||||
item?.buyer?.parentLegalPersonNationalCode
|
||||
? "legal"
|
||||
: "real"
|
||||
}
|
||||
defaultNationalCode={
|
||||
IS_STEWARD
|
||||
? item?.buyer?.nationalId
|
||||
: item?.buyer?.nationalCode
|
||||
}
|
||||
userType={userType}
|
||||
isRealPerson
|
||||
buyerType={IS_STEWARD ? "Steward" : "Guilds"}
|
||||
/>
|
||||
),
|
||||
})
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { SlaughterSellCarcassOutProvinceAddBuyer } from "../slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import { RiSearchLine } from "react-icons/ri";
|
||||
import { checkPathStartsWith } from "../../../../utils/checkPathStartsWith";
|
||||
|
||||
@@ -4,29 +4,15 @@ import { useDispatch } from "react-redux";
|
||||
import { useFormik } from "formik";
|
||||
import { Yup } from "../../../../lib/yup/yup";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import {
|
||||
Autocomplete,
|
||||
FormControl,
|
||||
FormControlLabel,
|
||||
IconButton,
|
||||
InputLabel,
|
||||
MenuItem,
|
||||
Radio,
|
||||
RadioGroup,
|
||||
Select,
|
||||
TextField,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { Autocomplete, IconButton, TextField, Typography } from "@mui/material";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
import SearchIcon from "@mui/icons-material/Search";
|
||||
import { extractProvinceFromAddress } from "../../../../utils/address";
|
||||
import { provinceGetNationalDocumentsService } from "../../../province/services/province-get-national-documents";
|
||||
import { getCarcassesBuyerInfoService } from "../../../steward/services/get-carcasses-buyer-info";
|
||||
import {
|
||||
slaughterEditBuyerDataService,
|
||||
slaughterSubmitBuyerDataService,
|
||||
} from "../../../slaughter-house/services/slaughter-house-submit-buyer";
|
||||
import { LabelField } from "../../../../components/label-field/LabelField";
|
||||
|
||||
export const validationSchemaForAdminAddBuyer = (isEdit, isRealPerson) =>
|
||||
Yup.object({
|
||||
mobile: Yup.string()
|
||||
@@ -55,9 +41,12 @@ export const validationSchemaForAdminAddBuyer = (isEdit, isRealPerson) =>
|
||||
: Yup.string()
|
||||
.required("این فیلد اجباری است!")
|
||||
.matches(/^\d{10,11}$/, "شناسه باید 10 یا 11 رقم و فقط عدد باشد"),
|
||||
role_key: Yup.string().required("این فیلد اجباری است!"),
|
||||
type: Yup.string().oneOf(["Steward", "KillHouse"]).required(),
|
||||
});
|
||||
}).test(
|
||||
"at-least-one-key",
|
||||
"حداقل یک کشتارگاه یا مباشر باید انتخاب شود",
|
||||
(value) =>
|
||||
value?.steward_keys?.length > 0 || value?.kill_house_keys?.length > 0
|
||||
);
|
||||
|
||||
export const handleSubmitForAdminAddBuyer = (
|
||||
formik,
|
||||
@@ -81,8 +70,8 @@ export const handleSubmitForAdminAddBuyer = (
|
||||
province: formik.values.province,
|
||||
national_id: formik.values.nationalId,
|
||||
unit_name: formik.values.unit_name,
|
||||
type: formik.values.type,
|
||||
role_key: formik.values.role_key,
|
||||
steward_keys: formik.values.steward_keys || [],
|
||||
kill_house_keys: formik.values.kill_house_keys || [],
|
||||
};
|
||||
|
||||
dispatch(slaughterEditBuyerDataService(submitData)).then((r) => {
|
||||
@@ -115,8 +104,8 @@ export const handleSubmitForAdminAddBuyer = (
|
||||
province: formik.values.province,
|
||||
unit_name: formik.values.unit_name,
|
||||
national_id: !isRealPerson ? null : formik.values.nationalId,
|
||||
type: formik.values.type,
|
||||
role_key: formik.values.role_key,
|
||||
steward_keys: formik.values.steward_keys || [],
|
||||
kill_house_keys: formik.values.kill_house_keys || [],
|
||||
...(!isRealPerson && {
|
||||
isRealPerson: false,
|
||||
info_value: formik.values.nationalId,
|
||||
@@ -150,20 +139,41 @@ export const handleSubmitForAdminAddBuyer = (
|
||||
}
|
||||
};
|
||||
|
||||
const extractStewardKeysFromInfo = (steward_info) => {
|
||||
if (!Array.isArray(steward_info)) return [];
|
||||
return steward_info
|
||||
.map((item) => item?.Steward?.key ?? item?.key)
|
||||
.filter(Boolean);
|
||||
};
|
||||
|
||||
const extractKillHouseKeysFromInfo = (killHouseInfo) => {
|
||||
const arr = killHouseInfo ?? [];
|
||||
if (!Array.isArray(arr)) return [];
|
||||
return arr.map((item) => item?.killHouse?.key).filter(Boolean);
|
||||
};
|
||||
|
||||
export const handleSetFormDataFromTableDataForAdminAddBuyer = (
|
||||
tableData,
|
||||
item,
|
||||
formik
|
||||
) => {
|
||||
const steward_keys =
|
||||
item?.steward_keys ??
|
||||
extractStewardKeysFromInfo(item?.stewardInfo) ??
|
||||
formik.values?.steward_keys ??
|
||||
[];
|
||||
const kill_house_keys =
|
||||
extractKillHouseKeysFromInfo(item?.killHouseInfo) ?? [];
|
||||
|
||||
const formData = {
|
||||
mobile: tableData.mobile || "",
|
||||
firstName: tableData.firstName || "",
|
||||
lastName: tableData.lastName || "",
|
||||
province: tableData.province || "",
|
||||
city: tableData.city || "",
|
||||
nationalId: tableData.nationalId || "",
|
||||
unit_name: tableData?.unitName || "",
|
||||
type: formik.values?.type,
|
||||
role_key: formik.values?.role_key,
|
||||
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,
|
||||
};
|
||||
|
||||
formik.setValues(formData);
|
||||
@@ -186,8 +196,8 @@ export const handleSetFormDataFromUserDataForAdminAddBuyer = (
|
||||
city: userData.city || "",
|
||||
nationalId: userData.nationalId || "",
|
||||
unit_name: userData?.unitName || "",
|
||||
type: formik.values?.type,
|
||||
role_key: formik.values?.role_key,
|
||||
steward_keys: formik.values?.steward_keys ?? [],
|
||||
kill_house_keys: formik.values?.kill_house_keys ?? [],
|
||||
};
|
||||
|
||||
formik.setValues(formData);
|
||||
@@ -248,22 +258,28 @@ export const InquiryForAdminAddBuyer = ({
|
||||
|
||||
const nationalCode = formik2.values.nationalCode;
|
||||
const personType = formik2.values.personType;
|
||||
const type = personType === "legal" ? "unit" : "person";
|
||||
|
||||
setInquiryInProgress(true);
|
||||
setNotFound(false);
|
||||
setUserData(null);
|
||||
|
||||
let personData = null;
|
||||
let selectedGuild = null;
|
||||
|
||||
try {
|
||||
if (personType === "legal") {
|
||||
const url = `https://pay.rasadyar.com/national-documents?info=${encodeURIComponent(
|
||||
nationalCode
|
||||
)}&type=unit`;
|
||||
const res = await fetch(url);
|
||||
const json = await res.json();
|
||||
const response = await dispatch(
|
||||
getCarcassesBuyerInfoService({ info: nationalCode, type })
|
||||
);
|
||||
|
||||
if (response.payload?.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: response.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const json = response.payload?.data;
|
||||
if (json?.status && json?.data) {
|
||||
const d = json.data;
|
||||
const extractedProvince = extractProvinceFromAddress(
|
||||
@@ -271,16 +287,17 @@ export const InquiryForAdminAddBuyer = ({
|
||||
provinceData
|
||||
);
|
||||
const aggregatedUserData = {
|
||||
mobile: d.mobile,
|
||||
firstName: d.name || "",
|
||||
lastName: d.name || "",
|
||||
unitName: d.unitName || "",
|
||||
province: d.state || extractedProvince || "",
|
||||
mobile: d.mobile || d.mobilenumber || "",
|
||||
firstName: d.firstName || d.name || "",
|
||||
lastName: d.lastName || d.name || "",
|
||||
unitName:
|
||||
d.unitName || d.title || d.corporationName || d.unionName || "",
|
||||
province: d.province || d.state || extractedProvince || "",
|
||||
city: d.city || "",
|
||||
nationalId: d.nationalCode || nationalCode,
|
||||
type: formik.values?.type,
|
||||
role_key: formik.values?.role_key,
|
||||
nationalId:
|
||||
d.nationalId || d.nationalCode || d.nationalcode || nationalCode,
|
||||
};
|
||||
setUserData(aggregatedUserData);
|
||||
handleSetFormDataFromUserDataForAdminAddBuyer(
|
||||
aggregatedUserData,
|
||||
formik
|
||||
@@ -292,7 +309,10 @@ export const InquiryForAdminAddBuyer = ({
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "اطلاعات حقوقی با موفقیت دریافت شد.",
|
||||
msg:
|
||||
type === "unit"
|
||||
? "اطلاعات حقوقی با موفقیت دریافت شد."
|
||||
: "اطلاعات با موفقیت دریافت شد.",
|
||||
severity: "success",
|
||||
});
|
||||
} else {
|
||||
@@ -301,133 +321,13 @@ export const InquiryForAdminAddBuyer = ({
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "اطلاعات حقوقی برای این شناسه یافت نشد، لطفا اطلاعات را به صورت دستی ثبت کنید.",
|
||||
msg:
|
||||
type === "unit"
|
||||
? "اطلاعات حقوقی برای این شناسه یافت نشد، لطفا اطلاعات را به صورت دستی ثبت کنید."
|
||||
: "اطلاعاتی برای این کد ملی یافت نشد، لطفا اطلاعات را به صورت دستی ثبت کنید.",
|
||||
severity: "warning",
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const personResponse = await dispatch(
|
||||
provinceGetNationalDocumentsService({
|
||||
info: nationalCode,
|
||||
type: "person",
|
||||
})
|
||||
);
|
||||
|
||||
if (personResponse.payload?.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: personResponse.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else if (
|
||||
personResponse.payload?.data?.status &&
|
||||
personResponse.payload?.data?.data
|
||||
) {
|
||||
personData = personResponse.payload.data.data;
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "اطلاعات فردی یافت نشد.",
|
||||
severity: "warning",
|
||||
});
|
||||
}
|
||||
|
||||
const guildResponse = await dispatch(
|
||||
provinceGetNationalDocumentsService({
|
||||
info: nationalCode,
|
||||
type: "guild",
|
||||
})
|
||||
);
|
||||
|
||||
if (guildResponse.payload?.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: guildResponse.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else if (
|
||||
guildResponse.payload?.data?.status &&
|
||||
guildResponse.payload?.data?.data
|
||||
) {
|
||||
const guildData = guildResponse.payload.data.data;
|
||||
const guildArray = Array.isArray(guildData) ? guildData : [guildData];
|
||||
if (guildArray.length > 0) {
|
||||
const activeGuildIndex = guildArray.findIndex(
|
||||
(g) => g.licenseStatus === "فعال/صادر شده"
|
||||
);
|
||||
selectedGuild =
|
||||
guildArray[activeGuildIndex !== -1 ? activeGuildIndex : 0];
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "اطلاعات صنفی برای این کد ملی یافت نشد.",
|
||||
severity: "warning",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "اطلاعات صنفی برای این کد ملی یافت نشد.",
|
||||
severity: "warning",
|
||||
});
|
||||
}
|
||||
|
||||
if (!personData && !selectedGuild) {
|
||||
setNotFound(true);
|
||||
formik.setFieldValue("nationalId", nationalCode);
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "اطلاعاتی برای این کد ملی یافت نشد، لطفا اطلاعات را به صورت دستی ثبت کنید.",
|
||||
severity: "warning",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const layerTwo = selectedGuild?.layerTwo || {};
|
||||
const aggregatedUserData = {
|
||||
mobile:
|
||||
layerTwo.mobilenumber ||
|
||||
personData?.mobile ||
|
||||
layerTwo.phonenumber ||
|
||||
"",
|
||||
firstName: personData?.firstName || "",
|
||||
lastName: personData?.lastName || "",
|
||||
unitName:
|
||||
selectedGuild?.title ||
|
||||
layerTwo.corporationName ||
|
||||
layerTwo.unionName ||
|
||||
"",
|
||||
province: selectedGuild?.state || "",
|
||||
city: selectedGuild?.city || "",
|
||||
nationalId:
|
||||
personData?.nationalId ||
|
||||
layerTwo.nationalcode ||
|
||||
selectedGuild?.nationalId ||
|
||||
nationalCode,
|
||||
type: formik.values?.type,
|
||||
role_key: formik.values?.role_key,
|
||||
};
|
||||
|
||||
setUserData(aggregatedUserData);
|
||||
handleSetFormDataFromUserDataForAdminAddBuyer(aggregatedUserData, formik);
|
||||
formik2.setFieldValue(
|
||||
"nationalCode",
|
||||
aggregatedUserData.nationalId || nationalCode
|
||||
);
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "اطلاعات با موفقیت دریافت شد.",
|
||||
severity: "success",
|
||||
});
|
||||
} finally {
|
||||
setInquiryInProgress(false);
|
||||
}
|
||||
@@ -486,7 +386,30 @@ export const AdminAddBuyerForm = ({
|
||||
isRealPerson,
|
||||
killHouses,
|
||||
stewards,
|
||||
editData,
|
||||
}) => {
|
||||
const getStewardLabel = (key) => {
|
||||
const item = stewards?.find((s) => s.key === key);
|
||||
if (item)
|
||||
return `${item?.name || ""} - ${item?.user?.fullname || ""} (${
|
||||
item?.user?.mobile || ""
|
||||
})`;
|
||||
const fromEdit = (editData?.stewardInfo || []).find(
|
||||
(s) => s?.Steward?.key === key || s?.key === key
|
||||
);
|
||||
if (fromEdit)
|
||||
return (
|
||||
fromEdit?.Steward?.name || fromEdit?.fullname || fromEdit?.name || null
|
||||
);
|
||||
return null;
|
||||
};
|
||||
const killHouseOptions = (killHouses || []).map((option) => ({
|
||||
key: option.key,
|
||||
killer: option.killer,
|
||||
label: option.killer
|
||||
? `کشتارکن ${(option.name || "").trim()}`
|
||||
: `کشتارگاه ${(option.name || "").trim()}`,
|
||||
}));
|
||||
return (
|
||||
<Grid
|
||||
container
|
||||
@@ -508,89 +431,61 @@ export const AdminAddBuyerForm = ({
|
||||
onBlur={formik.handleBlur}
|
||||
helperText={formik.touched.nationalId && formik.errors.nationalId}
|
||||
/>
|
||||
<LabelField label="انتخاب نوع واحد">
|
||||
<RadioGroup
|
||||
row
|
||||
name="type"
|
||||
value={formik.values.type}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
formik.setFieldValue("type", value);
|
||||
}}
|
||||
>
|
||||
<FormControlLabel value="Steward" control={<Radio />} label="مباشر" />
|
||||
<FormControlLabel
|
||||
value="KillHouse"
|
||||
control={<Radio />}
|
||||
label="کشتارگاه"
|
||||
/>
|
||||
</RadioGroup>
|
||||
</LabelField>
|
||||
{formik.values.type === "Steward" ? (
|
||||
<Autocomplete
|
||||
fullWidth
|
||||
multiple
|
||||
disablePortal
|
||||
id="role_key"
|
||||
options={stewards.map((item) => {
|
||||
return {
|
||||
id="steward_keys"
|
||||
options={stewards.map((item) => ({
|
||||
key: item?.key,
|
||||
label: `${item?.name || ""} - ${item?.user?.fullname || ""} (${
|
||||
item?.user?.mobile || ""
|
||||
})`,
|
||||
};
|
||||
})}
|
||||
onChange={(event, value) => {
|
||||
formik.setFieldValue("role_key", value?.key || "");
|
||||
}}
|
||||
value={
|
||||
formik.values.role_key
|
||||
? {
|
||||
key: formik.values.role_key,
|
||||
label:
|
||||
stewards.find((item) => item.key === formik.values.role_key)
|
||||
?.name || "",
|
||||
}
|
||||
: null
|
||||
}
|
||||
}))}
|
||||
getOptionLabel={(option) => option.label || ""}
|
||||
isOptionEqualToValue={(option, value) => option.key === value.key}
|
||||
label="انتخاب مباشر"
|
||||
onChange={(event, value) => {
|
||||
formik.setFieldValue(
|
||||
"steward_keys",
|
||||
value ? value.map((v) => v.key) : []
|
||||
);
|
||||
}}
|
||||
value={(formik.values.steward_keys || [])
|
||||
.map((key) => {
|
||||
const label = getStewardLabel(key);
|
||||
return label ? { key, label } : null;
|
||||
})
|
||||
.filter(Boolean)}
|
||||
renderInput={(params) => (
|
||||
<TextField fullWidth {...params} label={"انتخاب مباشر"} />
|
||||
<TextField {...params} label="انتخاب مباشر (چندگانه)" />
|
||||
)}
|
||||
/>
|
||||
) : formik.values.type === "KillHouse" ? (
|
||||
<FormControl
|
||||
<Autocomplete
|
||||
fullWidth
|
||||
error={formik.errors.selectedOption && formik.touched.selectedOption}
|
||||
>
|
||||
<InputLabel>انتخاب کشتارگاه یا کشتارکن</InputLabel>
|
||||
<Select
|
||||
label="انتخاب کشتارگاه یا کشتارکن"
|
||||
id="role_key"
|
||||
name="role_key"
|
||||
// value={formik.values.role_key}
|
||||
onChange={(e) => {
|
||||
const [key] = e.target.value.split("#");
|
||||
formik.setFieldValue("role_key", key);
|
||||
multiple
|
||||
disablePortal
|
||||
id="kill_house_keys"
|
||||
options={killHouseOptions}
|
||||
getOptionLabel={(option) => option.label || ""}
|
||||
isOptionEqualToValue={(option, value) => option.key === value.key}
|
||||
onChange={(event, value) => {
|
||||
formik.setFieldValue(
|
||||
"kill_house_keys",
|
||||
value ? value.map((v) => v.key) : []
|
||||
);
|
||||
}}
|
||||
onBlur={formik.handleBlur}
|
||||
>
|
||||
{killHouses?.map((option) => (
|
||||
<MenuItem
|
||||
key={option}
|
||||
value={`${option.key + "#" + option.killer}`}
|
||||
>
|
||||
{option.killer
|
||||
? `کشتارکن ${option.name}`
|
||||
: `کشتارگاه ${option.name}`}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
{formik.errors.role_key && formik.touched.role_key && (
|
||||
<div>{formik.errors.role_key}</div>
|
||||
value={(formik.values.kill_house_keys || [])
|
||||
.map((key) => {
|
||||
const option = killHouseOptions.find((k) => k.key === key);
|
||||
return option
|
||||
? { key, killer: option.killer, label: option.label }
|
||||
: null;
|
||||
})
|
||||
.filter(Boolean)}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} label="انتخاب کشتارگاه یا کشتارکن (چندگانه)" />
|
||||
)}
|
||||
</FormControl>
|
||||
) : null}
|
||||
/>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="mobile"
|
||||
|
||||
@@ -87,7 +87,7 @@ const getInitialValues = (page) => {
|
||||
return { ...INITIAL_VALUES_BASE, nationalId: "" };
|
||||
}
|
||||
if (page === PAGE_ADMIN) {
|
||||
return { ...INITIAL_VALUES_BASE, role_key: "", type: "" };
|
||||
return { ...INITIAL_VALUES_BASE, steward_keys: [], kill_house_keys: [] };
|
||||
}
|
||||
return { ...INITIAL_VALUES_BASE };
|
||||
};
|
||||
@@ -169,19 +169,16 @@ export const StewardAddBuyer = ({
|
||||
});
|
||||
}, [formik.values.province, dispatch]);
|
||||
|
||||
// Admin: load stewards or kill houses by type
|
||||
// Admin: load both stewards and kill houses
|
||||
useEffect(() => {
|
||||
if (page !== PAGE_ADMIN) return;
|
||||
if (formik.values.type === "KillHouse") {
|
||||
dispatch(inspectorGetKillHousesService());
|
||||
} else {
|
||||
dispatch(slaughterGetStewardsForAllocateService({ free: true })).then(
|
||||
(r) => {
|
||||
setStewards(r.payload?.data ?? []);
|
||||
}
|
||||
);
|
||||
}
|
||||
}, [page, formik.values.type, dispatch]);
|
||||
}, [page, dispatch]);
|
||||
|
||||
const handleSubmit = useCallback(() => {
|
||||
if (page === PAGE_STEWARD) {
|
||||
@@ -315,6 +312,7 @@ export const StewardAddBuyer = ({
|
||||
isRealPerson={isRealPerson}
|
||||
killHouses={killHouses}
|
||||
stewards={stewards}
|
||||
editData={isEdit ? data : null}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
31
src/features/steward/services/get-carcasses-buyer-info.js
Normal file
31
src/features/steward/services/get-carcasses-buyer-info.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
/**
|
||||
* GET get_carcasses_buyer_info
|
||||
* @param {Object} payload
|
||||
* @param {string} payload.info - National code or legal ID
|
||||
* @param {string} payload.type - "person" | "unit"
|
||||
*/
|
||||
export const getCarcassesBuyerInfoService = createAsyncThunk(
|
||||
"GET_CARCASSES_BUYER_INFO_SERVICE",
|
||||
async (payload, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.get(
|
||||
`get_carcasses_buyer_info/?info=${encodeURIComponent(
|
||||
payload.info
|
||||
)}&type=${payload.type}`,
|
||||
{ timeout: 30000 }
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return {
|
||||
error: e.response?.data?.result || "خطا در دریافت اطلاعات",
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user