feat(admin): implement edit and delete functionality for UMKM and Produk modules
- Added update and del methods to UMKM Valtio state - Wired up edit and delete buttons in UMKM and Produk list pages - Integrated ModalKonfirmasiHapus for deletion safety - Created UMKM and Produk edit pages with data loading and image previews - Cleaned up unused imports and fixed useEffect dependencies - Bumped version to 0.1.21
This commit is contained in:
@@ -124,6 +124,57 @@ export const umkmState = proxy({
|
||||
return false;
|
||||
}
|
||||
},
|
||||
update: {
|
||||
form: { ...defaultUmkmForm },
|
||||
loading: false,
|
||||
async submit(id: string) {
|
||||
const cek = umkmFormSchema.safeParse(this.form);
|
||||
if (!cek.success) return toast.error("Cek kembali form anda");
|
||||
this.loading = true;
|
||||
try {
|
||||
const res = await fetch(`/api/ekonomi/umkm/update/${id}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(this.form)
|
||||
});
|
||||
const result = await res.json();
|
||||
if (result.success) {
|
||||
toast.success("UMKM berhasil diperbarui");
|
||||
umkmState.umkm.findMany.load();
|
||||
return true;
|
||||
}
|
||||
toast.error(result.message);
|
||||
} catch (e) {
|
||||
toast.error("Gagal memperbarui UMKM");
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
del: {
|
||||
loading: false,
|
||||
async submit(id: string) {
|
||||
this.loading = true;
|
||||
try {
|
||||
const res = await fetch(`/api/ekonomi/umkm/delete/${id}`, {
|
||||
method: "DELETE"
|
||||
});
|
||||
const result = await res.json();
|
||||
if (result.success) {
|
||||
toast.success("UMKM berhasil dihapus");
|
||||
umkmState.umkm.findMany.load();
|
||||
return true;
|
||||
}
|
||||
toast.error(result.message);
|
||||
} catch (e) {
|
||||
toast.error("Gagal menghapus UMKM");
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
findUnique: {
|
||||
data: null as any,
|
||||
loading: false,
|
||||
@@ -203,6 +254,47 @@ export const umkmState = proxy({
|
||||
} catch (e) { toast.error("Gagal membuat produk"); } finally { this.loading = false; }
|
||||
return false;
|
||||
}
|
||||
},
|
||||
update: {
|
||||
form: { ...defaultProdukForm },
|
||||
loading: false,
|
||||
async submit(id: string) {
|
||||
const cek = produkFormSchema.safeParse(this.form);
|
||||
if (!cek.success) return toast.error("Cek kembali form anda");
|
||||
this.loading = true;
|
||||
try {
|
||||
const res = await fetch(`/api/ekonomi/umkm/produk/update/${id}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(this.form)
|
||||
});
|
||||
const result = await res.json();
|
||||
if (result.success) {
|
||||
toast.success("Produk berhasil diperbarui");
|
||||
umkmState.produk.findMany.load();
|
||||
return true;
|
||||
}
|
||||
} catch (e) { toast.error("Gagal memperbarui produk"); } finally { this.loading = false; }
|
||||
return false;
|
||||
}
|
||||
},
|
||||
del: {
|
||||
loading: false,
|
||||
async submit(id: string) {
|
||||
this.loading = true;
|
||||
try {
|
||||
const res = await fetch(`/api/ekonomi/umkm/produk/delete/${id}`, {
|
||||
method: "DELETE"
|
||||
});
|
||||
const result = await res.json();
|
||||
if (result.success) {
|
||||
toast.success("Produk berhasil dihapus");
|
||||
umkmState.produk.findMany.load();
|
||||
return true;
|
||||
}
|
||||
} catch (e) { toast.error("Gagal menghapus produk"); } finally { this.loading = false; }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user