mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
Merge branch 'development' of gitlab.com:mbugroup/lti-web-client into hotfix/adjustment-recording-fifo-stock
This commit is contained in:
@@ -24,8 +24,8 @@ import {
|
||||
} from '@/types/api/api-general';
|
||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||
|
||||
export interface OptionType {
|
||||
value: string | number;
|
||||
export interface OptionType<T = string | number> {
|
||||
value: T;
|
||||
label: string;
|
||||
className?: string;
|
||||
labelClassName?: string;
|
||||
|
||||
@@ -80,13 +80,13 @@ const InventoryAdjustmentTable = () => {
|
||||
const formik = useFormik<AdjustmentFilterType>({
|
||||
initialValues: {
|
||||
product_id: null,
|
||||
warehouse_id: null,
|
||||
warehouse: null,
|
||||
transaction_type: null,
|
||||
},
|
||||
validationSchema: AdjustmentFilterSchema,
|
||||
onSubmit: (values, { setSubmitting }) => {
|
||||
updateFilter('productFilter', values.product_id || '');
|
||||
updateFilter('warehouseFilter', values.warehouse_id || '');
|
||||
updateFilter('warehouseFilter', String(values.warehouse?.value) || '');
|
||||
updateFilter('transactionTypeFilter', values.transaction_type || '');
|
||||
filterModal.closeModal();
|
||||
setSubmitting(false);
|
||||
@@ -142,14 +142,11 @@ const InventoryAdjustmentTable = () => {
|
||||
[formik]
|
||||
);
|
||||
|
||||
const handleFilterWarehouseChange = useCallback(
|
||||
(val: OptionType | OptionType[] | null) => {
|
||||
const warehouse = val as OptionType | null;
|
||||
const warehouseId = warehouse?.value ? String(warehouse.value) : null;
|
||||
formik.setFieldValue('warehouse_id', warehouseId);
|
||||
},
|
||||
[formik]
|
||||
);
|
||||
const handleFilterWarehouseChange = (
|
||||
val: OptionType | OptionType[] | null
|
||||
) => {
|
||||
formik.setFieldValue('warehouse', val);
|
||||
};
|
||||
|
||||
const handleFilterTransactionTypeChange = useCallback(
|
||||
(val: OptionType | OptionType[] | null) => {
|
||||
@@ -170,15 +167,6 @@ const InventoryAdjustmentTable = () => {
|
||||
);
|
||||
}, [formik.values.product_id, productOptions]);
|
||||
|
||||
const warehouseIdValue = useMemo(() => {
|
||||
if (!formik.values.warehouse_id) return null;
|
||||
return (
|
||||
warehouseOptions.find(
|
||||
(opt) => String(opt.value) === formik.values.warehouse_id
|
||||
) || null
|
||||
);
|
||||
}, [formik.values.warehouse_id, warehouseOptions]);
|
||||
|
||||
const transactionTypeValue = useMemo(() => {
|
||||
if (!formik.values.transaction_type) return null;
|
||||
return (
|
||||
@@ -502,7 +490,7 @@ const InventoryAdjustmentTable = () => {
|
||||
label='Gudang'
|
||||
placeholder='Pilih Gudang'
|
||||
options={warehouseOptions}
|
||||
value={warehouseIdValue}
|
||||
value={formik.values.warehouse}
|
||||
onChange={handleFilterWarehouseChange}
|
||||
onInputChange={setWarehouseInputValue}
|
||||
isLoading={isLoadingWarehouseOptions}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { string, object } from 'yup';
|
||||
import { OptionType } from '@/components/input/SelectInput';
|
||||
|
||||
export const AdjustmentFilterSchema = object().shape({
|
||||
product_id: string().nullable(),
|
||||
@@ -8,6 +9,6 @@ export const AdjustmentFilterSchema = object().shape({
|
||||
|
||||
export type AdjustmentFilterType = {
|
||||
product_id: string | null;
|
||||
warehouse_id: string | null;
|
||||
transaction_type: string | null;
|
||||
warehouse: OptionType<number> | null;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
InventoryAdjustmentFormSchema,
|
||||
InventoryAdjustmentFormValues,
|
||||
} from '@/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.schema';
|
||||
import { KandangApi, LocationApi } from '@/services/api/master-data';
|
||||
import { LocationApi } from '@/services/api/master-data';
|
||||
import {
|
||||
ProjectFlockApi,
|
||||
ProjectFlockKandangApi,
|
||||
@@ -32,8 +32,6 @@ import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||
import { Location } from '@/types/api/master-data/location';
|
||||
import { ProjectFlock } from '@/types/api/production/project-flock';
|
||||
import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
|
||||
import { Kandang } from '@/types/api/master-data/kandang';
|
||||
import { Product } from '@/types/api/master-data/product';
|
||||
import { ProjectFlockKandangLookup } from '@/types/api/production/project-flock';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
@@ -119,40 +117,19 @@ const InventoryAdjustmentForm = ({
|
||||
}
|
||||
);
|
||||
|
||||
const { rawData: approvedProjectFlockKandangsRawData } =
|
||||
useSelect<ProjectFlockKandang>(
|
||||
ProjectFlockKandangApi.basePath,
|
||||
'id',
|
||||
'id',
|
||||
'search',
|
||||
{
|
||||
step_name: 'Disetujui',
|
||||
limit: '100',
|
||||
}
|
||||
);
|
||||
|
||||
const approvedProjectFlockKandangs = useMemo(() => {
|
||||
if (
|
||||
approvedProjectFlockKandangsRawData &&
|
||||
'data' in approvedProjectFlockKandangsRawData
|
||||
) {
|
||||
return approvedProjectFlockKandangsRawData.data as ProjectFlockKandang[];
|
||||
}
|
||||
return [];
|
||||
}, [approvedProjectFlockKandangsRawData]);
|
||||
|
||||
const {
|
||||
setInputValue: setKandangInputValue,
|
||||
options: kandangOptionsFromApi,
|
||||
isLoadingOptions: isLoadingKandangOptions,
|
||||
loadMore: loadMoreKandangs,
|
||||
} = useSelect<Kandang>(
|
||||
selectedProjectFlock ? KandangApi.basePath : '',
|
||||
'id',
|
||||
'name',
|
||||
options: projectFlockKandangOptions,
|
||||
loadMore: loadMoreProjectFlockKandangs,
|
||||
setInputValue: setProjectFlockKandangInputValue,
|
||||
isLoadingOptions: isLoadingProjectFlockKandangOptions,
|
||||
} = useSelect(
|
||||
selectedProjectFlock ? ProjectFlockKandangApi.basePath : '',
|
||||
'kandang.id',
|
||||
'kandang.name',
|
||||
'search',
|
||||
{
|
||||
location_id: selectedProjectFlockLocationId,
|
||||
step_name: 'Disetujui',
|
||||
project_flock_id: String(selectedProjectFlock?.value),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -222,26 +199,6 @@ const InventoryAdjustmentForm = ({
|
||||
return (product?.flags as string[]) || [];
|
||||
}, [selectedProduct, productOptions]);
|
||||
|
||||
const kandangOptions = useMemo(() => {
|
||||
let options: OptionType[] = [];
|
||||
|
||||
if (selectedProjectFlock) {
|
||||
const approvedKandangIds = approvedProjectFlockKandangs
|
||||
.filter((pfk) => pfk.project_flock_id === selectedProjectFlock.value)
|
||||
.map((pfk) => pfk.kandang_id);
|
||||
|
||||
options = kandangOptionsFromApi.filter((kandang) =>
|
||||
approvedKandangIds.includes(kandang.value as number)
|
||||
);
|
||||
}
|
||||
|
||||
return options;
|
||||
}, [
|
||||
selectedProjectFlock,
|
||||
kandangOptionsFromApi,
|
||||
approvedProjectFlockKandangs,
|
||||
]);
|
||||
|
||||
const formikInitialValues = useMemo<Partial<InventoryAdjustmentFormValues>>(
|
||||
() => ({
|
||||
location: null,
|
||||
@@ -693,10 +650,10 @@ const InventoryAdjustmentForm = ({
|
||||
label='Kandang'
|
||||
value={selectedKandang}
|
||||
onChange={kandangChangeHandler}
|
||||
onInputChange={setKandangInputValue}
|
||||
options={kandangOptions}
|
||||
onMenuScrollToBottom={loadMoreKandangs}
|
||||
isLoading={isLoadingKandangOptions}
|
||||
onInputChange={setProjectFlockKandangInputValue}
|
||||
options={projectFlockKandangOptions}
|
||||
onMenuScrollToBottom={loadMoreProjectFlockKandangs}
|
||||
isLoading={isLoadingProjectFlockKandangOptions}
|
||||
isError={
|
||||
formik.touched.kandang_id && Boolean(formik.errors.kandang_id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user