mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
refactor(FE): Refactor product selection to use ProductWarehouse API
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { isResponseError } from '@/lib/api-helper';
|
import { isResponseError } from '@/lib/api-helper';
|
||||||
import { InventoryAdjustmentApi } from '@/services/api/inventory';
|
import {
|
||||||
|
InventoryAdjustmentApi,
|
||||||
|
ProductWarehouseApi,
|
||||||
|
} from '@/services/api/inventory';
|
||||||
import {
|
import {
|
||||||
CreateInventoryAdjustmentPayload,
|
CreateInventoryAdjustmentPayload,
|
||||||
InventoryAdjustment,
|
InventoryAdjustment,
|
||||||
@@ -14,11 +17,7 @@ import {
|
|||||||
InventoryAdjustmentFormSchema,
|
InventoryAdjustmentFormSchema,
|
||||||
InventoryAdjustmentFormValues,
|
InventoryAdjustmentFormValues,
|
||||||
} from '@/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.schema';
|
} from '@/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.schema';
|
||||||
import {
|
import { KandangApi, LocationApi } from '@/services/api/master-data';
|
||||||
KandangApi,
|
|
||||||
LocationApi,
|
|
||||||
ProductApi,
|
|
||||||
} from '@/services/api/master-data';
|
|
||||||
import {
|
import {
|
||||||
ProjectFlockApi,
|
ProjectFlockApi,
|
||||||
ProjectFlockKandangApi,
|
ProjectFlockKandangApi,
|
||||||
@@ -36,7 +35,7 @@ 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 { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
|
||||||
import { Kandang } from '@/types/api/master-data/kandang';
|
import { Kandang } from '@/types/api/master-data/kandang';
|
||||||
import { Product } from '@/types/api/master-data/product';
|
import { ProductWarehouse } from '@/types/api/inventory/product-warehouse';
|
||||||
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';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
@@ -184,18 +183,19 @@ const InventoryAdjustmentForm = ({
|
|||||||
const {
|
const {
|
||||||
setInputValue: setProductInputValue,
|
setInputValue: setProductInputValue,
|
||||||
options: productOptions,
|
options: productOptions,
|
||||||
|
rawData: productWarehouseRawData,
|
||||||
isLoadingOptions: isLoadingProductOptions,
|
isLoadingOptions: isLoadingProductOptions,
|
||||||
loadMore: loadMoreProducts,
|
loadMore: loadMoreProducts,
|
||||||
} = useSelect<Product>(
|
} = useSelect<ProductWarehouse>(
|
||||||
projectFlockKandangLookup?.project_flock_kandang_id
|
selectedKandang && selectedProjectFlockLocationId
|
||||||
? ProductApi.basePath
|
? ProductWarehouseApi.basePath
|
||||||
: '',
|
: '',
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'product.name',
|
||||||
'search',
|
'search',
|
||||||
{
|
{
|
||||||
project_flock_kandang_id:
|
kandang_id: selectedKandang?.value?.toString() || '',
|
||||||
projectFlockKandangLookup?.project_flock_kandang_id?.toString() || '',
|
location_id: selectedProjectFlockLocationId,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -345,7 +345,23 @@ const InventoryAdjustmentForm = ({
|
|||||||
|
|
||||||
const productChangeHandler = (val: OptionType | OptionType[] | null) => {
|
const productChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||||
const product = val as OptionType | null;
|
const product = val as OptionType | null;
|
||||||
const productId = product?.value ?? 0;
|
const productWarehouseId = product?.value ?? 0;
|
||||||
|
|
||||||
|
let productId = 0;
|
||||||
|
if (
|
||||||
|
productWarehouseId &&
|
||||||
|
productWarehouseRawData &&
|
||||||
|
'data' in productWarehouseRawData
|
||||||
|
) {
|
||||||
|
const productWarehouses =
|
||||||
|
productWarehouseRawData.data as ProductWarehouse[];
|
||||||
|
const selectedProductWarehouse = productWarehouses.find(
|
||||||
|
(pw) => pw.id === productWarehouseId
|
||||||
|
);
|
||||||
|
if (selectedProductWarehouse) {
|
||||||
|
productId = selectedProductWarehouse.product_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
formik.setFieldTouched('product', true);
|
formik.setFieldTouched('product', true);
|
||||||
formik.setFieldValue('product', product);
|
formik.setFieldValue('product', product);
|
||||||
|
|||||||
Reference in New Issue
Block a user