mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-26 00:05:45 +00:00
fix: get flock source data if ID exist in query
This commit is contained in:
@@ -205,11 +205,9 @@ const TransferToLayingFormModal = () => {
|
||||
|
||||
const { formErrorList, close, handleFormSubmit } = useFormikErrorList(formik);
|
||||
|
||||
const selectedFlockSourceRawData = isResponseSuccess(flockSourceRawData)
|
||||
? flockSourceRawData.data.find(
|
||||
(item) => item.id === formik.values.flockSource?.value
|
||||
)
|
||||
: undefined;
|
||||
const [selectedFlockSourceRawData, setSelectedFlockSourceRawData] = useState<
|
||||
ProjectFlock | undefined
|
||||
>(undefined);
|
||||
|
||||
const selectedFlockDestinationRawData = isResponseSuccess(
|
||||
flockDestinationRawData
|
||||
@@ -375,15 +373,39 @@ const TransferToLayingFormModal = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const getFlockSourceData = async () => {
|
||||
if (transferToLayingId && isResponseSuccess(transferToLaying)) {
|
||||
const singleFlockSourceRawData = await ProjectFlockApi.getSingle(
|
||||
transferToLaying.data.from_project_flock.id
|
||||
);
|
||||
|
||||
if (isResponseSuccess(singleFlockSourceRawData)) {
|
||||
setSelectedFlockSourceRawData(singleFlockSourceRawData.data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
getFilledInitialValues();
|
||||
getFlockSourceData();
|
||||
}, [transferToLayingId, transferToLaying]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isResponseSuccess(flockSourceRawData)) {
|
||||
const selectedFlockSourceRawData = flockSourceRawData.data.find(
|
||||
(item) => item.id === formik.values.flockSource?.value
|
||||
);
|
||||
|
||||
setSelectedFlockSourceRawData(selectedFlockSourceRawData);
|
||||
}
|
||||
}, [flockSourceRawData]);
|
||||
|
||||
useEffect(() => {
|
||||
formik.setFieldValue('totalQuantity', totalTransferedChicken);
|
||||
formik.setFieldValue('maxTotalQuantity', totalTransferedChicken);
|
||||
}, [totalTransferedChicken]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal
|
||||
ref={formModal.ref}
|
||||
position='end'
|
||||
@@ -487,14 +509,17 @@ const TransferToLayingFormModal = () => {
|
||||
{mappedFlockSourceKandangsAvailability.map(
|
||||
(item, itemIdx) => {
|
||||
const isAvailable = item.available_qty > 0;
|
||||
const isChecked = formik.values.flockSourceKandangs.some(
|
||||
(k) => k.kandang.value === item.project_flock_kandang_id
|
||||
const isChecked =
|
||||
formik.values.flockSourceKandangs.some(
|
||||
(k) =>
|
||||
k.kandang.value === item.project_flock_kandang_id
|
||||
);
|
||||
|
||||
const flockSourceKandangCheckboxChangeHandler: FormEventHandler<
|
||||
HTMLInputElement
|
||||
> = (e) => {
|
||||
const checked = (e.target as HTMLInputElement).checked;
|
||||
const checked = (e.target as HTMLInputElement)
|
||||
.checked;
|
||||
if (checked) {
|
||||
formik.setFieldValue('flockSourceKandangs', [
|
||||
...formik.values.flockSourceKandangs,
|
||||
@@ -529,7 +554,9 @@ const TransferToLayingFormModal = () => {
|
||||
name={`flockSourceKandang.${itemIdx}.value`}
|
||||
value={item.project_flock_kandang_id}
|
||||
checked={isChecked}
|
||||
onChange={flockSourceKandangCheckboxChangeHandler}
|
||||
onChange={
|
||||
flockSourceKandangCheckboxChangeHandler
|
||||
}
|
||||
size='md'
|
||||
disabled={!isAvailable}
|
||||
classNames={{
|
||||
@@ -609,7 +636,8 @@ const TransferToLayingFormModal = () => {
|
||||
const flockDestinationKandangCheckboxChangeHandler: FormEventHandler<
|
||||
HTMLInputElement
|
||||
> = (e) => {
|
||||
const checked = (e.target as HTMLInputElement).checked;
|
||||
const checked = (e.target as HTMLInputElement)
|
||||
.checked;
|
||||
if (checked) {
|
||||
formik.setFieldValue('flockDestinationKandangs', [
|
||||
...formik.values.flockDestinationKandangs,
|
||||
@@ -796,7 +824,9 @@ const TransferToLayingFormModal = () => {
|
||||
|
||||
<StatusBadge
|
||||
color={
|
||||
totalAvailableChickenForTransfer < 0 ? 'error' : 'neutral'
|
||||
totalAvailableChickenForTransfer < 0
|
||||
? 'error'
|
||||
: 'neutral'
|
||||
}
|
||||
text={`Sisa ayam: ${formatNumber(
|
||||
totalAvailableChickenForTransfer
|
||||
@@ -934,6 +964,7 @@ const TransferToLayingFormModal = () => {
|
||||
)}
|
||||
</form>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user