Merge branch 'fix/transfer-to-laying' into 'development'

[FIX/FE] Transfer to Laying

See merge request mbugroup/lti-web-client!246
This commit is contained in:
Rivaldi A N S
2026-01-24 05:47:12 +00:00
2 changed files with 520 additions and 487 deletions
@@ -405,7 +405,9 @@ const FinanceTable = () => {
{ {
header: 'Bank', header: 'Bank',
accessorFn: (finance: Finance) => accessorFn: (finance: Finance) =>
`${finance.bank?.alias} - ${finance.bank?.account_number} - ${finance.bank?.owner}`, finance.bank
? `${finance.bank?.alias} - ${finance.bank?.account_number} - ${finance.bank?.owner}`
: '-',
}, },
{ {
header: 'Pengeluaran (Rp)', header: 'Pengeluaran (Rp)',
@@ -205,11 +205,9 @@ const TransferToLayingFormModal = () => {
const { formErrorList, close, handleFormSubmit } = useFormikErrorList(formik); const { formErrorList, close, handleFormSubmit } = useFormikErrorList(formik);
const selectedFlockSourceRawData = isResponseSuccess(flockSourceRawData) const [selectedFlockSourceRawData, setSelectedFlockSourceRawData] = useState<
? flockSourceRawData.data.find( ProjectFlock | undefined
(item) => item.id === formik.values.flockSource?.value >(undefined);
)
: undefined;
const selectedFlockDestinationRawData = isResponseSuccess( const selectedFlockDestinationRawData = isResponseSuccess(
flockDestinationRawData 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(); getFilledInitialValues();
getFlockSourceData();
}, [transferToLayingId, transferToLaying]); }, [transferToLayingId, transferToLaying]);
useEffect(() => {
if (isResponseSuccess(flockSourceRawData)) {
const selectedFlockSourceRawData = flockSourceRawData.data.find(
(item) => item.id === formik.values.flockSource?.value
);
setSelectedFlockSourceRawData(selectedFlockSourceRawData);
}
}, [flockSourceRawData]);
useEffect(() => { useEffect(() => {
formik.setFieldValue('totalQuantity', totalTransferedChicken); formik.setFieldValue('totalQuantity', totalTransferedChicken);
formik.setFieldValue('maxTotalQuantity', totalTransferedChicken); formik.setFieldValue('maxTotalQuantity', totalTransferedChicken);
}, [totalTransferedChicken]); }, [totalTransferedChicken]);
return ( return (
<>
<Modal <Modal
ref={formModal.ref} ref={formModal.ref}
position='end' position='end'
@@ -487,14 +509,17 @@ const TransferToLayingFormModal = () => {
{mappedFlockSourceKandangsAvailability.map( {mappedFlockSourceKandangsAvailability.map(
(item, itemIdx) => { (item, itemIdx) => {
const isAvailable = item.available_qty > 0; const isAvailable = item.available_qty > 0;
const isChecked = formik.values.flockSourceKandangs.some( const isChecked =
(k) => k.kandang.value === item.project_flock_kandang_id formik.values.flockSourceKandangs.some(
(k) =>
k.kandang.value === item.project_flock_kandang_id
); );
const flockSourceKandangCheckboxChangeHandler: FormEventHandler< const flockSourceKandangCheckboxChangeHandler: FormEventHandler<
HTMLInputElement HTMLInputElement
> = (e) => { > = (e) => {
const checked = (e.target as HTMLInputElement).checked; const checked = (e.target as HTMLInputElement)
.checked;
if (checked) { if (checked) {
formik.setFieldValue('flockSourceKandangs', [ formik.setFieldValue('flockSourceKandangs', [
...formik.values.flockSourceKandangs, ...formik.values.flockSourceKandangs,
@@ -529,7 +554,9 @@ const TransferToLayingFormModal = () => {
name={`flockSourceKandang.${itemIdx}.value`} name={`flockSourceKandang.${itemIdx}.value`}
value={item.project_flock_kandang_id} value={item.project_flock_kandang_id}
checked={isChecked} checked={isChecked}
onChange={flockSourceKandangCheckboxChangeHandler} onChange={
flockSourceKandangCheckboxChangeHandler
}
size='md' size='md'
disabled={!isAvailable} disabled={!isAvailable}
classNames={{ classNames={{
@@ -609,7 +636,8 @@ const TransferToLayingFormModal = () => {
const flockDestinationKandangCheckboxChangeHandler: FormEventHandler< const flockDestinationKandangCheckboxChangeHandler: FormEventHandler<
HTMLInputElement HTMLInputElement
> = (e) => { > = (e) => {
const checked = (e.target as HTMLInputElement).checked; const checked = (e.target as HTMLInputElement)
.checked;
if (checked) { if (checked) {
formik.setFieldValue('flockDestinationKandangs', [ formik.setFieldValue('flockDestinationKandangs', [
...formik.values.flockDestinationKandangs, ...formik.values.flockDestinationKandangs,
@@ -796,7 +824,9 @@ const TransferToLayingFormModal = () => {
<StatusBadge <StatusBadge
color={ color={
totalAvailableChickenForTransfer < 0 ? 'error' : 'neutral' totalAvailableChickenForTransfer < 0
? 'error'
: 'neutral'
} }
text={`Sisa ayam: ${formatNumber( text={`Sisa ayam: ${formatNumber(
totalAvailableChickenForTransfer totalAvailableChickenForTransfer
@@ -934,6 +964,7 @@ const TransferToLayingFormModal = () => {
)} )}
</form> </form>
</Modal> </Modal>
</>
); );
}; };