fix: disable form field for select killer if user is public killer
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
InputLabel,
|
||||
MenuItem,
|
||||
Select,
|
||||
Typography,
|
||||
Typography
|
||||
} from "@mui/material";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useFormik } from "formik";
|
||||
@@ -35,7 +35,7 @@ export const SlaughterEnterBarItem = ({
|
||||
isRejected,
|
||||
item,
|
||||
realNumber,
|
||||
updateTable,
|
||||
updateTable
|
||||
}) => {
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
@@ -75,7 +75,7 @@ export const SlaughterEnterBarItem = ({
|
||||
loadRealNumber: item.acceptedRealQuantity
|
||||
? item.acceptedRealQuantity
|
||||
: realNumber,
|
||||
exploitedCarcass: 0,
|
||||
exploitedCarcass: 0
|
||||
},
|
||||
validationSchema: Yup.object({
|
||||
weightWithoutBar: Yup.number()
|
||||
@@ -109,8 +109,8 @@ export const SlaughterEnterBarItem = ({
|
||||
.typeError("لطفا عدد وارد کنید!"),
|
||||
exploitedCarcass: Yup.number()
|
||||
.required("این فیلد اجباری است!")
|
||||
.typeError("لطفا عدد وارد کنید!"),
|
||||
}),
|
||||
.typeError("لطفا عدد وارد کنید!")
|
||||
})
|
||||
});
|
||||
|
||||
numFirstWeight = Number(formik.values.weightWithoutBar);
|
||||
@@ -148,17 +148,22 @@ export const SlaughterEnterBarItem = ({
|
||||
const [exclusiveKillers, setExclusiveKillers] = useState();
|
||||
const [selectedOption, setSelectedOption] = useState();
|
||||
|
||||
const shouldShowExclusiveKillerSelect = !(
|
||||
item?.killer && item?.type === "public"
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!shouldShowExclusiveKillerSelect) return;
|
||||
dispatch(
|
||||
slaughterGetExlusiveKillers({
|
||||
role_key: checkPathStartsWith("slaughter")
|
||||
? selectedSubUser?.key || ""
|
||||
: "",
|
||||
: ""
|
||||
})
|
||||
).then((r) => {
|
||||
setExclusiveKillers(r.payload.data);
|
||||
});
|
||||
}, [selectedSubUser?.key]);
|
||||
}, [selectedSubUser?.key, shouldShowExclusiveKillerSelect]);
|
||||
|
||||
const handleOptionChange = (event) => {
|
||||
setSelectedOption(event?.target.value);
|
||||
@@ -182,7 +187,7 @@ export const SlaughterEnterBarItem = ({
|
||||
"میانگین وزن تحویلی هر قطعه (کیلوگرم)",
|
||||
"سن",
|
||||
"تاریخ کشتار",
|
||||
"کشتارکن اختصاصی",
|
||||
"کشتارکن اختصاصی"
|
||||
]}
|
||||
data={data}
|
||||
/>
|
||||
@@ -351,12 +356,19 @@ export const SlaughterEnterBarItem = ({
|
||||
</Typography>
|
||||
<Typography variant={"button"}>{barWeight} کیلوگرم </Typography>
|
||||
</Grid>
|
||||
{exclusiveKillers?.length > 1 && (
|
||||
<Grid container direction={"column"} gap={1} alignItems="center">
|
||||
{shouldShowExclusiveKillerSelect &&
|
||||
exclusiveKillers?.length > 1 && (
|
||||
<Grid
|
||||
container
|
||||
direction={"column"}
|
||||
gap={1}
|
||||
alignItems="center"
|
||||
>
|
||||
<FormControl>
|
||||
<InputLabel id="demo-simple-select-label">
|
||||
انتخاب کشتارکن
|
||||
</InputLabel>
|
||||
|
||||
<Select
|
||||
label="کشتارکن"
|
||||
// disabled={disableSelect}
|
||||
@@ -391,7 +403,7 @@ export const SlaughterEnterBarItem = ({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
severity: "error"
|
||||
});
|
||||
} else {
|
||||
// reset form values
|
||||
@@ -403,7 +415,7 @@ export const SlaughterEnterBarItem = ({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
severity: "success"
|
||||
});
|
||||
|
||||
dispatch(
|
||||
@@ -412,7 +424,7 @@ export const SlaughterEnterBarItem = ({
|
||||
top: false,
|
||||
bottom: false,
|
||||
content: null,
|
||||
size: null,
|
||||
size: null
|
||||
})
|
||||
);
|
||||
|
||||
@@ -437,7 +449,7 @@ export const SlaughterEnterBarItem = ({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "حجم وارد شده با مجوز حداکثر افزایش/کاهش ورود اطلاعات بار مطابقت ندارد!",
|
||||
severity: "error",
|
||||
severity: "error"
|
||||
});
|
||||
} else if (
|
||||
getRoleFromUrl() !== "SuperAdmin" &&
|
||||
@@ -453,7 +465,7 @@ export const SlaughterEnterBarItem = ({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "میانگین وزنی با احراز سنی مطابقت ندارد. لطفا با اتحادیه تماس بگیرید.",
|
||||
severity: "error",
|
||||
severity: "error"
|
||||
});
|
||||
} else if (
|
||||
isRejected ||
|
||||
@@ -467,7 +479,9 @@ export const SlaughterEnterBarItem = ({
|
||||
real_quantity: formik.values.loadRealNumber,
|
||||
exploited_carcass: formik.values.exploitedCarcass,
|
||||
role: getRoleFromUrl(),
|
||||
killer_key: selectedOption ? selectedOption : null,
|
||||
...(shouldShowExclusiveKillerSelect && {
|
||||
killer_key: selectedOption ? selectedOption : null
|
||||
})
|
||||
};
|
||||
dispatch(slaughterUpdateBarWeight(reqUpdate)).then(
|
||||
thenCallback
|
||||
@@ -482,7 +496,9 @@ export const SlaughterEnterBarItem = ({
|
||||
kill_house_request_key: reqKey,
|
||||
// kill_house_check_key: checkKey,
|
||||
role: getRoleFromUrl(),
|
||||
killer_key: selectedOption ? selectedOption : null,
|
||||
...(shouldShowExclusiveKillerSelect && {
|
||||
killer_key: selectedOption ? selectedOption : null
|
||||
})
|
||||
};
|
||||
|
||||
if (!req.kill_house_check_key) {
|
||||
@@ -509,5 +525,5 @@ SlaughterEnterBarItem.propTypes = {
|
||||
checkKey: PropTypes.string,
|
||||
isRejected: PropTypes.bool,
|
||||
item: PropTypes.any,
|
||||
realNumber: PropTypes.any,
|
||||
realNumber: PropTypes.any
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user