702 lines
21 KiB
JavaScript
702 lines
21 KiB
JavaScript
|
|
import { useContext, useEffect, useState } from "react";
|
||
|
|
import { AppContext } from "../../../../contexts/AppContext";
|
||
|
|
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 { 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 {
|
||
|
|
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()
|
||
|
|
.required("این فیلد اجباری است!")
|
||
|
|
.min(11, "شماره موبایل باید 11 رقم باشد")
|
||
|
|
.max(11, "شماره موبایل باید 11 رقم باشد")
|
||
|
|
.matches(/^09\d{9}$/, "شماره موبایل باید با 09 شروع شود و 11 رقم باشد"),
|
||
|
|
firstName: Yup.string()
|
||
|
|
.required("این فیلد اجباری است!")
|
||
|
|
.typeError("لطفا فیلد را به درستی وارد کنید!"),
|
||
|
|
lastName: Yup.string()
|
||
|
|
.required("این فیلد اجباری است!")
|
||
|
|
.typeError("لطفا فیلد را به درستی وارد کنید!"),
|
||
|
|
unit_name: Yup.string()
|
||
|
|
.required("این فیلد اجباری است!")
|
||
|
|
.typeError("لطفا فیلد را به درستی وارد کنید!"),
|
||
|
|
province: Yup.string()
|
||
|
|
.required("این فیلد اجباری است!")
|
||
|
|
.typeError("لطفا فیلد را به درستی وارد کنید!"),
|
||
|
|
city: Yup.string()
|
||
|
|
.required("این فیلد اجباری است!")
|
||
|
|
.typeError("لطفا فیلد را به درستی وارد کنید!"),
|
||
|
|
nationalId:
|
||
|
|
!isRealPerson && isEdit
|
||
|
|
? Yup.string().nullable()
|
||
|
|
: Yup.string()
|
||
|
|
.required("این فیلد اجباری است!")
|
||
|
|
.matches(/^\d{10,11}$/, "شناسه باید 10 یا 11 رقم و فقط عدد باشد"),
|
||
|
|
role_key: Yup.string().required("این فیلد اجباری است!"),
|
||
|
|
type: Yup.string().oneOf(["Steward", "KillHouse"]).required(),
|
||
|
|
});
|
||
|
|
|
||
|
|
export const handleSubmitForAdminAddBuyer = (
|
||
|
|
formik,
|
||
|
|
dispatch,
|
||
|
|
isEdit,
|
||
|
|
tableData,
|
||
|
|
updateTable,
|
||
|
|
openNotif,
|
||
|
|
DRAWER,
|
||
|
|
isRealPerson,
|
||
|
|
buyerType
|
||
|
|
) => {
|
||
|
|
if (isEdit) {
|
||
|
|
const submitData = {
|
||
|
|
buyer_type: buyerType,
|
||
|
|
buyer_key: tableData?.key,
|
||
|
|
mobile: formik.values.mobile,
|
||
|
|
first_name: formik.values.firstName,
|
||
|
|
last_name: formik.values.lastName,
|
||
|
|
city: formik.values.city,
|
||
|
|
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,
|
||
|
|
};
|
||
|
|
|
||
|
|
dispatch(slaughterEditBuyerDataService(submitData)).then((r) => {
|
||
|
|
updateTable();
|
||
|
|
if (r.payload.error) {
|
||
|
|
openNotif({
|
||
|
|
vertical: "top",
|
||
|
|
horizontal: "center",
|
||
|
|
msg: r.payload.error,
|
||
|
|
severity: "error",
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||
|
|
|
||
|
|
openNotif({
|
||
|
|
vertical: "top",
|
||
|
|
horizontal: "center",
|
||
|
|
msg: "عملیات با موفقیت انجام شد.",
|
||
|
|
severity: "success",
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
const submitData = {
|
||
|
|
mobile: formik.values.mobile,
|
||
|
|
buyer_type: buyerType,
|
||
|
|
first_name: formik.values.firstName,
|
||
|
|
last_name: formik.values.lastName,
|
||
|
|
city: formik.values.city,
|
||
|
|
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,
|
||
|
|
...(!isRealPerson && {
|
||
|
|
isRealPerson: false,
|
||
|
|
info_value: formik.values.nationalId,
|
||
|
|
}),
|
||
|
|
};
|
||
|
|
|
||
|
|
// if (IS_STEWARD) {
|
||
|
|
// submitData.name = formik.values.unitName;
|
||
|
|
// delete submitData.unit_name;
|
||
|
|
// }
|
||
|
|
dispatch(slaughterSubmitBuyerDataService(submitData)).then((r) => {
|
||
|
|
updateTable();
|
||
|
|
if (r.payload.error) {
|
||
|
|
openNotif({
|
||
|
|
vertical: "top",
|
||
|
|
horizontal: "center",
|
||
|
|
msg: r.payload.error,
|
||
|
|
severity: "error",
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||
|
|
|
||
|
|
openNotif({
|
||
|
|
vertical: "top",
|
||
|
|
horizontal: "center",
|
||
|
|
msg: "عملیات با موفقیت انجام شد.",
|
||
|
|
severity: "success",
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
export const handleSetFormDataFromTableDataForAdminAddBuyer = (
|
||
|
|
tableData,
|
||
|
|
formik
|
||
|
|
) => {
|
||
|
|
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,
|
||
|
|
};
|
||
|
|
|
||
|
|
formik.setValues(formData);
|
||
|
|
|
||
|
|
setTimeout(() => {
|
||
|
|
formik.validateForm();
|
||
|
|
}, 1);
|
||
|
|
};
|
||
|
|
|
||
|
|
export const handleSetFormDataFromUserDataForAdminAddBuyer = (
|
||
|
|
userData,
|
||
|
|
formik
|
||
|
|
) => {
|
||
|
|
if (userData) {
|
||
|
|
const formData = {
|
||
|
|
mobile: userData.mobile || "",
|
||
|
|
firstName: userData.firstName || "",
|
||
|
|
lastName: userData.lastName || "",
|
||
|
|
province: userData.province || "",
|
||
|
|
city: userData.city || "",
|
||
|
|
nationalId: userData.nationalId || "",
|
||
|
|
unit_name: userData?.unitName || "",
|
||
|
|
type: formik.values?.type,
|
||
|
|
role_key: formik.values?.role_key,
|
||
|
|
};
|
||
|
|
|
||
|
|
formik.setValues(formData);
|
||
|
|
|
||
|
|
setTimeout(() => {
|
||
|
|
formik.validateForm();
|
||
|
|
}, 1);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
export const InquiryForAdminAddBuyer = ({
|
||
|
|
notFound,
|
||
|
|
setNotFound,
|
||
|
|
setUserData,
|
||
|
|
formik,
|
||
|
|
isEdit,
|
||
|
|
isRealPerson,
|
||
|
|
provinceData,
|
||
|
|
}) => {
|
||
|
|
const [inquiryInProgress, setInquiryInProgress] = useState(false);
|
||
|
|
|
||
|
|
const [openNotif] = useContext(AppContext);
|
||
|
|
const dispatch = useDispatch();
|
||
|
|
|
||
|
|
const formik2 = useFormik({
|
||
|
|
initialValues: {
|
||
|
|
personType: isRealPerson ? "real" : "legal", // real | legal
|
||
|
|
nationalCode: "",
|
||
|
|
},
|
||
|
|
validationSchema: Yup.object({
|
||
|
|
nationalCode:
|
||
|
|
isEdit && isRealPerson
|
||
|
|
? Yup.string().nullable()
|
||
|
|
: Yup.string()
|
||
|
|
.required("این فیلد اجباری است!")
|
||
|
|
.when("personType", {
|
||
|
|
is: "real",
|
||
|
|
then: (schema) =>
|
||
|
|
schema
|
||
|
|
.length(10, "کد ملی باید 10 رقم باشد")
|
||
|
|
.matches(/^\d{10}$/, "کد ملی باید فقط شامل اعداد باشد"),
|
||
|
|
otherwise: (schema) =>
|
||
|
|
schema
|
||
|
|
.length(11, "شناسه ملی حقوقی باید 11 رقم باشد")
|
||
|
|
.matches(
|
||
|
|
/^\d{11}$/,
|
||
|
|
"شناسه ملی حقوقی باید فقط شامل اعداد باشد"
|
||
|
|
),
|
||
|
|
}),
|
||
|
|
}),
|
||
|
|
validateOnMount: isEdit ? false : true,
|
||
|
|
});
|
||
|
|
|
||
|
|
const handleInquiry = async () => {
|
||
|
|
if (!formik2.isValid || inquiryInProgress) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const nationalCode = formik2.values.nationalCode;
|
||
|
|
const personType = formik2.values.personType;
|
||
|
|
|
||
|
|
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();
|
||
|
|
|
||
|
|
if (json?.status && json?.data) {
|
||
|
|
const d = json.data;
|
||
|
|
const extractedProvince = extractProvinceFromAddress(
|
||
|
|
d.address || "",
|
||
|
|
provinceData
|
||
|
|
);
|
||
|
|
const aggregatedUserData = {
|
||
|
|
mobile: d.mobile,
|
||
|
|
firstName: d.name || "",
|
||
|
|
lastName: d.name || "",
|
||
|
|
unitName: d.unitName || "",
|
||
|
|
province: d.state || extractedProvince || "",
|
||
|
|
city: d.city || "",
|
||
|
|
nationalId: d.nationalCode || nationalCode,
|
||
|
|
type: formik.values?.type,
|
||
|
|
role_key: formik.values?.role_key,
|
||
|
|
};
|
||
|
|
handleSetFormDataFromUserDataForAdminAddBuyer(
|
||
|
|
aggregatedUserData,
|
||
|
|
formik
|
||
|
|
);
|
||
|
|
formik2.setFieldValue(
|
||
|
|
"nationalCode",
|
||
|
|
aggregatedUserData.nationalId || nationalCode
|
||
|
|
);
|
||
|
|
openNotif({
|
||
|
|
vertical: "top",
|
||
|
|
horizontal: "center",
|
||
|
|
msg: "اطلاعات حقوقی با موفقیت دریافت شد.",
|
||
|
|
severity: "success",
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
setNotFound(true);
|
||
|
|
formik.setFieldValue("nationalId", nationalCode);
|
||
|
|
openNotif({
|
||
|
|
vertical: "top",
|
||
|
|
horizontal: "center",
|
||
|
|
msg: "اطلاعات حقوقی برای این شناسه یافت نشد، لطفا اطلاعات را به صورت دستی ثبت کنید.",
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
if (notFound) {
|
||
|
|
formik.setFieldValue("mobile", formik2.values.mobile);
|
||
|
|
}
|
||
|
|
}, [notFound]);
|
||
|
|
|
||
|
|
return (
|
||
|
|
<Grid container xs={12}>
|
||
|
|
<Typography mt={2}>
|
||
|
|
{"استعلام "}
|
||
|
|
{!isRealPerson ? "شناسه ملی حقوقی" : "کد ملی"}
|
||
|
|
</Typography>
|
||
|
|
<Grid mt={SPACING.SMALL} display="flex" width={1}>
|
||
|
|
<TextField
|
||
|
|
fullWidth
|
||
|
|
id="nationalCode"
|
||
|
|
name="nationalCode"
|
||
|
|
label={!isRealPerson ? "شناسه ملی حقوقی" : "کد ملی"}
|
||
|
|
variant="outlined"
|
||
|
|
value={formik2.values.nationalCode}
|
||
|
|
error={Boolean(
|
||
|
|
formik2.touched.nationalCode && formik2.errors.nationalCode
|
||
|
|
)}
|
||
|
|
onChange={formik2.handleChange}
|
||
|
|
onBlur={formik2.handleBlur}
|
||
|
|
helperText={
|
||
|
|
formik2.touched.nationalCode && formik2.errors.nationalCode
|
||
|
|
}
|
||
|
|
inputProps={{
|
||
|
|
maxLength: !isRealPerson ? 11 : 10,
|
||
|
|
}}
|
||
|
|
/>
|
||
|
|
<IconButton
|
||
|
|
disabled={!formik2.isValid || inquiryInProgress}
|
||
|
|
aria-label="search"
|
||
|
|
color="primary"
|
||
|
|
onClick={handleInquiry}
|
||
|
|
>
|
||
|
|
<SearchIcon />
|
||
|
|
</IconButton>
|
||
|
|
</Grid>
|
||
|
|
</Grid>
|
||
|
|
);
|
||
|
|
};
|
||
|
|
|
||
|
|
export const AdminAddBuyerForm = ({
|
||
|
|
formik,
|
||
|
|
provinceData,
|
||
|
|
cityData,
|
||
|
|
notFound,
|
||
|
|
isRealPerson,
|
||
|
|
killHouses,
|
||
|
|
stewards,
|
||
|
|
}) => {
|
||
|
|
return (
|
||
|
|
<Grid
|
||
|
|
container
|
||
|
|
justifyContent="space-between"
|
||
|
|
alignItems="start"
|
||
|
|
xs={12}
|
||
|
|
direction="column"
|
||
|
|
gap={2}
|
||
|
|
>
|
||
|
|
<TextField
|
||
|
|
fullWidth
|
||
|
|
id="nationalId"
|
||
|
|
name="nationalId"
|
||
|
|
label={!isRealPerson ? "شناسه ملی حقوقی" : "کد ملی"}
|
||
|
|
disabled={true}
|
||
|
|
variant="outlined"
|
||
|
|
value={formik.values.nationalId}
|
||
|
|
onChange={formik.handleChange}
|
||
|
|
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
|
||
|
|
disablePortal
|
||
|
|
id="role_key"
|
||
|
|
options={stewards.map((item) => {
|
||
|
|
return {
|
||
|
|
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
|
||
|
|
}
|
||
|
|
isOptionEqualToValue={(option, value) => option.key === value.key}
|
||
|
|
label="انتخاب مباشر"
|
||
|
|
renderInput={(params) => (
|
||
|
|
<TextField fullWidth {...params} label={"انتخاب مباشر"} />
|
||
|
|
)}
|
||
|
|
/>
|
||
|
|
) : formik.values.type === "KillHouse" ? (
|
||
|
|
<FormControl
|
||
|
|
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);
|
||
|
|
}}
|
||
|
|
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>
|
||
|
|
)}
|
||
|
|
</FormControl>
|
||
|
|
) : null}
|
||
|
|
<TextField
|
||
|
|
fullWidth
|
||
|
|
id="mobile"
|
||
|
|
label="شماره موبایل"
|
||
|
|
variant="outlined"
|
||
|
|
value={formik.values.mobile}
|
||
|
|
onChange={formik.handleChange}
|
||
|
|
onBlur={formik.handleBlur}
|
||
|
|
error={Boolean(formik.errors.mobile)}
|
||
|
|
helperText={formik.errors.mobile}
|
||
|
|
/>
|
||
|
|
<TextField
|
||
|
|
fullWidth
|
||
|
|
id="firstName"
|
||
|
|
label="نام"
|
||
|
|
variant="outlined"
|
||
|
|
value={formik.values.firstName}
|
||
|
|
onChange={formik.handleChange}
|
||
|
|
onBlur={formik.handleBlur}
|
||
|
|
helperText={formik.touched.firstName && formik.errors.firstName}
|
||
|
|
error={Boolean(formik.errors.firstName)}
|
||
|
|
/>
|
||
|
|
<TextField
|
||
|
|
fullWidth
|
||
|
|
id="lastName"
|
||
|
|
label="نام خانوادگی"
|
||
|
|
variant="outlined"
|
||
|
|
value={formik.values.lastName}
|
||
|
|
onChange={formik.handleChange}
|
||
|
|
onBlur={formik.handleBlur}
|
||
|
|
helperText={formik.touched.lastName && formik.errors.lastName}
|
||
|
|
error={Boolean(formik.errors.lastName)}
|
||
|
|
/>
|
||
|
|
<TextField
|
||
|
|
fullWidth
|
||
|
|
id="unit_name"
|
||
|
|
label="نام واحد"
|
||
|
|
variant="outlined"
|
||
|
|
value={formik.values.unit_name}
|
||
|
|
onChange={formik.handleChange}
|
||
|
|
onBlur={formik.handleBlur}
|
||
|
|
helperText={formik.touched.unit_name && formik.errors.unit_name}
|
||
|
|
error={Boolean(formik.errors.unit_name)}
|
||
|
|
/>
|
||
|
|
|
||
|
|
<Autocomplete
|
||
|
|
style={{ width: "100%" }}
|
||
|
|
disablePortal
|
||
|
|
id="province"
|
||
|
|
options={
|
||
|
|
provinceData
|
||
|
|
? provinceData.map((i) => ({ id: i.name, label: i.name }))
|
||
|
|
: []
|
||
|
|
}
|
||
|
|
isOptionEqualToValue={(option, value) => option.id === value.id}
|
||
|
|
onChange={(e, value) => {
|
||
|
|
formik.setFieldValue("province", value ? value.id : "");
|
||
|
|
formik.setFieldValue("city", "");
|
||
|
|
}}
|
||
|
|
value={
|
||
|
|
formik.values.province
|
||
|
|
? {
|
||
|
|
id: formik.values.province,
|
||
|
|
label: formik.values.province,
|
||
|
|
}
|
||
|
|
: null
|
||
|
|
}
|
||
|
|
renderInput={(params) => (
|
||
|
|
<TextField {...params} label="استان را انتخاب کنید" />
|
||
|
|
)}
|
||
|
|
/>
|
||
|
|
{!notFound && (
|
||
|
|
<Typography variant="caption" color="error">
|
||
|
|
استان: {formik.values.province}
|
||
|
|
</Typography>
|
||
|
|
)}
|
||
|
|
{cityData && formik.values.province && (
|
||
|
|
<>
|
||
|
|
<Autocomplete
|
||
|
|
minWidth={210}
|
||
|
|
style={{ width: "100%" }}
|
||
|
|
disablePortal
|
||
|
|
id="city"
|
||
|
|
options={
|
||
|
|
cityData
|
||
|
|
? cityData.map((i) => ({ id: i.name, label: i.name }))
|
||
|
|
: []
|
||
|
|
}
|
||
|
|
isOptionEqualToValue={(option, value) => option.id === value.id}
|
||
|
|
onChange={(e, value) => {
|
||
|
|
formik.setFieldValue("city", value ? value.id : "");
|
||
|
|
}}
|
||
|
|
value={cityData.find((i) => i.name === formik.values.city)?.name}
|
||
|
|
renderInput={(params) => (
|
||
|
|
<TextField {...params} label="شهر را انتخاب کنید" />
|
||
|
|
)}
|
||
|
|
/>
|
||
|
|
|
||
|
|
{!notFound && (
|
||
|
|
<Typography variant="caption" color="error">
|
||
|
|
شهر: {formik.values.city}
|
||
|
|
</Typography>
|
||
|
|
)}
|
||
|
|
</>
|
||
|
|
)}
|
||
|
|
</Grid>
|
||
|
|
);
|
||
|
|
};
|