feat(FE-208,212): enhance PurchaseRequestForm with dummy data and update type definitions for purchase items

This commit is contained in:
rstubryan
2025-11-04 13:17:43 +07:00
parent 4828af71b8
commit ef193b9f03
2 changed files with 198 additions and 5 deletions
+186 -5
View File
@@ -6,7 +6,7 @@ import useSWR from 'swr';
import PurchaseRequestForm from '@/components/pages/purchase/form/request/PurchaseRequestForm'; import PurchaseRequestForm from '@/components/pages/purchase/form/request/PurchaseRequestForm';
import { PurchaseApi } from '@/services/api/purchase'; import { PurchaseApi } from '@/services/api/purchase';
import { isResponseError } from '@/lib/api-helper'; import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
import { Purchase } from '@/types/api/purchase/purchase'; import { Purchase } from '@/types/api/purchase/purchase';
@@ -54,6 +54,190 @@ const DUMMY_PURCHASE_EDIT: Purchase = {
email: 'a@email.com', email: 'a@email.com',
name: 'Admin User', name: 'Admin User',
}, },
purchase_items: [
{
id: 1,
product_warehouse: {
id: 1,
product_id: 1,
warehouse_id: 1,
quantity: 100,
product: {
id: 1,
name: 'Product A',
brand: 'Brand A',
sku: 'PROD-A-001',
product_price: 500000,
expiry_period: 0,
uom: {
id: 1,
name: 'pcs',
created_at: '2024-01-01T00:00:00Z',
updated_at: '2024-01-01T00:00:00Z',
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
},
product_category: {
id: 1,
code: 'CAT-1',
name: 'Electronics',
created_at: '2024-01-01T00:00:00Z',
updated_at: '2024-01-01T00:00:00Z',
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
},
suppliers: [
{
id: 1,
name: 'Supplier A',
alias: 'SupA',
pic: 'John Doe',
type: 'Local',
category: 'Electronics',
hatchery: 'N/A',
phone: '555-1234',
email: 'email@.com',
address: '123 Main St, Cityville',
npwp: '12.345.678.9-012.345',
account_number: 'ACC-12345',
due_date: 30,
balance: 1000000,
created_at: '2024-01-10T10:00:00Z',
updated_at: '2024-01-12T12:00:00Z',
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
},
],
flags: [],
created_at: '2024-01-05T09:00:00Z',
updated_at: '2024-01-07T11:00:00Z',
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
},
warehouse: {
id: 1,
name: 'Main Warehouse',
type: 'AREA',
area: { id: 1, name: 'Area 1' },
created_at: '2024-01-01T00:00:00Z',
updated_at: '2024-01-01T00:00:00Z',
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
},
created_at: '2024-01-05T09:00:00Z',
updated_at: '2024-01-07T11:00:00Z',
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
},
product: {
id: 1,
name: 'Product A',
brand: 'Brand A',
sku: 'PROD-A-001',
product_price: 500000,
expiry_period: 0,
uom: {
id: 1,
name: 'pcs',
created_at: '2024-01-01T00:00:00Z',
updated_at: '2024-01-01T00:00:00Z',
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
},
product_category: {
id: 1,
code: 'CAT-1',
name: 'Electronics',
created_at: '2024-01-01T00:00:00Z',
updated_at: '2024-01-01T00:00:00Z',
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
},
suppliers: [
{
id: 1,
name: 'Supplier A',
alias: 'SupA',
pic: 'John Doe',
type: 'Local',
category: 'Electronics',
hatchery: 'N/A',
phone: '555-1234',
email: 'email@.com',
address: '123 Main St, Cityville',
npwp: '12.345.678.9-012.345',
account_number: 'ACC-12345',
due_date: 30,
balance: 1000000,
created_at: '2024-01-10T10:00:00Z',
updated_at: '2024-01-12T12:00:00Z',
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
},
],
flags: [],
created_at: '2024-01-05T09:00:00Z',
updated_at: '2024-01-07T11:00:00Z',
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
},
warehouse: {
id: 1,
name: 'Main Warehouse',
type: 'AREA',
area: { id: 1, name: 'Area 1' },
created_at: '2024-01-01T00:00:00Z',
updated_at: '2024-01-01T00:00:00Z',
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
},
sub_qty: 3,
},
],
}; };
const PurchaseEdit = () => { const PurchaseEdit = () => {
@@ -91,11 +275,8 @@ const PurchaseEdit = () => {
{isLoadingPurchase && ( {isLoadingPurchase && (
<span className='loading loading-spinner loading-xl' /> <span className='loading loading-spinner loading-xl' />
)} )}
{/* {!isLoadingPurchase && isResponseSuccess(purchase) && (
<PurchaseRequestForm type='detail' initialValues={purchase.data} />
)} */}
{/* TODO: remove this dummy data and integrate to real API */} {/* DEBUG TEMP: force dummy to verify form mapping/rendering */}
<PurchaseRequestForm type='edit' initialValues={DUMMY_PURCHASE_EDIT} /> <PurchaseRequestForm type='edit' initialValues={DUMMY_PURCHASE_EDIT} />
</div> </div>
); );
+12
View File
@@ -1,5 +1,16 @@
import { BaseMetadata } from '@/types/api/api-general'; import { BaseMetadata } from '@/types/api/api-general';
import { Supplier } from '@/types/api/master-data/supplier'; import { Supplier } from '@/types/api/master-data/supplier';
import { Warehouse } from '@/types/api/master-data/warehouse';
import { Product } from '@/types/api/master-data/product';
import { ProductWarehouse } from '@/types/api/inventory/product-warehouse';
export type PurchaseItem = {
id: number;
warehouse: Warehouse;
product: Product;
product_warehouse: ProductWarehouse;
sub_qty: number;
};
export type BasePurchase = { export type BasePurchase = {
id: number; id: number;
@@ -13,6 +24,7 @@ export type BasePurchase = {
notes?: string | null; notes?: string | null;
deleted_at?: string | null; deleted_at?: string | null;
created_by: number; created_by: number;
purchase_items?: PurchaseItem[];
}; };
export type Purchase = BaseMetadata & BasePurchase; export type Purchase = BaseMetadata & BasePurchase;