Kebutuhan Deploy
This commit is contained in:
@@ -39,15 +39,15 @@ const grafikkepuasan = proxy({
|
||||
const res = await ApiFetch.api.kesehatan.grafikkepuasan["create"].post(grafikkepuasan.create.form);
|
||||
|
||||
if (res.status === 200) {
|
||||
const id = res.data?.data?.id;
|
||||
if (id) {
|
||||
const uuid = res.data?.data?.uuid;
|
||||
if (uuid) {
|
||||
toast.success("Success create");
|
||||
grafikkepuasan.create.form = {
|
||||
label: "",
|
||||
jumlah: "",
|
||||
};
|
||||
grafikkepuasan.findMany.load();
|
||||
return id;
|
||||
return uuid;
|
||||
}
|
||||
}
|
||||
toast.error("failed create");
|
||||
@@ -77,9 +77,9 @@ const grafikkepuasan = proxy({
|
||||
data: null as Prisma.GrafikKepuasanGetPayload<{
|
||||
omit: { isActive: true }
|
||||
}> | null,
|
||||
async load(id: string) {
|
||||
async load(uuid: string) {
|
||||
try {
|
||||
const res = await fetch(`/api/kesehatan/grafikkepuasan/${id}`);
|
||||
const res = await fetch(`/api/kesehatan/grafikkepuasan/${uuid}`);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
grafikkepuasan.findUnique.data = data.data ?? null;
|
||||
@@ -94,14 +94,14 @@ const grafikkepuasan = proxy({
|
||||
},
|
||||
},
|
||||
update: {
|
||||
id: "",
|
||||
uuid: "",
|
||||
form: {...defaultForm},
|
||||
loading: false,
|
||||
async byId() {
|
||||
},
|
||||
async submit() {
|
||||
const id = this.id;
|
||||
if (!id) {
|
||||
const uuid = this.uuid;
|
||||
if (!uuid) {
|
||||
toast.warn("ID tidak valid");
|
||||
return null;
|
||||
}
|
||||
@@ -114,7 +114,7 @@ const grafikkepuasan = proxy({
|
||||
}
|
||||
try {
|
||||
this.loading = true;
|
||||
const response = await fetch(`/api/kesehatan/grafikkepuasan/${id}`, {
|
||||
const response = await fetch(`/api/kesehatan/grafikkepuasan/${uuid}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -143,14 +143,14 @@ const grafikkepuasan = proxy({
|
||||
},
|
||||
delete: {
|
||||
loading: false,
|
||||
async byId(id: string) {
|
||||
if (!id) {
|
||||
async byId(uuid: string) {
|
||||
if (!uuid) {
|
||||
return toast.warn("ID tidak valid");
|
||||
}
|
||||
try {
|
||||
grafikkepuasan.delete.loading = true;
|
||||
|
||||
const response = await fetch(`/api/kesehatan/grafikkepuasan/del/${id}`, {
|
||||
const response = await fetch(`/api/kesehatan/grafikkepuasan/del/${uuid}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -34,28 +34,23 @@ const persentasekelahiran = proxy({
|
||||
async create() {
|
||||
const cek = templatePersentase.safeParse(persentasekelahiran.create.form);
|
||||
if (!cek.success) {
|
||||
const err = `[${cek.error.issues
|
||||
.map((v) => `${v.path.join(".")}`)
|
||||
.join("\n")}] required`;
|
||||
const err = `[${cek.error.issues.map((v) => `${v.path.join(".")}`).join("\n")}] required`;
|
||||
toast.error(err);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
persentasekelahiran.create.loading = true;
|
||||
const res = await ApiFetch.api.kesehatan.persentasekelahiran["create"].post(persentasekelahiran.create.form);
|
||||
|
||||
const res = await ApiFetch.api.kesehatan.persentasekelahiran["create"].post(
|
||||
persentasekelahiran.create.form
|
||||
);
|
||||
|
||||
if (res.status === 200) {
|
||||
const id = res.data?.data?.id;
|
||||
if (id) {
|
||||
const uuid = res.data?.data?.uuid;
|
||||
if (uuid) {
|
||||
toast.success("Success create");
|
||||
persentasekelahiran.create.form = {
|
||||
tahun: "",
|
||||
kematianKasar: "",
|
||||
kelahiranKasar: "",
|
||||
kematianBayi: "",
|
||||
};
|
||||
persentasekelahiran.create.form = { ...defaultForm };
|
||||
persentasekelahiran.findMany.load();
|
||||
return id;
|
||||
return uuid;
|
||||
}
|
||||
}
|
||||
toast.error("failed create");
|
||||
@@ -68,26 +63,26 @@ const persentasekelahiran = proxy({
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
findMany: {
|
||||
data: null as
|
||||
| Prisma.DataKematian_KelahiranGetPayload<{ omit: { isActive: true } }>[]
|
||||
| null,
|
||||
data: null as Prisma.DataKematian_KelahiranGetPayload<{
|
||||
omit: { isActive: true };
|
||||
}>[] | null,
|
||||
async load() {
|
||||
const res = await ApiFetch.api.kesehatan.persentasekelahiran[
|
||||
"find-many"
|
||||
].get();
|
||||
const res = await ApiFetch.api.kesehatan.persentasekelahiran["find-many"].get();
|
||||
if (res.status === 200) {
|
||||
persentasekelahiran.findMany.data = res.data?.data ?? [];
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
findUnique: {
|
||||
data: null as Prisma.DataKematian_KelahiranGetPayload<{
|
||||
omit: { isActive: true };
|
||||
}> | null,
|
||||
async load(id: string) {
|
||||
async load(uuid: string) {
|
||||
try {
|
||||
const res = await fetch(`/api/kesehatan/persentasekelahiran/${id}`);
|
||||
const res = await fetch(`/api/kesehatan/persentasekelahiran/${uuid}`);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
persentasekelahiran.findUnique.data = data.data ?? null;
|
||||
@@ -101,82 +96,86 @@ const persentasekelahiran = proxy({
|
||||
}
|
||||
},
|
||||
},
|
||||
update: {
|
||||
id: "",
|
||||
form: { ...defaultForm },
|
||||
loading: false,
|
||||
async byId() {},
|
||||
async submit() {
|
||||
const id = this.id;
|
||||
if (!id) {
|
||||
toast.warn("ID tidak valid");
|
||||
return null;
|
||||
|
||||
update: {
|
||||
uuid: "",
|
||||
form: { ...defaultForm },
|
||||
loading: false,
|
||||
async submit() {
|
||||
const uuid = this.uuid;
|
||||
if (!uuid) {
|
||||
toast.warn("UUID tidak valid");
|
||||
return null;
|
||||
}
|
||||
|
||||
const formData = {
|
||||
tahun: this.form.tahun,
|
||||
kematianKasar: this.form.kematianKasar,
|
||||
kelahiranKasar: this.form.kelahiranKasar,
|
||||
kematianBayi: this.form.kematianBayi,
|
||||
};
|
||||
|
||||
const cek = templatePersentase.safeParse(formData);
|
||||
if (!cek.success) {
|
||||
const err = `[${cek.error.issues
|
||||
.map((v) => `${v.path.join(".")}`)
|
||||
.join("\n")}] required`;
|
||||
toast.error(err);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
this.loading = true;
|
||||
const res = await fetch(`/api/kesehatan/persentasekelahiran/${uuid}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(formData),
|
||||
});
|
||||
|
||||
const result = await res.json();
|
||||
|
||||
if (!res.ok || !result?.success) {
|
||||
throw new Error(result?.message || "Gagal update data");
|
||||
}
|
||||
const cek = templatePersentase.safeParse(persentasekelahiran.update.form);
|
||||
if (!cek.success) {
|
||||
const err = `[${cek.error.issues
|
||||
.map((v) => `${v.path.join(".")}`)
|
||||
.join("\n")}] required`;
|
||||
return toast.error(err);
|
||||
}
|
||||
try {
|
||||
this.loading = true;
|
||||
const response = await fetch(`/api/kesehatan/persentasekelahiran/${id}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(this.form),
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok || !result?.success) {
|
||||
throw new Error(result?.message || "Gagal update data");
|
||||
}
|
||||
|
||||
toast.success("Berhasil update data!");
|
||||
|
||||
// ✅ Optional: refresh list kalau kamu langsung ke halaman list
|
||||
await persentasekelahiran.findMany.load();
|
||||
|
||||
return result.data;
|
||||
} catch (error) {
|
||||
console.error("Error update data:", error);
|
||||
toast.error("Gagal update data persentase kelahiran");
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
toast.success("Berhasil update data!");
|
||||
await persentasekelahiran.findMany.load();
|
||||
return result.data;
|
||||
} catch (error) {
|
||||
console.error("Update error:", error);
|
||||
toast.error("Gagal update data persentase kelahiran");
|
||||
throw error;
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
delete: {
|
||||
loading: false,
|
||||
async byId(id: string) {
|
||||
if (!id) return toast.warn("ID tidak valid");
|
||||
async byId(uuid: string) {
|
||||
if (!uuid) return toast.warn("UUID tidak valid");
|
||||
|
||||
try {
|
||||
persentasekelahiran.delete.loading = true;
|
||||
|
||||
const response = await fetch(
|
||||
`/api/kesehatan/persentasekelahiran/del/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
const response = await fetch(`/api/kesehatan/persentasekelahiran/del/${uuid}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok && result?.success) {
|
||||
toast.success(
|
||||
result.message || "Persentase kelahiran berhasil dihapus"
|
||||
);
|
||||
await persentasekelahiran.findMany.load(); // refresh list
|
||||
toast.success(result.message || "Persentase kelahiran berhasil dihapus");
|
||||
await persentasekelahiran.findMany.load();
|
||||
} else {
|
||||
toast.error(
|
||||
result?.message || "Gagal menghapus persentase kelahiran"
|
||||
);
|
||||
toast.error(result?.message || "Gagal menghapus persentase kelahiran");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Gagal delete:", error);
|
||||
|
||||
@@ -11,15 +11,15 @@ import { useProxy } from 'valtio/utils';
|
||||
|
||||
function EditGrafikHasilKepuasan() {
|
||||
const router = useRouter()
|
||||
const params = useParams() as { id: string }
|
||||
const params = useParams() as { uuid: string }
|
||||
const stateGrafikKepuasan = useProxy(grafikkepuasan)
|
||||
|
||||
const id = params.id
|
||||
const uuid = params.uuid
|
||||
|
||||
// Load data saat komponen mount
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
stateGrafikKepuasan.findUnique.load(id).then(() => {
|
||||
if (uuid) {
|
||||
stateGrafikKepuasan.findUnique.load(uuid).then(() => {
|
||||
const data = stateGrafikKepuasan.findUnique.data
|
||||
if (data) {
|
||||
stateGrafikKepuasan.update.form = {
|
||||
@@ -29,11 +29,11 @@ function EditGrafikHasilKepuasan() {
|
||||
}
|
||||
})
|
||||
}
|
||||
}, [id])
|
||||
}, [uuid])
|
||||
|
||||
const handleSubmit = async () => {
|
||||
// Set the ID before submitting
|
||||
stateGrafikKepuasan.update.id = id;
|
||||
stateGrafikKepuasan.update.uuid = uuid;
|
||||
await stateGrafikKepuasan.update.submit();
|
||||
router.push('/admin/kesehatan/data-kesehatan-warga/grafik_hasil_kepuasan')
|
||||
}
|
||||
@@ -45,7 +45,7 @@ function GrafikHasilKepuasanMasyarakat() {
|
||||
setMounted(true);
|
||||
if (stateGrafikKepuasan.findMany.data) {
|
||||
setChartData(stateGrafikKepuasan.findMany.data.map((item) => ({
|
||||
id: item.id,
|
||||
id: item.uuid,
|
||||
label: item.label,
|
||||
jumlah: Number(item.jumlah),
|
||||
})));
|
||||
@@ -82,11 +82,11 @@ function GrafikHasilKepuasanMasyarakat() {
|
||||
</TableThead>
|
||||
<TableTbody>
|
||||
{stateGrafikKepuasan.findMany.data?.map((item) => (
|
||||
<TableTr key={item.id}>
|
||||
<TableTr key={item.uuid}>
|
||||
<TableTd>{item.label}</TableTd>
|
||||
<TableTd>{item.jumlah}</TableTd>
|
||||
<TableTd>
|
||||
<Button color='green' onClick={() => router.push(`/admin/kesehatan/data-kesehatan-warga/grafik_hasil_kepuasan/${item.id}`)}>
|
||||
<Button color='green' onClick={() => router.push(`/admin/kesehatan/data-kesehatan-warga/grafik_hasil_kepuasan/${item.uuid}`)}>
|
||||
<IconEdit size={20} />
|
||||
</Button>
|
||||
</TableTd>
|
||||
@@ -95,7 +95,7 @@ function GrafikHasilKepuasanMasyarakat() {
|
||||
color='red'
|
||||
disabled={stateGrafikKepuasan.delete.loading}
|
||||
onClick={() => {
|
||||
setSelectedId(item.id)
|
||||
setSelectedId(item.uuid)
|
||||
setModalHapus(true)
|
||||
}}>
|
||||
<IconTrash size={20} />
|
||||
|
||||
@@ -7,38 +7,51 @@ import { Box, Button, Paper, Stack, TextInput, Title } from '@mantine/core';
|
||||
import { IconArrowBack } from '@tabler/icons-react';
|
||||
import { useParams, useRouter } from 'next/navigation';
|
||||
import { useEffect } from 'react';
|
||||
import { toast } from 'react-toastify';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
|
||||
function EditPersentaseDataKelahiranKematian() {
|
||||
const router = useRouter()
|
||||
const params = useParams() as { id: string }
|
||||
const params = useParams() as { uuid: string }
|
||||
const statePresentase = useProxy(persentasekelahiran)
|
||||
|
||||
const id = params.id
|
||||
const id = params.uuid
|
||||
|
||||
// Load data saat komponen mount
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
statePresentase.findUnique.load(id).then(() => {
|
||||
const data = statePresentase.findUnique.data
|
||||
if (data) {
|
||||
statePresentase.update.form = {
|
||||
tahun: data.tahun || '',
|
||||
kematianKasar: data.kematianKasar || '',
|
||||
kelahiranKasar: data.kelahiranKasar || '',
|
||||
kematianBayi: data.kematianBayi || '',
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}, [id])
|
||||
// Di file page.tsx, ubah useEffect-nya menjadi:
|
||||
useEffect(() => {
|
||||
if (!id) return;
|
||||
statePresentase.update.uuid = id;
|
||||
statePresentase.findUnique.load(id)
|
||||
.then(() => {
|
||||
const data = statePresentase.findUnique.data;
|
||||
if (data) {
|
||||
statePresentase.update.form = {
|
||||
tahun: String(data.tahun || ''),
|
||||
kematianKasar: String(data.kematianKasar || ''),
|
||||
kelahiranKasar: String(data.kelahiranKasar || ''),
|
||||
kematianBayi: String(data.kematianBayi || '')
|
||||
};
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error loading data:', error);
|
||||
toast.error('Gagal memuat data');
|
||||
});
|
||||
}, [id]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
// Set the ID before submitting
|
||||
statePresentase.update.id = id;
|
||||
// Di handleSubmit, ubah menjadi:
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
statePresentase.update.uuid = id;
|
||||
await statePresentase.update.submit();
|
||||
router.push('/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian')
|
||||
toast.success('Data berhasil diperbarui');
|
||||
router.push('/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian');
|
||||
} catch (error) {
|
||||
console.error('Error updating data:', error);
|
||||
toast.error('Gagal memperbarui data');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Box>
|
||||
@@ -13,7 +13,7 @@ import { ModalKonfirmasiHapus } from '../../../_com/modalKonfirmasiHapus';
|
||||
|
||||
function PersentaseDataKelahiranKematian() {
|
||||
type PDKMGrafik = {
|
||||
id: string;
|
||||
uuid: string;
|
||||
tahun: string;
|
||||
kematianKasar: number;
|
||||
kematianBayi: number;
|
||||
@@ -47,7 +47,7 @@ function PersentaseDataKelahiranKematian() {
|
||||
setMounted(true);
|
||||
if (statePersentase.findMany.data) {
|
||||
setChartData(statePersentase.findMany.data.map((item) => ({
|
||||
id: item.id,
|
||||
uuid: item.uuid,
|
||||
tahun: item.tahun,
|
||||
kematianKasar: Number(item.kematianKasar),
|
||||
kematianBayi: Number(item.kematianBayi),
|
||||
@@ -88,13 +88,13 @@ function PersentaseDataKelahiranKematian() {
|
||||
</TableThead>
|
||||
<TableTbody>
|
||||
{statePersentase.findMany.data?.map((item) => (
|
||||
<TableTr key={item.id}>
|
||||
<TableTr key={item.uuid}>
|
||||
<TableTd>{item.tahun}</TableTd>
|
||||
<TableTd>{item.kematianKasar}</TableTd>
|
||||
<TableTd>{item.kematianBayi}</TableTd>
|
||||
<TableTd>{item.kelahiranKasar}</TableTd>
|
||||
<TableTd>
|
||||
<Button color='green' onClick={() => router.push(`/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian/${item.id}`)}>
|
||||
<Button color='green' onClick={() => router.push(`/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian/${item.uuid}`)}>
|
||||
<IconEdit size={20} />
|
||||
</Button>
|
||||
</TableTd>
|
||||
@@ -103,7 +103,7 @@ function PersentaseDataKelahiranKematian() {
|
||||
color='red'
|
||||
disabled={statePersentase.delete.loading}
|
||||
onClick={() => {
|
||||
setSelectedId(item.id)
|
||||
setSelectedId(item.uuid)
|
||||
setModalHapus(true)
|
||||
}}>
|
||||
<IconTrash size={20} />
|
||||
|
||||
Reference in New Issue
Block a user