mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-208,212,213): integrate dynamic supplier selection in PurchaseOrderAcceptApprovalForm
This commit is contained in:
@@ -8,7 +8,10 @@ import { useSearchParams } from 'next/navigation';
|
|||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import TextInput from '@/components/input/TextInput';
|
import TextInput from '@/components/input/TextInput';
|
||||||
import NumberInput from '@/components/input/NumberInput';
|
import NumberInput from '@/components/input/NumberInput';
|
||||||
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
import SelectInput, {
|
||||||
|
OptionType,
|
||||||
|
useSelect,
|
||||||
|
} from '@/components/input/SelectInput';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -24,6 +27,8 @@ import {
|
|||||||
} from '@/types/api/purchase/purchase';
|
} from '@/types/api/purchase/purchase';
|
||||||
import DateInput from '@/components/input/DateInput';
|
import DateInput from '@/components/input/DateInput';
|
||||||
import { formatNumber } from '@/lib/helper';
|
import { formatNumber } from '@/lib/helper';
|
||||||
|
import { Supplier } from '@/types/api/master-data/supplier';
|
||||||
|
import { SupplierApi } from '@/services/api/master-data';
|
||||||
|
|
||||||
interface PurchaseOrderAcceptApprovalFormProps {
|
interface PurchaseOrderAcceptApprovalFormProps {
|
||||||
type?: 'add' | 'edit';
|
type?: 'add' | 'edit';
|
||||||
@@ -47,13 +52,6 @@ const PurchaseOrderAcceptApprovalForm = ({
|
|||||||
const [purchaseOrderFormErrorMessage, setPurchaseOrderFormErrorMessage] =
|
const [purchaseOrderFormErrorMessage, setPurchaseOrderFormErrorMessage] =
|
||||||
useState('');
|
useState('');
|
||||||
|
|
||||||
// ===== TYPE DEFINITIONS =====
|
|
||||||
interface ExpeditionVendorOptionType {
|
|
||||||
value: number;
|
|
||||||
label: string;
|
|
||||||
id: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===== UTILITY FUNCTIONS =====
|
// ===== UTILITY FUNCTIONS =====
|
||||||
const isRepeaterInputError = (
|
const isRepeaterInputError = (
|
||||||
idx: number,
|
idx: number,
|
||||||
@@ -115,7 +113,13 @@ const PurchaseOrderAcceptApprovalForm = ({
|
|||||||
onModalClose?.();
|
onModalClose?.();
|
||||||
router.refresh();
|
router.refresh();
|
||||||
},
|
},
|
||||||
[initialValues?.id, searchParams, refreshApprovals, onModalClose, onRefetchData]
|
[
|
||||||
|
initialValues?.id,
|
||||||
|
searchParams,
|
||||||
|
refreshApprovals,
|
||||||
|
onModalClose,
|
||||||
|
onRefetchData,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
const updateAcceptApprovalHandler = useCallback(
|
const updateAcceptApprovalHandler = useCallback(
|
||||||
@@ -136,6 +140,15 @@ const PurchaseOrderAcceptApprovalForm = ({
|
|||||||
[refreshApprovals, onModalClose, onRefetchData]
|
[refreshApprovals, onModalClose, onRefetchData]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ===== SELECT INPUT DATA =====
|
||||||
|
const {
|
||||||
|
setInputValue: setExpeditionsSelectInputValue,
|
||||||
|
options: expeditionVendors,
|
||||||
|
isLoadingOptions: isLoadingExpeditions,
|
||||||
|
} = useSelect<Supplier>(SupplierApi.basePath, 'id', 'name', 'search', {
|
||||||
|
category: 'BOP',
|
||||||
|
});
|
||||||
|
|
||||||
// ===== FORM CONFIGURATION =====
|
// ===== FORM CONFIGURATION =====
|
||||||
const formikInitialValues = useMemo(() => {
|
const formikInitialValues = useMemo(() => {
|
||||||
return initialValues
|
return initialValues
|
||||||
@@ -250,36 +263,6 @@ const PurchaseOrderAcceptApprovalForm = ({
|
|||||||
[purchaseItems]
|
[purchaseItems]
|
||||||
);
|
);
|
||||||
|
|
||||||
const expeditionVendors: ExpeditionVendorOptionType[] = useMemo(() => {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
value: 1,
|
|
||||||
label: 'PT. Ekspedisi Sejahtera',
|
|
||||||
id: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 2,
|
|
||||||
label: 'PT. Jaya Trans Logistics',
|
|
||||||
id: 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 3,
|
|
||||||
label: 'PT. Cargo Express Indonesia',
|
|
||||||
id: 3,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 4,
|
|
||||||
label: 'PT. Fast Delivery Service',
|
|
||||||
id: 4,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 5,
|
|
||||||
label: 'PT. Mitra Angkutan Sejahtera',
|
|
||||||
id: 5,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const getExpeditionVendorOptions = useCallback(() => {
|
const getExpeditionVendorOptions = useCallback(() => {
|
||||||
return expeditionVendors;
|
return expeditionVendors;
|
||||||
}, [expeditionVendors]);
|
}, [expeditionVendors]);
|
||||||
@@ -289,7 +272,7 @@ const PurchaseOrderAcceptApprovalForm = ({
|
|||||||
idx: number,
|
idx: number,
|
||||||
val: OptionType | OptionType[] | null
|
val: OptionType | OptionType[] | null
|
||||||
) => {
|
) => {
|
||||||
const expeditionVendor = val as ExpeditionVendorOptionType | null;
|
const expeditionVendor = val as OptionType | null;
|
||||||
formik.setFieldTouched(`items.${idx}.expedition_vendor`, true);
|
formik.setFieldTouched(`items.${idx}.expedition_vendor`, true);
|
||||||
formik.setFieldValue(`items.${idx}.expedition_vendor`, expeditionVendor);
|
formik.setFieldValue(`items.${idx}.expedition_vendor`, expeditionVendor);
|
||||||
formik.setFieldTouched(`items.${idx}.expedition_vendor_id`, true);
|
formik.setFieldTouched(`items.${idx}.expedition_vendor_id`, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user