FIX UI & API Menu Lingkungan Submenu Gotong Royong

This commit is contained in:
2025-07-22 11:53:15 +08:00
parent 80a7df663e
commit 9b2201ea57
5 changed files with 61 additions and 50 deletions

View File

@@ -41,10 +41,10 @@ const kegiatanDesa = proxy({
try {
kegiatanDesa.create.loading = true;
const res = await ApiFetch.api.lingkungan.kegiatandesa["create"].post({
...kegiatanDesa.create.form,
tanggal: kegiatanDesa.create.form.tanggal.toISOString(), // ✅ convert Date -> string
});
...kegiatanDesa.create.form,
tanggal: kegiatanDesa.create.form.tanggal.toISOString(), // ✅ convert Date -> string
});
if (res.status === 200) {
kegiatanDesa.findMany.load();
return toast.success("Data berhasil ditambahkan");
@@ -64,7 +64,7 @@ const kegiatanDesa = proxy({
include: {
image: true;
kategoriKegiatan: true;
};
};
}>
> | null,
async load() {
@@ -191,24 +191,28 @@ const kegiatanDesa = proxy({
try {
kegiatanDesa.edit.loading = true;
const response = await fetch(`/api/lingkungan/kegiatandesa/${this.id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
judul: this.form.judul,
deskripsiSingkat: this.form.deskripsiSingkat,
deskripsiLengkap: this.form.deskripsiLengkap,
tanggal: typeof this.form.tanggal === "string"
? this.form.tanggal
: this.form.tanggal.toISOString(),
lokasi: this.form.lokasi,
partisipan: this.form.partisipan,
imageId: this.form.imageId,
kategoriKegiatanId: this.form.kategoriKegiatanId,
}),
});
const response = await fetch(
`/api/lingkungan/kegiatandesa/${this.id}`,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
judul: this.form.judul,
deskripsiSingkat: this.form.deskripsiSingkat,
deskripsiLengkap: this.form.deskripsiLengkap,
tanggal:
typeof this.form.tanggal === "string"
? this.form.tanggal
: this.form.tanggal.toISOString(),
lokasi: this.form.lokasi,
partisipan: this.form.partisipan,
imageId: this.form.imageId,
kategoriKegiatanId: this.form.kategoriKegiatanId,
}),
}
);
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new Error(
@@ -226,7 +230,9 @@ const kegiatanDesa = proxy({
} catch (error) {
console.error("Error updating kegiatan desa:", error);
toast.error(
error instanceof Error ? error.message : "Gagal mengupdate kegiatan desa"
error instanceof Error
? error.message
: "Gagal mengupdate kegiatan desa"
);
return false;
} finally {
@@ -263,9 +269,9 @@ const kategoriKegiatan = proxy({
}
try {
kategoriKegiatan.create.loading = true;
const res = await ApiFetch.api.lingkungan.kegiatandesa.kategorikegiatan["create"].post(
kategoriKegiatan.create.form
);
const res = await ApiFetch.api.lingkungan.kategorikegiatan[
"create"
].post(kategoriKegiatan.create.form);
if (res.status === 200) {
kategoriKegiatan.findMany.load();
return toast.success("Data berhasil ditambahkan");
@@ -285,7 +291,9 @@ const kategoriKegiatan = proxy({
nama: string;
}> | null,
async load() {
const res = await ApiFetch.api.lingkungan.kegiatandesa.kategorikegiatan["find-many"].get();
const res = await ApiFetch.api.lingkungan.kategorikegiatan[
"find-many"
].get();
if (res.status === 200) {
kategoriKegiatan.findMany.data = res.data?.data ?? [];
}
@@ -297,7 +305,9 @@ const kategoriKegiatan = proxy({
}> | null,
async load(id: string) {
try {
const res = await fetch(`/api/lingkungan/kegiatanDesa/kategorikegiatan/${id}`);
const res = await fetch(
`/api/lingkungan/kategorikegiatan/${id}`
);
if (res.ok) {
const data = await res.json();
kategoriKegiatan.findUnique.data = data.data ?? null;
@@ -319,12 +329,15 @@ const kategoriKegiatan = proxy({
try {
kategoriKegiatan.delete.loading = true;
const response = await fetch(`/api/lingkungan/kegiatandesa/kategorikegiatan/del/${id}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
});
const response = await fetch(
`/api/lingkungan/kategorikegiatan/del/${id}`,
{
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
}
);
const result = await response.json();
@@ -354,12 +367,15 @@ const kategoriKegiatan = proxy({
}
try {
const response = await fetch(`/api/lingkungan/kegiatandesa/kategorikegiatan/${id}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
const response = await fetch(
`/api/lingkungan/kategorikegiatan/${id}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
@@ -396,7 +412,7 @@ const kategoriKegiatan = proxy({
try {
kategoriKegiatan.edit.loading = true;
const response = await fetch(
`/api/lingkungan/kegiatandesa/kategorikegiatan/${kategoriKegiatan.edit.id}`,
`/api/lingkungan/kategorikegiatan/${kategoriKegiatan.edit.id}`,
{
method: "PUT",
headers: {

View File

@@ -4,7 +4,6 @@ import KegiatanDesaDelete from "./del";
import KegiatanDesaFindMany from "./findMany";
import KegiatanDesaFindUnique from "./findUnique";
import KegiatanDesaUpdate from "./updt";
import KategoriKegiatan from "./kategori-kegiatan";
const KegiatanDesa = new Elysia({
prefix: "/kegiatandesa",
@@ -44,11 +43,6 @@ const KegiatanDesa = new Elysia({
kategoriKegiatanId: t.Optional(t.String()),
}),
})
// ✅ Kategori kegiatan routes (nested)
.use(KategoriKegiatan)
// ✅ Delete
.delete("/del/:id", KegiatanDesaDelete);

View File

@@ -25,7 +25,7 @@ const kategoriKegiatanDelete = async (context: Context) => {
return {
success: true,
message: "Success delete kategori kegiatan",
message: "Success delete kategori produk",
data: kategoriKegiatan,
}
}

View File

@@ -22,7 +22,6 @@ const KategoriKegiatan = new Elysia({
})
.put("/:id", kategoriKegiatanUpdate, {
body: t.Object({
id: t.String(),
nama: t.String(),
}),
});

View File

@@ -5,6 +5,7 @@ import DataLingkunganDesa from "./data-lingkungan-desa";
import EdukasiLingkungan from "./edukasi-lingkungan";
import KonservasiAdatBali from "./konservasi-adat-bali";
import KegiatanDesa from "./gotong-royong";
import KategoriKegiatan from "./gotong-royong/kategori-kegiatan";
const Lingkungan = new Elysia({
prefix: "/api/lingkungan",
@@ -17,6 +18,7 @@ const Lingkungan = new Elysia({
.use(EdukasiLingkungan)
.use(KonservasiAdatBali)
.use(KegiatanDesa)
.use(KategoriKegiatan)
export default Lingkungan;