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';
|
} from '@/types/api/api-general';
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
|
||||||
export interface OptionType {
|
export interface OptionType<T = string | number> {
|
||||||
value: string | number;
|
value: T;
|
||||||
label: string;
|
label: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
labelClassName?: string;
|
labelClassName?: string;
|
||||||
|
|||||||
@@ -80,13 +80,13 @@ const InventoryAdjustmentTable = () => {
|
|||||||
const formik = useFormik<AdjustmentFilterType>({
|
const formik = useFormik<AdjustmentFilterType>({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
product_id: null,
|
product_id: null,
|
||||||
warehouse_id: null,
|
warehouse: null,
|
||||||
transaction_type: null,
|
transaction_type: null,
|
||||||
},
|
},
|
||||||
validationSchema: AdjustmentFilterSchema,
|
validationSchema: AdjustmentFilterSchema,
|
||||||
onSubmit: (values, { setSubmitting }) => {
|
onSubmit: (values, { setSubmitting }) => {
|
||||||
updateFilter('productFilter', values.product_id || '');
|
updateFilter('productFilter', values.product_id || '');
|
||||||
updateFilter('warehouseFilter', values.warehouse_id || '');
|
updateFilter('warehouseFilter', String(values.warehouse?.value) || '');
|
||||||
updateFilter('transactionTypeFilter', values.transaction_type || '');
|
updateFilter('transactionTypeFilter', values.transaction_type || '');
|
||||||
filterModal.closeModal();
|
filterModal.closeModal();
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
@@ -142,14 +142,11 @@ const InventoryAdjustmentTable = () => {
|
|||||||
[formik]
|
[formik]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleFilterWarehouseChange = useCallback(
|
const handleFilterWarehouseChange = (
|
||||||
(val: OptionType | OptionType[] | null) => {
|
val: OptionType | OptionType[] | null
|
||||||
const warehouse = val as OptionType | null;
|
) => {
|
||||||
const warehouseId = warehouse?.value ? String(warehouse.value) : null;
|
formik.setFieldValue('warehouse', val);
|
||||||
formik.setFieldValue('warehouse_id', warehouseId);
|
};
|
||||||
},
|
|
||||||
[formik]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleFilterTransactionTypeChange = useCallback(
|
const handleFilterTransactionTypeChange = useCallback(
|
||||||
(val: OptionType | OptionType[] | null) => {
|
(val: OptionType | OptionType[] | null) => {
|
||||||
@@ -170,15 +167,6 @@ const InventoryAdjustmentTable = () => {
|
|||||||
);
|
);
|
||||||
}, [formik.values.product_id, productOptions]);
|
}, [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(() => {
|
const transactionTypeValue = useMemo(() => {
|
||||||
if (!formik.values.transaction_type) return null;
|
if (!formik.values.transaction_type) return null;
|
||||||
return (
|
return (
|
||||||
@@ -502,7 +490,7 @@ const InventoryAdjustmentTable = () => {
|
|||||||
label='Gudang'
|
label='Gudang'
|
||||||
placeholder='Pilih Gudang'
|
placeholder='Pilih Gudang'
|
||||||
options={warehouseOptions}
|
options={warehouseOptions}
|
||||||
value={warehouseIdValue}
|
value={formik.values.warehouse}
|
||||||
onChange={handleFilterWarehouseChange}
|
onChange={handleFilterWarehouseChange}
|
||||||
onInputChange={setWarehouseInputValue}
|
onInputChange={setWarehouseInputValue}
|
||||||
isLoading={isLoadingWarehouseOptions}
|
isLoading={isLoadingWarehouseOptions}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { string, object } from 'yup';
|
import { string, object } from 'yup';
|
||||||
|
import { OptionType } from '@/components/input/SelectInput';
|
||||||
|
|
||||||
export const AdjustmentFilterSchema = object().shape({
|
export const AdjustmentFilterSchema = object().shape({
|
||||||
product_id: string().nullable(),
|
product_id: string().nullable(),
|
||||||
@@ -8,6 +9,6 @@ export const AdjustmentFilterSchema = object().shape({
|
|||||||
|
|
||||||
export type AdjustmentFilterType = {
|
export type AdjustmentFilterType = {
|
||||||
product_id: string | null;
|
product_id: string | null;
|
||||||
warehouse_id: string | null;
|
|
||||||
transaction_type: string | null;
|
transaction_type: string | null;
|
||||||
|
warehouse: OptionType<number> | null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
InventoryAdjustmentFormSchema,
|
InventoryAdjustmentFormSchema,
|
||||||
InventoryAdjustmentFormValues,
|
InventoryAdjustmentFormValues,
|
||||||
} from '@/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.schema';
|
} from '@/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.schema';
|
||||||
import { KandangApi, LocationApi } from '@/services/api/master-data';
|
import { LocationApi } from '@/services/api/master-data';
|
||||||
import {
|
import {
|
||||||
ProjectFlockApi,
|
ProjectFlockApi,
|
||||||
ProjectFlockKandangApi,
|
ProjectFlockKandangApi,
|
||||||
@@ -32,8 +32,6 @@ import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
|||||||
import AlertErrorList from '@/components/helper/form/FormErrors';
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
import { Location } from '@/types/api/master-data/location';
|
import { Location } from '@/types/api/master-data/location';
|
||||||
import { ProjectFlock } from '@/types/api/production/project-flock';
|
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 { Product } from '@/types/api/master-data/product';
|
||||||
import { ProjectFlockKandangLookup } from '@/types/api/production/project-flock';
|
import { ProjectFlockKandangLookup } from '@/types/api/production/project-flock';
|
||||||
import { BaseApiResponse } from '@/types/api/api-general';
|
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 {
|
const {
|
||||||
setInputValue: setKandangInputValue,
|
options: projectFlockKandangOptions,
|
||||||
options: kandangOptionsFromApi,
|
loadMore: loadMoreProjectFlockKandangs,
|
||||||
isLoadingOptions: isLoadingKandangOptions,
|
setInputValue: setProjectFlockKandangInputValue,
|
||||||
loadMore: loadMoreKandangs,
|
isLoadingOptions: isLoadingProjectFlockKandangOptions,
|
||||||
} = useSelect<Kandang>(
|
} = useSelect(
|
||||||
selectedProjectFlock ? KandangApi.basePath : '',
|
selectedProjectFlock ? ProjectFlockKandangApi.basePath : '',
|
||||||
'id',
|
'kandang.id',
|
||||||
'name',
|
'kandang.name',
|
||||||
'search',
|
'search',
|
||||||
{
|
{
|
||||||
location_id: selectedProjectFlockLocationId,
|
step_name: 'Disetujui',
|
||||||
|
project_flock_id: String(selectedProjectFlock?.value),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -222,26 +199,6 @@ const InventoryAdjustmentForm = ({
|
|||||||
return (product?.flags as string[]) || [];
|
return (product?.flags as string[]) || [];
|
||||||
}, [selectedProduct, productOptions]);
|
}, [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>>(
|
const formikInitialValues = useMemo<Partial<InventoryAdjustmentFormValues>>(
|
||||||
() => ({
|
() => ({
|
||||||
location: null,
|
location: null,
|
||||||
@@ -693,10 +650,10 @@ const InventoryAdjustmentForm = ({
|
|||||||
label='Kandang'
|
label='Kandang'
|
||||||
value={selectedKandang}
|
value={selectedKandang}
|
||||||
onChange={kandangChangeHandler}
|
onChange={kandangChangeHandler}
|
||||||
onInputChange={setKandangInputValue}
|
onInputChange={setProjectFlockKandangInputValue}
|
||||||
options={kandangOptions}
|
options={projectFlockKandangOptions}
|
||||||
onMenuScrollToBottom={loadMoreKandangs}
|
onMenuScrollToBottom={loadMoreProjectFlockKandangs}
|
||||||
isLoading={isLoadingKandangOptions}
|
isLoading={isLoadingProjectFlockKandangOptions}
|
||||||
isError={
|
isError={
|
||||||
formik.touched.kandang_id && Boolean(formik.errors.kandang_id)
|
formik.touched.kandang_id && Boolean(formik.errors.kandang_id)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user