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