From 65942ac9d2cd9b9a66a8b06da4cc6739dfd63e64 Mon Sep 17 00:00:00 2001 From: nico Date: Tue, 3 Mar 2026 15:30:33 +0800 Subject: [PATCH] refactor(create): remove realisasiAwal, simplify to anggaran-only input Refactoring: - Remove realisasiAwal field from ItemForm type - Remove NumberInput for realisasi awal from UI - Remove realisasiAwal column from preview table - Simplify state management (no realisasiAwal mapping) - API create: Create items with totalRealisasi=0 (no auto-create realisasi) Rationale: - Cleaner separation: Anggaran dan Realisasi adalah entitas terpisah - User create item untuk ANGGARAN dulu - Setelah item dibuat, user bisa add MULTIPLE REALISASI dengan: * Uraian yang jelas untuk setiap realisasi * Tanggal yang spesifik * Keterangan detail * Bukti file attachment - Follows the original schema design more closely Co-authored-by: Qwen-Coder --- .../(dashboard)/_state/landing-page/apbdes.ts | 19 ++--------- .../landing-page/apbdes/create/page.tsx | 17 +--------- .../_lib/landing_page/apbdes/create.ts | 32 +++++-------------- 3 files changed, 11 insertions(+), 57 deletions(-) diff --git a/src/app/admin/(dashboard)/_state/landing-page/apbdes.ts b/src/app/admin/(dashboard)/_state/landing-page/apbdes.ts index 8fa5d724..c858fba5 100644 --- a/src/app/admin/(dashboard)/_state/landing-page/apbdes.ts +++ b/src/app/admin/(dashboard)/_state/landing-page/apbdes.ts @@ -5,12 +5,11 @@ import { toast } from "react-toastify"; import { proxy } from "valtio"; import { z } from "zod"; -// --- Zod Schema untuk APBDes Item (dengan realisasiAwal opsional) --- +// --- Zod Schema untuk APBDes Item (tanpa field kalkulasi) --- const ApbdesItemSchema = z.object({ kode: z.string().min(1, "Kode wajib diisi"), uraian: z.string().min(1, "Uraian wajib diisi"), anggaran: z.number().min(0, "Anggaran tidak boleh negatif"), - realisasiAwal: z.number().min(0).optional(), // Realisasi pertama saat create level: z.number().int().min(1).max(3), tipe: z.enum(['pendapatan', 'belanja', 'pembiayaan']).nullable().optional(), }); @@ -92,21 +91,7 @@ const apbdes = proxy({ try { this.loading = true; - - // Extract realisasiAwal dari items - const itemsWithRealisasi = this.form.items.map(item => ({ - kode: item.kode, - uraian: item.uraian, - anggaran: item.anggaran, - level: item.level, - tipe: item.tipe, - realisasiAwal: item.realisasiAwal || 0, - })); - - const res = await ApiFetch.api.landingpage.apbdes["create"].post({ - ...parsed.data, - items: itemsWithRealisasi, - }); + const res = await ApiFetch.api.landingpage.apbdes["create"].post(parsed.data); if (res.data?.success) { toast.success("APBDes berhasil dibuat"); diff --git a/src/app/admin/(dashboard)/landing-page/apbdes/create/page.tsx b/src/app/admin/(dashboard)/landing-page/apbdes/create/page.tsx index 034c4503..e4990717 100644 --- a/src/app/admin/(dashboard)/landing-page/apbdes/create/page.tsx +++ b/src/app/admin/(dashboard)/landing-page/apbdes/create/page.tsx @@ -33,7 +33,6 @@ type ItemForm = { kode: string; uraian: string; anggaran: number; - realisasiAwal?: number; // Realisasi pertama saat create level: number; tipe: 'pendapatan' | 'belanja' | 'pembiayaan'; }; @@ -61,7 +60,6 @@ function CreateAPBDes() { kode: '', uraian: '', anggaran: 0, - realisasiAwal: 0, level: 1, tipe: 'pendapatan', }); @@ -80,7 +78,6 @@ function CreateAPBDes() { kode: '', uraian: '', anggaran: 0, - realisasiAwal: 0, level: 1, tipe: 'pendapatan', }); @@ -127,7 +124,7 @@ function CreateAPBDes() { // Tambahkan item ke state const handleAddItem = () => { - const { kode, uraian, anggaran, realisasiAwal, level, tipe } = newItem; + const { kode, uraian, anggaran, level, tipe } = newItem; if (!kode || !uraian) { return toast.warn("Kode dan uraian wajib diisi"); } @@ -138,7 +135,6 @@ function CreateAPBDes() { kode, uraian, anggaran, - realisasiAwal: realisasiAwal || 0, level, tipe: finalTipe, }); @@ -148,7 +144,6 @@ function CreateAPBDes() { kode: '', uraian: '', anggaran: 0, - realisasiAwal: 0, level: 1, tipe: 'pendapatan', }); @@ -423,14 +418,6 @@ function CreateAPBDes() { thousandSeparator min={0} /> - setNewItem({ ...newItem, realisasiAwal: Number(val) || 0 })} - thousandSeparator - min={0} - description="Isi jika sudah ada realisasi saat create" - />