feat/FE/US-34/TASK-52-53-slicing-ui-table-adjust-form-with-api

This commit is contained in:
randy-ar
2025-10-11 13:12:05 +07:00
parent aa7b6581d9
commit b75b5956eb
3 changed files with 151 additions and 37 deletions
+42 -5
View File
@@ -1,11 +1,48 @@
import InventoryAdjustmentForm from "@/components/pages/inventory/adjustment/form/InventoryAdjustmentForm";
'use client';
import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import useSWR from 'swr';
import InventoryAdjustmentForm from '@/components/pages/inventory/adjustment/form/InventoryAdjustmentForm';
import { inventoryAdjustmentApi } from '@/services/api/inventory';
import type { InventoryAdjustment } from '@/types/api/inventory/adjustment';
const DetailInventoryAdjustment = () => {
const router = useRouter();
const [inventoryAdjustment, setInventoryAdjustment] = useState<InventoryAdjustment | null>(null);
// Ambil data dari router state
useEffect(() => {
console.log("Router State");
console.log(window.history.state);
const state = window.history.state?.usr as
| { inventoryAdjustment?: InventoryAdjustment }
| undefined;
if (state?.inventoryAdjustment) {
// jika object dikirim via router.push(state)
setInventoryAdjustment(state.inventoryAdjustment);
}
}, [router]);
const finalData = inventoryAdjustment;
console.log("Final Data");
console.log(finalData);
if (!finalData) {
return (
<div className="w-full flex flex-row justify-center items-center p-4">
<span className="loading loading-spinner loading-xl" />
</div>
);
}
return (
<section>
<InventoryAdjustmentForm/>
<section className="w-full p-4 flex flex-row justify-center">
<InventoryAdjustmentForm initialValues={finalData} />
</section>
);
}
};
export default DetailInventoryAdjustment;
export default DetailInventoryAdjustment;