From 88392f378d5cd82409d5dbf0be558f14f6600a17 Mon Sep 17 00:00:00 2001 From: Reza Ashrafi Date: Mon, 2 Feb 2026 09:35:01 +0330 Subject: [PATCH] fix: disable form field for select killer if user is public killer --- .../SlaughterEnterBarItem.js | 104 ++++++++++-------- 1 file changed, 60 insertions(+), 44 deletions(-) diff --git a/src/features/file/components/slaughter-enter-bar-item/SlaughterEnterBarItem.js b/src/features/file/components/slaughter-enter-bar-item/SlaughterEnterBarItem.js index 2ede861..238d3cd 100644 --- a/src/features/file/components/slaughter-enter-bar-item/SlaughterEnterBarItem.js +++ b/src/features/file/components/slaughter-enter-bar-item/SlaughterEnterBarItem.js @@ -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,35 +356,42 @@ export const SlaughterEnterBarItem = ({ {barWeight} کیلوگرم - {exclusiveKillers?.length > 1 && ( - - - - انتخاب کشتارکن - - - - - - ویرایش کشتارکن اختصاصی (اختیاری) - + {shouldShowExclusiveKillerSelect && + exclusiveKillers?.length > 1 && ( + + + + انتخاب کشتارکن + + + + + + + ویرایش کشتارکن اختصاصی (اختیاری) + + - - )} + )}