refactor(FE-208): rename PurchaseRequestForm to PurchaseRequisitionsForm and update related components

This commit is contained in:
rstubryan
2025-11-08 09:53:21 +07:00
parent 53751d566c
commit 10dca5c692
5 changed files with 300 additions and 506 deletions
+4 -4
View File
@@ -1,11 +1,11 @@
import PurchaseRequestForm from '@/components/pages/purchase/form/request/PurchaseRequestForm';
import PurchaseRequisitionsForm from '@/components/pages/purchase/form/request/PurchaseRequisitionsForm';
const AddPurchaseRequest = () => {
const AddPurchaseRequisitions = () => {
return (
<div className='w-full p-4 flex flex-row justify-center'>
<PurchaseRequestForm />
<PurchaseRequisitionsForm />
</div>
);
};
export default AddPurchaseRequest;
export default AddPurchaseRequisitions;
+6 -244
View File
@@ -2,243 +2,9 @@
import { useRouter, useSearchParams } from 'next/navigation';
import useSWR from 'swr';
import PurchaseRequestForm from '@/components/pages/purchase/form/request/PurchaseRequestForm';
import PurchaseRequisitionsForm from '@/components/pages/purchase/form/request/PurchaseRequisitionsForm';
import { PurchaseApi } from '@/services/api/purchase';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
import { Purchase } from '@/types/api/purchase/purchase';
// TODO: delete dummy data
const DUMMY_PURCHASE_EDIT: Purchase = {
id: 1,
pr_number: 'PR-001',
po_number: 'PO-001',
po_date: '2024-01-15',
supplier: {
id: 1,
name: 'Supplier A',
address: '123 Main St, Cityville',
account_number: 'ACC-12345',
alias: 'SupA',
category: 'Electronics',
type: 'Local',
phone: '555-1234',
email: 'email@.com',
npwp: '12.345.678.9-012.345',
pic: 'John Doe',
balance: 1000000,
hatchery: 'N/A',
due_date: 30,
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',
},
},
credit_term: 30,
due_date: '2024-02-14',
grand_total: 1500000,
notes: 'Urgent delivery required',
deleted_at: null,
created_at: '2024-01-10T10:00:00Z',
updated_at: '2024-01-12T12:00:00Z',
created_by: 2,
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
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,
},
],
};
import { isResponseSuccess, isResponseError } from '@/lib/api-helper';
const PurchaseEdit = () => {
const router = useRouter();
@@ -261,11 +27,7 @@ const PurchaseEdit = () => {
);
}
// TODO: remove dummy data and integrate with real API
if (
!isLoadingPurchase &&
(!purchase || (isResponseError(purchase) && !DUMMY_PURCHASE_EDIT))
) {
if (!isLoadingPurchase && (!purchase || isResponseError(purchase))) {
router.replace('/404');
return;
}
@@ -275,9 +37,9 @@ const PurchaseEdit = () => {
{isLoadingPurchase && (
<span className='loading loading-spinner loading-xl' />
)}
{/* DEBUG TEMP: force dummy to verify form mapping/rendering */}
<PurchaseRequestForm type='edit' initialValues={DUMMY_PURCHASE_EDIT} />
{!isLoadingPurchase && isResponseSuccess(purchase) && (
<PurchaseRequisitionsForm type='edit' initialValues={purchase.data} />
)}
</div>
);
};
+6 -66
View File
@@ -2,59 +2,9 @@
import { useRouter, useSearchParams } from 'next/navigation';
import useSWR from 'swr';
import PurchaseRequestForm from '@/components/pages/purchase/form/request/PurchaseRequestForm';
import PurchaseRequisitionsForm from '@/components/pages/purchase/form/request/PurchaseRequisitionsForm';
import { PurchaseApi } from '@/services/api/purchase';
import { isResponseError } from '@/lib/api-helper';
import { Purchase } from '@/types/api/purchase/purchase';
// TODO: delete dummy data
const DUMMY_PURCHASE_DETAIL: Purchase = {
id: 1,
pr_number: 'PR-001',
po_number: 'PO-001',
po_date: '2024-01-15',
supplier: {
id: 1,
name: 'Supplier A',
address: '123 Main St, Cityville',
account_number: 'ACC-12345',
alias: 'SupA',
category: 'Electronics',
type: 'Local',
phone: '555-1234',
email: 'email@.com',
npwp: '12.345.678.9-012.345',
pic: 'John Doe',
balance: 1000000,
hatchery: 'N/A',
due_date: 30,
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',
},
},
credit_term: 30,
due_date: '2024-02-14',
grand_total: 1500000,
notes: 'Urgent delivery required',
deleted_at: null,
created_at: '2024-01-10T10:00:00Z',
updated_at: '2024-01-12T12:00:00Z',
created_by: 2,
created_user: {
id: 2,
id_user: 2,
email: 'a@email.com',
name: 'Admin User',
},
};
import { isResponseSuccess, isResponseError } from '@/lib/api-helper';
const PurchaseDetail = () => {
const router = useRouter();
@@ -77,11 +27,7 @@ const PurchaseDetail = () => {
);
}
// TODO: remove dummy data and integrate with real API
if (
!isLoadingPurchase &&
(!purchase || (isResponseError(purchase) && !DUMMY_PURCHASE_DETAIL))
) {
if (!isLoadingPurchase && (!purchase || isResponseError(purchase))) {
router.replace('/404');
return;
}
@@ -91,15 +37,9 @@ const PurchaseDetail = () => {
{isLoadingPurchase && (
<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 */}
<PurchaseRequestForm
type='detail'
initialValues={DUMMY_PURCHASE_DETAIL}
/>
{!isLoadingPurchase && isResponseSuccess(purchase) && (
<PurchaseRequisitionsForm type='detail' initialValues={purchase.data} />
)}
</div>
);
};