UI & API Admin Kesehatan Done
This commit is contained in:
@@ -0,0 +1,214 @@
|
|||||||
|
import ApiFetch from "@/lib/api-fetch";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
import { proxy } from "valtio";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const templateForm = z.object({
|
||||||
|
name: z.string().min(3, "Judul minimal 3 karakter"),
|
||||||
|
deskripsiSingkat: z.string().min(3, "Deskripsi singkat minimal 3 karakter"),
|
||||||
|
deskripsiLengkap: z.string().min(3, "Deskripsi lengkap minimal 3 karakter"),
|
||||||
|
imageId: z.string().nonempty(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const defaultForm = {
|
||||||
|
name: "",
|
||||||
|
deskripsiSingkat: "",
|
||||||
|
deskripsiLengkap: "",
|
||||||
|
imageId: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
const infoWabahPenyakit = proxy({
|
||||||
|
findMany: {
|
||||||
|
data: [] as Prisma.InfoWabahPenyakitGetPayload<{
|
||||||
|
include: {
|
||||||
|
image: true;
|
||||||
|
};
|
||||||
|
}>[],
|
||||||
|
async load() {
|
||||||
|
const res = await ApiFetch.api.kesehatan.infowabahpenyakit[
|
||||||
|
"find-many"
|
||||||
|
].get();
|
||||||
|
if (res.status === 200) {
|
||||||
|
infoWabahPenyakit.findMany.data = res.data?.data ?? [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
form: { ...defaultForm },
|
||||||
|
loading: false,
|
||||||
|
async create() {
|
||||||
|
const cek = templateForm.safeParse(infoWabahPenyakit.create.form);
|
||||||
|
if (!cek.success) {
|
||||||
|
const err = `[${cek.error.issues
|
||||||
|
.map((v) => `${v.path.join(".")}`)
|
||||||
|
.join("\n")}] required`;
|
||||||
|
return toast.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
infoWabahPenyakit.create.loading = true;
|
||||||
|
const res = await ApiFetch.api.kesehatan.infowabahpenyakit[
|
||||||
|
"create"
|
||||||
|
].post(infoWabahPenyakit.create.form);
|
||||||
|
if (res.status === 200) {
|
||||||
|
infoWabahPenyakit.findMany.load();
|
||||||
|
return toast.success("Info wabah penyakit berhasil disimpan!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return toast.error("Gagal menyimpan info wabah penyakit");
|
||||||
|
} catch (error) {
|
||||||
|
console.log((error as Error).message);
|
||||||
|
} finally {
|
||||||
|
infoWabahPenyakit.create.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resetForm() {
|
||||||
|
infoWabahPenyakit.create.form = { ...defaultForm };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
findUnique: {
|
||||||
|
data: null as Prisma.InfoWabahPenyakitGetPayload<{
|
||||||
|
include: {
|
||||||
|
image: true;
|
||||||
|
};
|
||||||
|
}> | null,
|
||||||
|
async load(id: string) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/kesehatan/infowabahpenyakit/${id}`);
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
infoWabahPenyakit.findUnique.data = data.data ?? null;
|
||||||
|
} else {
|
||||||
|
console.error("Failed to fetch info wabah penyakit:", res.statusText);
|
||||||
|
infoWabahPenyakit.findUnique.data = null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching info wabah penyakit:", error);
|
||||||
|
infoWabahPenyakit.findUnique.data = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
delete: {
|
||||||
|
loading: false,
|
||||||
|
async byId(id: string) {
|
||||||
|
if (!id) return toast.warn("ID tidak valid");
|
||||||
|
|
||||||
|
try {
|
||||||
|
infoWabahPenyakit.delete.loading = true;
|
||||||
|
|
||||||
|
const response = await fetch(`/api/kesehatan/infowabahpenyakit/del/${id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
if (response.ok && result?.success) {
|
||||||
|
toast.success(result.message || "Info wabah penyakit berhasil dihapus");
|
||||||
|
await infoWabahPenyakit.findMany.load(); // refresh list
|
||||||
|
} else {
|
||||||
|
toast.error(result?.message || "Gagal menghapus info wabah penyakit");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Gagal delete:", error);
|
||||||
|
toast.error("Terjadi kesalahan saat menghapus info wabah penyakit");
|
||||||
|
} finally {
|
||||||
|
infoWabahPenyakit.delete.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
edit: {
|
||||||
|
id: "",
|
||||||
|
form: { ...defaultForm },
|
||||||
|
loading: false,
|
||||||
|
|
||||||
|
async load(id: string) {
|
||||||
|
if (!id) {
|
||||||
|
toast.warn("ID tidak valid");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/kesehatan/infowabahpenyakit/${id}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const result = await response.json();
|
||||||
|
if (result?.success) {
|
||||||
|
const data = result.data;
|
||||||
|
this.id = data.id;
|
||||||
|
this.form = {
|
||||||
|
name: data.name,
|
||||||
|
deskripsiSingkat: data.deskripsiSingkat,
|
||||||
|
deskripsiLengkap: data.deskripsiLengkap,
|
||||||
|
imageId: data.imageId,
|
||||||
|
};
|
||||||
|
return data; // Return the loaded data
|
||||||
|
} else {
|
||||||
|
throw new Error(result?.message || "Gagal memuat data");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching info wabah penyakit:", error);
|
||||||
|
toast.error(error instanceof Error ? error.message : "Gagal memuat data");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async update() {
|
||||||
|
const cek = templateForm.safeParse(infoWabahPenyakit.edit.form);
|
||||||
|
if (!cek.success) {
|
||||||
|
const err = `[${cek.error.issues
|
||||||
|
.map((v) => `${v.path.join(".")}`)
|
||||||
|
.join("\n")}] required`;
|
||||||
|
return toast.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
infoWabahPenyakit.edit.loading = true;
|
||||||
|
const response = await fetch(`/api/kesehatan/infowabahpenyakit/${this.id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: this.form.name,
|
||||||
|
deskripsiSingkat: this.form.deskripsiSingkat,
|
||||||
|
deskripsiLengkap: this.form.deskripsiLengkap,
|
||||||
|
imageId: this.form.imageId,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const result = await response.json();
|
||||||
|
if (result.success) {
|
||||||
|
toast.success(result.message || "Info wabah penyakit berhasil diupdate");
|
||||||
|
await infoWabahPenyakit.findMany.load();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
throw new Error(result.message || "Gagal update info wabah penyakit");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Gagal update:", error);
|
||||||
|
toast.error(error instanceof Error ? error.message : "Terjadi kesalahan saat mengupdate info wabah penyakit");
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
infoWabahPenyakit.edit.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
reset() {
|
||||||
|
infoWabahPenyakit.edit.id = "";
|
||||||
|
infoWabahPenyakit.edit.form = { ...defaultForm };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default infoWabahPenyakit;
|
||||||
@@ -0,0 +1,208 @@
|
|||||||
|
import ApiFetch from "@/lib/api-fetch";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
import { proxy } from "valtio";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const templateForm = z.object({
|
||||||
|
name: z.string().min(3, "Judul minimal 3 karakter"),
|
||||||
|
deskripsi: z.string().min(3, "Deskripsi minimal 3 karakter"),
|
||||||
|
imageId: z.string().nonempty(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const defaultForm = {
|
||||||
|
name: "",
|
||||||
|
deskripsi: "",
|
||||||
|
imageId: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
const kontakDarurat = proxy({
|
||||||
|
findMany: {
|
||||||
|
data: [] as Prisma.KontakDaruratGetPayload<{
|
||||||
|
include: {
|
||||||
|
image: true;
|
||||||
|
};
|
||||||
|
}>[],
|
||||||
|
async load() {
|
||||||
|
const res = await ApiFetch.api.kesehatan.kontakdarurat[
|
||||||
|
"find-many"
|
||||||
|
].get();
|
||||||
|
if (res.status === 200) {
|
||||||
|
kontakDarurat.findMany.data = res.data?.data ?? [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create:{
|
||||||
|
form: {...defaultForm},
|
||||||
|
loading: false,
|
||||||
|
async create() {
|
||||||
|
const cek = templateForm.safeParse(kontakDarurat.create.form);
|
||||||
|
if (!cek.success) {
|
||||||
|
const err = `[${cek.error.issues
|
||||||
|
.map((v) => `${v.path.join(".")}`)
|
||||||
|
.join("\n")}] required`;
|
||||||
|
return toast.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
kontakDarurat.create.loading = true;
|
||||||
|
const res = await ApiFetch.api.kesehatan.kontakdarurat[
|
||||||
|
"create"
|
||||||
|
].post(kontakDarurat.create.form);
|
||||||
|
if (res.status === 200) {
|
||||||
|
kontakDarurat.findMany.load();
|
||||||
|
return toast.success("Kontak Darurat berhasil disimpan!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return toast.error("Gagal menyimpan kontak darurat");
|
||||||
|
} catch (error) {
|
||||||
|
console.log((error as Error).message);
|
||||||
|
} finally {
|
||||||
|
kontakDarurat.create.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resetForm() {
|
||||||
|
kontakDarurat.create.form = {...defaultForm};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
findUnique: {
|
||||||
|
data: null as Prisma.KontakDaruratGetPayload<{
|
||||||
|
include: {
|
||||||
|
image: true;
|
||||||
|
};
|
||||||
|
}> | null,
|
||||||
|
async load(id: string) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/kesehatan/kontakdarurat/${id}`);
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
kontakDarurat.findUnique.data = data.data ?? null;
|
||||||
|
} else {
|
||||||
|
console.error("Failed to fetch data", res.status, res.statusText);
|
||||||
|
kontakDarurat.findUnique.data = null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching data:", error);
|
||||||
|
kontakDarurat.findUnique.data = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
delete: {
|
||||||
|
loading: false,
|
||||||
|
async byId(id: string) {
|
||||||
|
try {
|
||||||
|
kontakDarurat.delete.loading = true;
|
||||||
|
const response = await fetch(`/api/kesehatan/kontakdarurat/del/${id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (response.ok && result?.success) {
|
||||||
|
toast.success(result.message || "Kontak darurat berhasil dihapus");
|
||||||
|
await kontakDarurat.findMany.load(); // refresh list
|
||||||
|
} else {
|
||||||
|
toast.error(result?.message || "Gagal menghapus kontak darurat");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Gagal delete:", error);
|
||||||
|
toast.error("Terjadi kesalahan saat menghapus kontak darurat");
|
||||||
|
} finally {
|
||||||
|
kontakDarurat.delete.loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
edit: {
|
||||||
|
id: "",
|
||||||
|
form: { ...defaultForm },
|
||||||
|
loading: false,
|
||||||
|
|
||||||
|
async load(id: string) {
|
||||||
|
if (!id) {
|
||||||
|
toast.warn("ID tidak valid");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/kesehatan/kontakdarurat/${id}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const result = await response.json();
|
||||||
|
if (result?.success) {
|
||||||
|
const data = result.data;
|
||||||
|
this.id = data.id;
|
||||||
|
this.form = {
|
||||||
|
name: data.name,
|
||||||
|
deskripsi: data.deskripsi,
|
||||||
|
imageId: data.imageId,
|
||||||
|
};
|
||||||
|
return data; // Return the loaded data
|
||||||
|
} else {
|
||||||
|
throw new Error(result?.message || "Gagal memuat data");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching kontak darurat:", error);
|
||||||
|
toast.error(error instanceof Error ? error.message : "Gagal memuat data");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async update() {
|
||||||
|
const cek = templateForm.safeParse(kontakDarurat.edit.form);
|
||||||
|
if (!cek.success) {
|
||||||
|
const err = `[${cek.error.issues
|
||||||
|
.map((v) => `${v.path.join(".")}`)
|
||||||
|
.join("\n")}] required`;
|
||||||
|
return toast.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
kontakDarurat.edit.loading = true;
|
||||||
|
const response = await fetch(`/api/kesehatan/kontakdarurat/${this.id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: this.form.name,
|
||||||
|
deskripsi: this.form.deskripsi,
|
||||||
|
imageId: this.form.imageId,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const result = await response.json();
|
||||||
|
if (result.success) {
|
||||||
|
toast.success(result.message || "Kontak darurat berhasil diupdate");
|
||||||
|
await kontakDarurat.findMany.load();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
throw new Error(result.message || "Gagal update kontak darurat");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Gagal update:", error);
|
||||||
|
toast.error(error instanceof Error ? error.message : "Terjadi kesalahan saat mengupdate kontak darurat");
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
kontakDarurat.edit.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
reset() {
|
||||||
|
kontakDarurat.edit.id = "";
|
||||||
|
kontakDarurat.edit.form = { ...defaultForm };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default kontakDarurat
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
|
'use client'
|
||||||
|
import EditEditor from '@/app/admin/(dashboard)/_com/editEditor';
|
||||||
|
import infoWabahPenyakit from '@/app/admin/(dashboard)/_state/kesehatan/info-wabah-penyakit/infoWabahPenyakit';
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import ApiFetch from '@/lib/api-fetch';
|
||||||
|
import { Box, Button, Center, FileInput, Image, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
||||||
|
import { IconArrowBack, IconImageInPicture } from '@tabler/icons-react';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { toast } from 'react-toastify';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
|
||||||
|
|
||||||
|
function EditInfoWabahPenyakit() {
|
||||||
|
const infoWabahPenyakitState = useProxy(infoWabahPenyakit)
|
||||||
|
const router = useRouter();
|
||||||
|
const params = useParams()
|
||||||
|
|
||||||
|
const [previewImage, setPreviewImage] = useState<string | null>(null);
|
||||||
|
const [file, setFile] = useState<File | null>(null);
|
||||||
|
const [formData, setFormData] = useState({
|
||||||
|
name: infoWabahPenyakitState.edit.form.name || '',
|
||||||
|
deskripsiSingkat: infoWabahPenyakitState.edit.form.deskripsiSingkat || '',
|
||||||
|
deskripsi: infoWabahPenyakitState.edit.form.deskripsiLengkap || '',
|
||||||
|
imageId: infoWabahPenyakitState.edit.form.imageId || '',
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadInfoWabahPenyakit = async () => {
|
||||||
|
const id = params?.id as string;
|
||||||
|
if (!id) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await infoWabahPenyakitState.edit.load(id);
|
||||||
|
if (data) {
|
||||||
|
setFormData({
|
||||||
|
name: data.name || '',
|
||||||
|
deskripsiSingkat: data.deskripsiSingkat || '',
|
||||||
|
deskripsi: data.deskripsiLengkap || '',
|
||||||
|
imageId: data.imageId || '',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data?.image?.link) {
|
||||||
|
setPreviewImage(data.image.link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading program kesehatan:", error);
|
||||||
|
toast.error("Gagal memuat data program kesehatan");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadInfoWabahPenyakit();
|
||||||
|
}, [params?.id]);
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
try {
|
||||||
|
infoWabahPenyakitState.edit.form = {
|
||||||
|
...infoWabahPenyakitState.edit.form,
|
||||||
|
name: formData.name,
|
||||||
|
deskripsiSingkat: formData.deskripsiSingkat,
|
||||||
|
deskripsiLengkap: formData.deskripsi,
|
||||||
|
imageId: formData.imageId,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
const res = await ApiFetch.api.fileStorage.create.post({ file, name: file.name });
|
||||||
|
const uploaded = res.data?.data;
|
||||||
|
|
||||||
|
if (!uploaded?.id) {
|
||||||
|
return toast.error("Gagal upload gambar");
|
||||||
|
}
|
||||||
|
|
||||||
|
infoWabahPenyakitState.edit.form.imageId = uploaded.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
await infoWabahPenyakitState.edit.update();
|
||||||
|
toast.success("Info wabah penyakit berhasil diperbarui!");
|
||||||
|
router.push("/admin/kesehatan/info-wabah-penyakit");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating info wabah penyakit:", error);
|
||||||
|
toast.error("Gagal memuat data info wabah penyakit");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box mb={10}>
|
||||||
|
<Button variant="subtle" onClick={() => router.back()}>
|
||||||
|
<IconArrowBack color={colors['blue-button']} size={25} />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={"xs"}>
|
||||||
|
<Paper bg={colors['white-1']} p="md" w={{ base: '100%', md: '50%' }}>
|
||||||
|
<Stack gap="xs">
|
||||||
|
<Title order={3}>Edit Info Wabah Penyakit</Title>
|
||||||
|
<TextInput
|
||||||
|
value={formData.name}
|
||||||
|
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
||||||
|
label={<Text fz="sm" fw="bold">Judul</Text>}
|
||||||
|
placeholder="masukkan judul"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextInput
|
||||||
|
value={formData.deskripsiSingkat}
|
||||||
|
onChange={(e) => setFormData({ ...formData, deskripsiSingkat: e.target.value })}
|
||||||
|
label={<Text fz="sm" fw="bold">Deskripsi Singkat</Text>}
|
||||||
|
placeholder="masukkan deskripsi"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Box>
|
||||||
|
<Text fz="sm" fw="bold">Deskripsi</Text>
|
||||||
|
<EditEditor
|
||||||
|
value={formData.deskripsi}
|
||||||
|
onChange={(val) => setFormData({ ...formData, deskripsi: val })}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<FileInput
|
||||||
|
label={<Text fz="sm" fw="bold">Upload Gambar</Text>}
|
||||||
|
value={file}
|
||||||
|
onChange={async (e) => {
|
||||||
|
if (!e) return;
|
||||||
|
setFile(e);
|
||||||
|
const base64 = await e.arrayBuffer().then((buf) =>
|
||||||
|
'data:image/png;base64,' + Buffer.from(buf).toString('base64')
|
||||||
|
);
|
||||||
|
setPreviewImage(base64);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{previewImage ? (
|
||||||
|
<Image alt="" src={previewImage} w={200} h={200} />
|
||||||
|
) : (
|
||||||
|
<Center w={200} h={200} bg="gray">
|
||||||
|
<IconImageInPicture />
|
||||||
|
</Center>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button onClick={handleSubmit} bg={colors['blue-button']}>
|
||||||
|
Simpan
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Stack>
|
||||||
|
</Box >
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditInfoWabahPenyakit;
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Stack, Flex, Text, Image, Skeleton } from '@mantine/core';
|
||||||
|
import { IconArrowBack, IconX, IconEdit } from '@tabler/icons-react';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import React, { useState } from 'react';
|
||||||
|
import infoWabahPenyakit from '../../../_state/kesehatan/info-wabah-penyakit/infoWabahPenyakit';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
|
import { ModalKonfirmasiHapus } from '../../../_com/modalKonfirmasiHapus';
|
||||||
|
|
||||||
|
function DetailInfoWabahPenyakit() {
|
||||||
|
const infoWabahPenyakitState = useProxy(infoWabahPenyakit)
|
||||||
|
const [modalHapus, setModalHapus] = useState(false)
|
||||||
|
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||||
|
const router = useRouter();
|
||||||
|
const params = useParams()
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
infoWabahPenyakitState.findUnique.load(params?.id as string)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const handleHapus = () => {
|
||||||
|
if (selectedId) {
|
||||||
|
infoWabahPenyakitState.delete.byId(selectedId)
|
||||||
|
setModalHapus(false)
|
||||||
|
setSelectedId(null)
|
||||||
|
router.push("/admin/kesehatan/info-wabah-penyakit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!infoWabahPenyakitState.findUnique.data) {
|
||||||
|
return (
|
||||||
|
<Stack py={10}>
|
||||||
|
<Skeleton h={400} />
|
||||||
|
</Stack>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box mb={10}>
|
||||||
|
<Button variant="subtle" onClick={() => router.back()}>
|
||||||
|
<IconArrowBack color={colors['blue-button']} size={25} />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Paper w={{ base: "100%", md: "50%" }} bg={colors['white-1']} p={'md'}>
|
||||||
|
<Stack>
|
||||||
|
<Text fz={"xl"} fw={"bold"}>Detail Info Wabah Penyakit</Text>
|
||||||
|
{infoWabahPenyakitState.findUnique.data ? (
|
||||||
|
<Paper bg={colors['BG-trans']} p={'md'}>
|
||||||
|
<Stack gap={"xs"}>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"lg"} fw={"bold"}>Judul</Text>
|
||||||
|
<Text fz={"lg"}>{infoWabahPenyakitState.findUnique.data.name}</Text>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"lg"} fw={"bold"}>Deskripsi Singkat</Text>
|
||||||
|
<Text fz={"lg"}>{infoWabahPenyakitState.findUnique.data.deskripsiSingkat}</Text>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"lg"} fw={"bold"}>Deskripsi</Text>
|
||||||
|
<Text fz={"lg"} dangerouslySetInnerHTML={{ __html: infoWabahPenyakitState.findUnique.data.deskripsiLengkap }} />
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"lg"} fw={"bold"}>Gambar</Text>
|
||||||
|
<Image src={infoWabahPenyakitState.findUnique.data.image?.link} alt="gambar" />
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Flex gap={"xs"}>
|
||||||
|
<Button color="red" onClick={() => {
|
||||||
|
if (infoWabahPenyakitState.findUnique.data) {
|
||||||
|
setSelectedId(infoWabahPenyakitState.findUnique.data.id)
|
||||||
|
setModalHapus(true)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={infoWabahPenyakitState.delete.loading || !infoWabahPenyakitState.findUnique.data}
|
||||||
|
>
|
||||||
|
<IconX size={20} />
|
||||||
|
</Button>
|
||||||
|
<Button onClick={() => router.push(`/admin/kesehatan/info-wabah-penyakit/${infoWabahPenyakitState.findUnique.data?.id}/edit`)} color="green">
|
||||||
|
<IconEdit size={20} />
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
) : null}
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
{/* Modal Hapus */}
|
||||||
|
<ModalKonfirmasiHapus
|
||||||
|
opened={modalHapus}
|
||||||
|
onClose={() => setModalHapus(false)}
|
||||||
|
onConfirm={handleHapus}
|
||||||
|
text="Apakah anda yakin ingin menghapus info wabah penyakit ini?"
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DetailInfoWabahPenyakit;
|
||||||
@@ -1,43 +1,101 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Button, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
import ApiFetch from '@/lib/api-fetch';
|
||||||
import { IconArrowBack } from '@tabler/icons-react';
|
import { Box, Button, Center, FileInput, Image, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
||||||
|
import { IconArrowBack, IconImageInPicture } from '@tabler/icons-react';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
import { useState } from 'react';
|
||||||
|
import { toast } from 'react-toastify';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import CreateEditor from '../../../_com/createEditor';
|
||||||
|
import infoWabahPenyakit from '../../../_state/kesehatan/info-wabah-penyakit/infoWabahPenyakit';
|
||||||
|
|
||||||
function CreateInfoWabahPenyakit() {
|
function CreateInfoWabahPenyakit() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const infoWabahPenyakitState = useProxy(infoWabahPenyakit)
|
||||||
|
const [previewImage, setPreviewImage] = useState<string | null>(null);
|
||||||
|
const [file, setFile] = useState<File | null>(null);
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
// Reset state di valtio
|
||||||
|
infoWabahPenyakitState.create.form = {
|
||||||
|
name: "",
|
||||||
|
deskripsiSingkat: "",
|
||||||
|
deskripsiLengkap: "",
|
||||||
|
imageId: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Reset state lokal
|
||||||
|
setPreviewImage(null);
|
||||||
|
setFile(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (!file) {
|
||||||
|
return toast.warn("Pilih file gambar terlebih dahulu");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload gambar dulu
|
||||||
|
const res = await ApiFetch.api.fileStorage.create.post({
|
||||||
|
file,
|
||||||
|
name: file.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
const uploaded = res.data?.data;
|
||||||
|
if (!uploaded?.id) {
|
||||||
|
return toast.error("Gagal upload gambar");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simpan ID gambar ke form
|
||||||
|
infoWabahPenyakitState.create.form.imageId = uploaded.id;
|
||||||
|
|
||||||
|
// Submit data berita
|
||||||
|
await infoWabahPenyakitState.create.create();
|
||||||
|
|
||||||
|
// Reset form setelah submit
|
||||||
|
resetForm();
|
||||||
|
router.push("/admin/kesehatan/info-wabah-penyakit")
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Box mb={10}>
|
<Box mb={10}>
|
||||||
<Button variant="subtle" onClick={() => router.back()}>
|
<Button variant="subtle" onClick={() => router.back()}>
|
||||||
<IconArrowBack color={colors['blue-button']} size={25} />
|
<IconArrowBack color={colors['blue-button']} size={25} />
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Paper bg={colors['white-1']} p="md" w={{ base: '100%', md: '50%' }}>
|
<Paper bg={colors['white-1']} p="md" w={{ base: '100%', md: '50%' }}>
|
||||||
<Stack gap="xs">
|
<Stack gap="xs">
|
||||||
<Title order={3}>Create Info Wabah Penyakit</Title>
|
<Title order={3}>Create Info Wabah Penyakit</Title>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
|
value={infoWabahPenyakitState.create.form.name}
|
||||||
|
onChange={(val) => {
|
||||||
|
infoWabahPenyakitState.create.form.name = val.target.value;
|
||||||
|
}}
|
||||||
label={<Text fz="sm" fw="bold">Judul</Text>}
|
label={<Text fz="sm" fw="bold">Judul</Text>}
|
||||||
placeholder="masukkan judul"
|
placeholder="masukkan judul"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
|
value={infoWabahPenyakitState.create.form.deskripsiSingkat}
|
||||||
label={<Text fz="sm" fw="bold">Deskripsi</Text>}
|
onChange={(val) => {
|
||||||
|
infoWabahPenyakitState.create.form.deskripsiSingkat = val.target.value;
|
||||||
|
}}
|
||||||
|
label={<Text fz="sm" fw="bold">Deskripsi Singkat</Text>}
|
||||||
placeholder="masukkan deskripsi"
|
placeholder="masukkan deskripsi"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextInput
|
<Box>
|
||||||
|
<Text fz="sm" fw="bold">Deskripsi</Text>
|
||||||
label={<Text fz="sm" fw="bold">Kategori</Text>}
|
<CreateEditor
|
||||||
placeholder="masukkan kategori"
|
value={infoWabahPenyakitState.create.form.deskripsiLengkap}
|
||||||
/>
|
onChange={(val) => {
|
||||||
|
infoWabahPenyakitState.create.form.deskripsiLengkap = val;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
{/* <FileInput
|
<FileInput
|
||||||
label={<Text fz="sm" fw="bold">Upload Gambar</Text>}
|
label={<Text fz="sm" fw="bold">Upload Gambar</Text>}
|
||||||
value={file}
|
value={file}
|
||||||
onChange={async (e) => {
|
onChange={async (e) => {
|
||||||
@@ -48,25 +106,18 @@ function CreateInfoWabahPenyakit() {
|
|||||||
);
|
);
|
||||||
setPreviewImage(base64);
|
setPreviewImage(base64);
|
||||||
}}
|
}}
|
||||||
/> */}
|
/>
|
||||||
|
|
||||||
{/* {previewImage ? (
|
{previewImage ? (
|
||||||
<Image alt="" src={previewImage} w={200} h={200} />
|
<Image alt="" src={previewImage} w={200} h={200} />
|
||||||
) : (
|
) : (
|
||||||
<Center w={200} h={200} bg="gray">
|
<Center w={200} h={200} bg="gray">
|
||||||
<IconImageInPicture />
|
<IconImageInPicture />
|
||||||
</Center>
|
</Center>
|
||||||
)} */}
|
)}
|
||||||
|
|
||||||
<Box>
|
<Button onClick={handleSubmit} bg={colors['blue-button']}>
|
||||||
<Text fz="sm" fw="bold">Konten</Text>
|
Simpan
|
||||||
<KesehatanEditor
|
|
||||||
showSubmit={false}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
<Button bg={colors['blue-button']}>
|
|
||||||
Simpan Potensi
|
|
||||||
</Button>
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
'use client'
|
|
||||||
import colors from '@/con/colors';
|
|
||||||
import { Box, Button, Paper, Stack, Flex, Text, Image } from '@mantine/core';
|
|
||||||
import { IconArrowBack, IconX, IconEdit } from '@tabler/icons-react';
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
import React from 'react';
|
|
||||||
// import { ModalKonfirmasiHapus } from '../../../_com/modalKonfirmasiHapus';
|
|
||||||
|
|
||||||
function DetailInfoWabahPenyakit() {
|
|
||||||
const router = useRouter();
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<Box mb={10}>
|
|
||||||
<Button variant="subtle" onClick={() => router.back()}>
|
|
||||||
<IconArrowBack color={colors['blue-button']} size={25} />
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
<Paper w={{ base: "100%", md: "50%" }} bg={colors['white-1']} p={'md'}>
|
|
||||||
<Stack>
|
|
||||||
<Text fz={"xl"} fw={"bold"}>Detail Info Wabah/Penyakit</Text>
|
|
||||||
|
|
||||||
<Paper bg={colors['BG-trans']} p={'md'}>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Nama Info Wabah/Penyakit</Text>
|
|
||||||
<Text fz={"lg"}>Test Judul</Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Deskripsi Info Wabah/Penyakit</Text>
|
|
||||||
<Text fz={"lg"}>Test Kategori</Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Deskripsi</Text>
|
|
||||||
<Text fz={"lg"}>Test Deskripsi</Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Gambar</Text>
|
|
||||||
<Image src={"/"} alt="gambar" />
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Konten</Text>
|
|
||||||
<Text fz={"lg"} >Test Konten</Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Flex gap={"xs"}>
|
|
||||||
<Button color="red">
|
|
||||||
<IconX size={20} />
|
|
||||||
</Button>
|
|
||||||
<Button onClick={() => router.push('/admin/kesehatan/info-wabah-penyakit/edit')} color="green">
|
|
||||||
<IconEdit size={20} />
|
|
||||||
</Button>
|
|
||||||
</Flex>
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
|
|
||||||
{/* Modal Hapus
|
|
||||||
<ModalKonfirmasiHapus
|
|
||||||
opened={modalHapus}
|
|
||||||
onClose={() => setModalHapus(false)}
|
|
||||||
onConfirm={handleHapus}
|
|
||||||
text="Apakah anda yakin ingin menghapus penanganan darurat ini?"
|
|
||||||
/> */}
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default DetailInfoWabahPenyakit;
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
'use client'
|
|
||||||
import colors from '@/con/colors';
|
|
||||||
import { Box, Stack, SimpleGrid, Paper, Title, TextInput, Text, Button, Image } from '@mantine/core';
|
|
||||||
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
|
||||||
import { IconArrowBack } from '@tabler/icons-react';
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
|
|
||||||
|
|
||||||
function EditInfoWabahPenyakit() {
|
|
||||||
const router = useRouter();
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<Box mb={10}>
|
|
||||||
<Button variant="subtle" onClick={() => router.back()}>
|
|
||||||
<IconArrowBack color={colors['blue-button']} size={25} />
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<SimpleGrid cols={{ base: 1, md: 2 }}>
|
|
||||||
<Box>
|
|
||||||
<Paper bg={colors['white-1']} p={"md"}>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<Title order={3}>Edit Info Wabah/Penyakit</Title>
|
|
||||||
<TextInput
|
|
||||||
label={<Text fw={"bold"} fz={"sm"}>Nama Info Wabah/Penyakit</Text>}
|
|
||||||
placeholder='Masukkan nama Info Wabah/Penyakit'
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
label={<Text fw={"bold"} fz={"sm"}>Deskripsi Info Wabah/Penyakit</Text>}
|
|
||||||
placeholder='Masukkan deskripsi Info Wabah/Penyakit'
|
|
||||||
/>
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Deskripsi</Text>
|
|
||||||
<KesehatanEditor
|
|
||||||
showSubmit={false}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Gambar</Text>
|
|
||||||
<Image src={"/"} alt="gambar" />
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Paper bg={colors['white-1']} p={"md"}>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<Title order={4}>Preview Data Info Wabah/Penyakit</Title>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Nama Info Wabah/Penyakit</Text>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Deskripsi Info Wabah/Penyakit</Text>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Deskripsi</Text>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Gambar</Text>
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
</SimpleGrid>
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default EditInfoWabahPenyakit;
|
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Button, Image, Paper, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
import { Box, Button, Image, Paper, Skeleton, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
||||||
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
||||||
import JudulList from '../../_com/judulList';
|
import JudulList from '../../_com/judulList';
|
||||||
import HeaderSearch from '../../_com/header';
|
import HeaderSearch from '../../_com/header';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import infoWabahPenyakit from '../../_state/kesehatan/info-wabah-penyakit/infoWabahPenyakit';
|
||||||
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
|
|
||||||
function InfoWabahPenyakit() {
|
function InfoWabahPenyakit() {
|
||||||
return (
|
return (
|
||||||
@@ -20,7 +23,20 @@ function InfoWabahPenyakit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ListInfoWabahPenyakit() {
|
function ListInfoWabahPenyakit() {
|
||||||
|
const infoWabahPenyakitState = useProxy(infoWabahPenyakit)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
infoWabahPenyakitState.findMany.load()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
if (!infoWabahPenyakitState.findMany.data) {
|
||||||
|
return (
|
||||||
|
<Box py={10}>
|
||||||
|
<Skeleton h={500} />
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Box py={10}>
|
<Box py={10}>
|
||||||
<Paper bg={colors['white-1']} p={'md'}>
|
<Paper bg={colors['white-1']} p={'md'}>
|
||||||
@@ -34,27 +50,32 @@ function ListInfoWabahPenyakit() {
|
|||||||
<TableThead>
|
<TableThead>
|
||||||
<TableTr>
|
<TableTr>
|
||||||
<TableTh>Judul</TableTh>
|
<TableTh>Judul</TableTh>
|
||||||
<TableTh>Kategori</TableTh>
|
<TableTh>Deskripsi Singkat</TableTh>
|
||||||
<TableTh>Image</TableTh>
|
<TableTh>Image</TableTh>
|
||||||
<TableTh>Detail</TableTh>
|
<TableTh>Detail</TableTh>
|
||||||
</TableTr>
|
</TableTr>
|
||||||
</TableThead>
|
</TableThead>
|
||||||
<TableTbody>
|
<TableTbody>
|
||||||
<TableTr>
|
{infoWabahPenyakitState.findMany.data?.map((item) => (
|
||||||
<TableTd>
|
<TableTr key={item.id}>
|
||||||
<Box w={100}>
|
<TableTd>
|
||||||
<Text truncate="end" fz={"sm"}>Test</Text>
|
<Box w={100}>
|
||||||
</Box></TableTd>
|
<Text truncate="end" fz={"sm"}>{item.name}</Text>
|
||||||
<TableTd>Test</TableTd>
|
</Box>
|
||||||
<TableTd>
|
</TableTd>
|
||||||
<Image w={100} src={"/"} alt="image" />
|
<TableTd>
|
||||||
</TableTd>
|
<Text truncate="end" fz={"sm"}>{item.deskripsiSingkat}</Text>
|
||||||
<TableTd>
|
</TableTd>
|
||||||
<Button onClick={() => router.push('/admin/kesehatan/info-wabah-penyakit/detail')}>
|
<TableTd>
|
||||||
<IconDeviceImacCog size={25} />
|
<Image w={100} src={item.image?.link} alt="image" />
|
||||||
</Button>
|
</TableTd>
|
||||||
</TableTd>
|
<TableTd>
|
||||||
</TableTr>
|
<Button onClick={() => router.push(`/admin/kesehatan/info-wabah-penyakit/${item.id}`)}>
|
||||||
|
<IconDeviceImacCog size={25} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
</TableTr>
|
||||||
|
))}
|
||||||
</TableTbody>
|
</TableTbody>
|
||||||
</Table>
|
</Table>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
|
'use client'
|
||||||
|
import EditEditor from '@/app/admin/(dashboard)/_com/editEditor';
|
||||||
|
import kontakDarurat from '@/app/admin/(dashboard)/_state/kesehatan/kontak-darurat/kontakDarurat';
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import ApiFetch from '@/lib/api-fetch';
|
||||||
|
import { Box, Button, Center, FileInput, Image, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
||||||
|
import { IconArrowBack, IconImageInPicture } from '@tabler/icons-react';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { toast } from 'react-toastify';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function EditKontakDarurat() {
|
||||||
|
const kontakDaruratState = useProxy(kontakDarurat)
|
||||||
|
const router = useRouter();
|
||||||
|
const params = useParams()
|
||||||
|
|
||||||
|
const [previewImage, setPreviewImage] = useState<string | null>(null);
|
||||||
|
const [file, setFile] = useState<File | null>(null);
|
||||||
|
const [formData, setFormData] = useState({
|
||||||
|
name: kontakDaruratState.edit.form.name || '',
|
||||||
|
deskripsi: kontakDaruratState.edit.form.deskripsi || '',
|
||||||
|
imageId: kontakDaruratState.edit.form.imageId || '',
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadProgramKesehatan = async () => {
|
||||||
|
const id = params?.id as string;
|
||||||
|
if (!id) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await kontakDaruratState.edit.load(id);
|
||||||
|
if (data) {
|
||||||
|
setFormData({
|
||||||
|
name: data.name || '',
|
||||||
|
deskripsi: data.deskripsi || '',
|
||||||
|
imageId: data.imageId || '',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data?.image?.link) {
|
||||||
|
setPreviewImage(data.image.link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading program kesehatan:", error);
|
||||||
|
toast.error("Gagal memuat data program kesehatan");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadProgramKesehatan();
|
||||||
|
}, [params?.id]);
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
try {
|
||||||
|
kontakDaruratState.edit.form = {
|
||||||
|
...kontakDaruratState.edit.form,
|
||||||
|
name: formData.name,
|
||||||
|
deskripsi: formData.deskripsi,
|
||||||
|
imageId: formData.imageId,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
const res = await ApiFetch.api.fileStorage.create.post({ file, name: file.name });
|
||||||
|
const uploaded = res.data?.data;
|
||||||
|
|
||||||
|
if (!uploaded?.id) {
|
||||||
|
return toast.error("Gagal upload gambar");
|
||||||
|
}
|
||||||
|
|
||||||
|
kontakDaruratState.edit.form.imageId = uploaded.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
await kontakDaruratState.edit.update();
|
||||||
|
toast.success("Kontak darurat berhasil diperbarui!");
|
||||||
|
router.push("/admin/kesehatan/kontak-darurat");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating kontak darurat:", error);
|
||||||
|
toast.error("Gagal memuat data kontak darurat");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box mb={10}>
|
||||||
|
<Button variant="subtle" onClick={() => router.back()}>
|
||||||
|
<IconArrowBack color={colors['blue-button']} size={25} />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={"xs"}>
|
||||||
|
<Paper bg={colors['white-1']} p="md" w={{ base: '100%', md: '50%' }}>
|
||||||
|
<Stack gap="xs">
|
||||||
|
<Title order={3}>Edit Kontak Darurat</Title>
|
||||||
|
<TextInput
|
||||||
|
value={formData.name}
|
||||||
|
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
||||||
|
label={<Text fz="sm" fw="bold">Judul</Text>}
|
||||||
|
placeholder="masukkan judul"
|
||||||
|
/>
|
||||||
|
<Box>
|
||||||
|
<Text fz="sm" fw="bold">Deskripsi</Text>
|
||||||
|
<EditEditor
|
||||||
|
value={formData.deskripsi}
|
||||||
|
onChange={(val) => setFormData({ ...formData, deskripsi: val })}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<FileInput
|
||||||
|
label={<Text fz="sm" fw="bold">Upload Gambar</Text>}
|
||||||
|
value={file}
|
||||||
|
onChange={async (e) => {
|
||||||
|
if (!e) return;
|
||||||
|
setFile(e);
|
||||||
|
const base64 = await e.arrayBuffer().then((buf) =>
|
||||||
|
'data:image/png;base64,' + Buffer.from(buf).toString('base64')
|
||||||
|
);
|
||||||
|
setPreviewImage(base64);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{previewImage ? (
|
||||||
|
<Image alt="" src={previewImage} w={200} h={200} />
|
||||||
|
) : (
|
||||||
|
<Center w={200} h={200} bg="gray">
|
||||||
|
<IconImageInPicture />
|
||||||
|
</Center>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button onClick={handleSubmit} bg={colors['blue-button']}>
|
||||||
|
Simpan
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Stack>
|
||||||
|
</Box >
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditKontakDarurat;
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Flex, Image, Paper, Skeleton, Stack, Text } from '@mantine/core';
|
||||||
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
|
import { IconArrowBack, IconEdit, IconX } from '@tabler/icons-react';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import { ModalKonfirmasiHapus } from '../../../_com/modalKonfirmasiHapus';
|
||||||
|
import kontakDarurat from '../../../_state/kesehatan/kontak-darurat/kontakDarurat';
|
||||||
|
|
||||||
|
function DetailKontakDarurat() {
|
||||||
|
const kontakDaruratState = useProxy(kontakDarurat)
|
||||||
|
const [modalHapus, setModalHapus] = useState(false)
|
||||||
|
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||||
|
const router = useRouter();
|
||||||
|
const params = useParams()
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
kontakDaruratState.findUnique.load(params?.id as string)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const handleHapus = () => {
|
||||||
|
if (selectedId) {
|
||||||
|
kontakDaruratState.delete.byId(selectedId)
|
||||||
|
setModalHapus(false)
|
||||||
|
setSelectedId(null)
|
||||||
|
router.push("/admin/kesehatan/kontak-darurat")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!kontakDaruratState.findUnique.data) {
|
||||||
|
return (
|
||||||
|
<Stack py={10}>
|
||||||
|
<Skeleton h={400} />
|
||||||
|
</Stack>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box mb={10}>
|
||||||
|
<Button variant="subtle" onClick={() => router.back()}>
|
||||||
|
<IconArrowBack color={colors['blue-button']} size={25} />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Paper w={{ base: "100%", md: "50%" }} bg={colors['white-1']} p={'md'}>
|
||||||
|
<Stack>
|
||||||
|
<Text fz={"xl"} fw={"bold"}>Detail Kontak Darurat</Text>
|
||||||
|
{kontakDaruratState.findUnique.data ? (
|
||||||
|
<Paper bg={colors['BG-trans']} p={'md'}>
|
||||||
|
<Stack gap={"xs"}>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"lg"} fw={"bold"}>Judul</Text>
|
||||||
|
<Text fz={"lg"}>{kontakDaruratState.findUnique.data.name}</Text>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"lg"} fw={"bold"}>Deskripsi</Text>
|
||||||
|
<Text fz={"lg"} dangerouslySetInnerHTML={{ __html: kontakDaruratState.findUnique.data.deskripsi }} />
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"lg"} fw={"bold"}>Gambar</Text>
|
||||||
|
<Image src={kontakDaruratState.findUnique.data.image?.link} alt="gambar" />
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Flex gap={"xs"}>
|
||||||
|
<Button color="red" onClick={() => {
|
||||||
|
if (kontakDaruratState.findUnique.data) {
|
||||||
|
setSelectedId(kontakDaruratState.findUnique.data.id)
|
||||||
|
setModalHapus(true)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={kontakDaruratState.delete.loading || !kontakDaruratState.findUnique.data}
|
||||||
|
>
|
||||||
|
<IconX size={20} />
|
||||||
|
</Button>
|
||||||
|
<Button onClick={() => router.push(`/admin/kesehatan/kontak-darurat/${kontakDaruratState.findUnique.data?.id}/edit`)} color="green">
|
||||||
|
<IconEdit size={20} />
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
) : null}
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
{/* Modal Hapus */}
|
||||||
|
<ModalKonfirmasiHapus
|
||||||
|
opened={modalHapus}
|
||||||
|
onClose={() => setModalHapus(false)}
|
||||||
|
onConfirm={handleHapus}
|
||||||
|
text="Apakah anda yakin ingin menghapus kontak darurat ini?"
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DetailKontakDarurat;
|
||||||
@@ -1,77 +1,113 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Button, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
import { Box, Button, Center, FileInput, Image, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
||||||
import { IconArrowBack } from '@tabler/icons-react';
|
import { IconArrowBack, IconImageInPicture } from '@tabler/icons-react';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import kontakDarurat from '../../../_state/kesehatan/kontak-darurat/kontakDarurat';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { toast } from 'react-toastify';
|
||||||
|
import ApiFetch from '@/lib/api-fetch';
|
||||||
|
import CreateEditor from '../../../_com/createEditor';
|
||||||
|
|
||||||
|
|
||||||
function CreateKontakDarurat() {
|
function CreateKontakDarurat() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
return (
|
const kontakDaruratState = useProxy(kontakDarurat)
|
||||||
<Box>
|
const [previewImage, setPreviewImage] = useState<string | null>(null);
|
||||||
<Box mb={10}>
|
const [file, setFile] = useState<File | null>(null);
|
||||||
<Button variant="subtle" onClick={() => router.back()}>
|
|
||||||
<IconArrowBack color={colors['blue-button']} size={25} />
|
const resetForm = () => {
|
||||||
</Button>
|
kontakDaruratState.create.form = {
|
||||||
</Box>
|
name: "",
|
||||||
|
deskripsi: "",
|
||||||
<Paper bg={colors['white-1']} p="md" w={{ base: '100%', md: '50%' }}>
|
imageId: "",
|
||||||
<Stack gap="xs">
|
};
|
||||||
<Title order={3}>Create Kontak Darurat</Title>
|
setPreviewImage(null);
|
||||||
|
setFile(null);
|
||||||
<TextInput
|
};
|
||||||
|
|
||||||
label={<Text fz="sm" fw="bold">Judul</Text>}
|
const handleSubmit = async () => {
|
||||||
placeholder="masukkan judul"
|
if (!file) {
|
||||||
/>
|
return toast.warn("Pilih file gambar terlebih dahulu");
|
||||||
|
}
|
||||||
<TextInput
|
|
||||||
|
const res = await ApiFetch.api.fileStorage.create.post({
|
||||||
label={<Text fz="sm" fw="bold">Deskripsi</Text>}
|
file,
|
||||||
placeholder="masukkan deskripsi"
|
name: file.name,
|
||||||
/>
|
});
|
||||||
|
|
||||||
<TextInput
|
const uploaded = res.data?.data;
|
||||||
|
if (!uploaded?.id) {
|
||||||
label={<Text fz="sm" fw="bold">Kategori</Text>}
|
return toast.error("Gagal upload gambar");
|
||||||
placeholder="masukkan kategori"
|
}
|
||||||
/>
|
|
||||||
|
kontakDaruratState.create.form.imageId = uploaded.id;
|
||||||
{/* <FileInput
|
|
||||||
label={<Text fz="sm" fw="bold">Upload Gambar</Text>}
|
await kontakDaruratState.create.create();
|
||||||
value={file}
|
|
||||||
onChange={async (e) => {
|
resetForm();
|
||||||
if (!e) return;
|
router.push("/admin/kesehatan/kontak-darurat")
|
||||||
setFile(e);
|
}
|
||||||
const base64 = await e.arrayBuffer().then((buf) =>
|
return (
|
||||||
'data:image/png;base64,' + Buffer.from(buf).toString('base64')
|
<Box>
|
||||||
);
|
<Box mb={10}>
|
||||||
setPreviewImage(base64);
|
<Button variant="subtle" onClick={() => router.back()}>
|
||||||
}}
|
<IconArrowBack color={colors['blue-button']} size={25} />
|
||||||
/> */}
|
|
||||||
|
|
||||||
{/* {previewImage ? (
|
|
||||||
<Image alt="" src={previewImage} w={200} h={200} />
|
|
||||||
) : (
|
|
||||||
<Center w={200} h={200} bg="gray">
|
|
||||||
<IconImageInPicture />
|
|
||||||
</Center>
|
|
||||||
)} */}
|
|
||||||
|
|
||||||
<Box>
|
|
||||||
<Text fz="sm" fw="bold">Konten</Text>
|
|
||||||
<KesehatanEditor
|
|
||||||
showSubmit={false}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
<Button bg={colors['blue-button']}>
|
|
||||||
Simpan Potensi
|
|
||||||
</Button>
|
</Button>
|
||||||
</Stack>
|
</Box>
|
||||||
</Paper>
|
|
||||||
</Box>
|
<Paper bg={colors['white-1']} p="md" w={{ base: '100%', md: '50%' }}>
|
||||||
);
|
<Stack gap="xs">
|
||||||
|
<Title order={3}>Create Kontak Darurat</Title>
|
||||||
|
|
||||||
|
<TextInput
|
||||||
|
value={kontakDaruratState.create.form.name}
|
||||||
|
onChange={(val) => {
|
||||||
|
kontakDaruratState.create.form.name = val.target.value;
|
||||||
|
}}
|
||||||
|
label={<Text fz="sm" fw="bold">Judul</Text>}
|
||||||
|
placeholder="masukkan judul"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Box>
|
||||||
|
<Text fz="sm" fw="bold">Deskripsi</Text>
|
||||||
|
<CreateEditor
|
||||||
|
value={kontakDaruratState.create.form.deskripsi}
|
||||||
|
onChange={(val) => {
|
||||||
|
kontakDaruratState.create.form.deskripsi = val;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<FileInput
|
||||||
|
label={<Text fz="sm" fw="bold">Upload Gambar</Text>}
|
||||||
|
value={file}
|
||||||
|
onChange={async (e) => {
|
||||||
|
if (!e) return;
|
||||||
|
setFile(e);
|
||||||
|
const base64 = await e.arrayBuffer().then((buf) =>
|
||||||
|
'data:image/png;base64,' + Buffer.from(buf).toString('base64')
|
||||||
|
);
|
||||||
|
setPreviewImage(base64);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{previewImage ? (
|
||||||
|
<Image alt="" src={previewImage} w={200} h={200} />
|
||||||
|
) : (
|
||||||
|
<Center w={200} h={200} bg="gray">
|
||||||
|
<IconImageInPicture />
|
||||||
|
</Center>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button onClick={handleSubmit} bg={colors['blue-button']}>
|
||||||
|
Simpan
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CreateKontakDarurat;
|
export default CreateKontakDarurat;
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
'use client'
|
|
||||||
import colors from '@/con/colors';
|
|
||||||
import { Box, Button, Paper, Stack, Flex, Text, Image } from '@mantine/core';
|
|
||||||
import { IconArrowBack, IconX, IconEdit } from '@tabler/icons-react';
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
import React from 'react';
|
|
||||||
// import { ModalKonfirmasiHapus } from '../../../_com/modalKonfirmasiHapus';
|
|
||||||
|
|
||||||
function DetailKontakDarurat() {
|
|
||||||
const router = useRouter();
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<Box mb={10}>
|
|
||||||
<Button variant="subtle" onClick={() => router.back()}>
|
|
||||||
<IconArrowBack color={colors['blue-button']} size={25} />
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
<Paper w={{ base: "100%", md: "50%" }} bg={colors['white-1']} p={'md'}>
|
|
||||||
<Stack>
|
|
||||||
<Text fz={"xl"} fw={"bold"}>Detail Kontak Darurat</Text>
|
|
||||||
|
|
||||||
<Paper bg={colors['BG-trans']} p={'md'}>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Nama Kontak Darurat</Text>
|
|
||||||
<Text fz={"lg"}>Test Judul</Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Deskripsi Kontak Darurat</Text>
|
|
||||||
<Text fz={"lg"}>Test Kategori</Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Deskripsi</Text>
|
|
||||||
<Text fz={"lg"}>Test Deskripsi</Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Gambar</Text>
|
|
||||||
<Image src={"/"} alt="gambar" />
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Konten</Text>
|
|
||||||
<Text fz={"lg"} >Test Konten</Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Flex gap={"xs"}>
|
|
||||||
<Button color="red">
|
|
||||||
<IconX size={20} />
|
|
||||||
</Button>
|
|
||||||
<Button onClick={() => router.push('/admin/kesehatan/kontak-darurat/edit')} color="green">
|
|
||||||
<IconEdit size={20} />
|
|
||||||
</Button>
|
|
||||||
</Flex>
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
|
|
||||||
{/* Modal Hapus
|
|
||||||
<ModalKonfirmasiHapus
|
|
||||||
opened={modalHapus}
|
|
||||||
onClose={() => setModalHapus(false)}
|
|
||||||
onConfirm={handleHapus}
|
|
||||||
text="Apakah anda yakin ingin menghapus penanganan darurat ini?"
|
|
||||||
/> */}
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default DetailKontakDarurat;
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
'use client'
|
|
||||||
import colors from '@/con/colors';
|
|
||||||
import { Box, Stack, SimpleGrid, Paper, Title, TextInput, Text, Button, Image } from '@mantine/core';
|
|
||||||
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
|
||||||
import { IconArrowBack } from '@tabler/icons-react';
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
|
|
||||||
|
|
||||||
function EditKontakDarurat() {
|
|
||||||
const router = useRouter();
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<Box mb={10}>
|
|
||||||
<Button variant="subtle" onClick={() => router.back()}>
|
|
||||||
<IconArrowBack color={colors['blue-button']} size={25} />
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<SimpleGrid cols={{ base: 1, md: 2 }}>
|
|
||||||
<Box>
|
|
||||||
<Paper bg={colors['white-1']} p={"md"}>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<Title order={3}>Edit Kontak Darurat</Title>
|
|
||||||
<TextInput
|
|
||||||
label={<Text fw={"bold"} fz={"sm"}>Nama Kontak Darurat</Text>}
|
|
||||||
placeholder='Masukkan nama Kontak Darurat'
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
label={<Text fw={"bold"} fz={"sm"}>Deskripsi Kontak Darurat</Text>}
|
|
||||||
placeholder='Masukkan deskripsi Kontak Darurat'
|
|
||||||
/>
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Deskripsi</Text>
|
|
||||||
<KesehatanEditor
|
|
||||||
showSubmit={false}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Gambar</Text>
|
|
||||||
<Image src={"/"} alt="gambar" />
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Paper bg={colors['white-1']} p={"md"}>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<Title order={4}>Preview Data Kontak Darurat</Title>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Nama Kontak Darurat</Text>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Deskripsi Kontak Darurat</Text>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Deskripsi</Text>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Gambar</Text>
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
</SimpleGrid>
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default EditKontakDarurat;
|
|
||||||
@@ -1,66 +1,88 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Button, Image, Paper, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
import { Box, Button, Image, Paper, Skeleton, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
||||||
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
||||||
import JudulList from '../../_com/judulList';
|
import JudulList from '../../_com/judulList';
|
||||||
import HeaderSearch from '../../_com/header';
|
import HeaderSearch from '../../_com/header';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import kontakDarurat from '../../_state/kesehatan/kontak-darurat/kontakDarurat';
|
||||||
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
|
|
||||||
function KontakDarurat() {
|
function KontakDarurat() {
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<HeaderSearch
|
<HeaderSearch
|
||||||
title='KontakDarurat'
|
title='Kontak Darurat'
|
||||||
placeholder='pencarian'
|
placeholder='pencarian'
|
||||||
searchIcon={<IconSearch size={20} />}
|
searchIcon={<IconSearch size={20} />}
|
||||||
/>
|
/>
|
||||||
<ListKontakDarurat/>
|
<ListKontakDarurat />
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ListKontakDarurat() {
|
function ListKontakDarurat() {
|
||||||
|
const kontakDaruratState = useProxy(kontakDarurat)
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
kontakDaruratState.findMany.load()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
if (!kontakDaruratState.findMany.data) {
|
||||||
|
return (
|
||||||
|
<Box py={10}>
|
||||||
|
<Skeleton h={500} />
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box py={10}>
|
<Box py={10}>
|
||||||
<Paper bg={colors['white-1']} p={'md'}>
|
<Paper bg={colors['white-1']} p={'md'}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<JudulList
|
<JudulList
|
||||||
title='List Kontak Darurat'
|
title='List Kontak Darurat'
|
||||||
href='/admin/kesehatan/kontak-darurat/create'
|
href='/admin/kesehatan/kontak-darurat/create'
|
||||||
/>
|
/>
|
||||||
<Box style={{ overflowX: "auto" }}>
|
<Box style={{ overflowX: "auto" }}>
|
||||||
<Table striped withRowBorders withTableBorder style={{ minWidth: '700px' }}>
|
<Table striped withRowBorders withTableBorder style={{ minWidth: '700px' }}>
|
||||||
<TableThead>
|
<TableThead>
|
||||||
<TableTr>
|
<TableTr>
|
||||||
<TableTh>Judul</TableTh>
|
<TableTh>Judul</TableTh>
|
||||||
<TableTh>Kategori</TableTh>
|
<TableTh>Deskripsi</TableTh>
|
||||||
<TableTh>Image</TableTh>
|
<TableTh>Image</TableTh>
|
||||||
<TableTh>Detail</TableTh>
|
<TableTh>Detail</TableTh>
|
||||||
</TableTr>
|
</TableTr>
|
||||||
</TableThead>
|
</TableThead>
|
||||||
<TableTbody>
|
<TableTbody>
|
||||||
<TableTr>
|
{kontakDaruratState.findMany.data?.map((item) => (
|
||||||
<TableTd>
|
<TableTr key={item.id}>
|
||||||
<Box w={100}>
|
<TableTd>
|
||||||
<Text truncate="end" fz={"sm"}>Test</Text>
|
<Box w={100}>
|
||||||
</Box></TableTd>
|
<Text truncate="end" fz={"sm"}>{item.name}</Text>
|
||||||
<TableTd>Test</TableTd>
|
</Box>
|
||||||
<TableTd>
|
</TableTd>
|
||||||
<Image w={100} src={"/"} alt="image" />
|
<TableTd>
|
||||||
</TableTd>
|
<Text truncate="end" fz={"sm"} dangerouslySetInnerHTML={{ __html: item.deskripsi }} />
|
||||||
<TableTd>
|
</TableTd>
|
||||||
<Button onClick={() => router.push('/admin/kesehatan/kontak-darurat/detail')}>
|
<TableTd>
|
||||||
<IconDeviceImacCog size={25} />
|
<Image w={100} src={item.image?.link} alt="image" />
|
||||||
</Button>
|
</TableTd>
|
||||||
</TableTd>
|
<TableTd>
|
||||||
</TableTr>
|
<Button onClick={() => router.push(`/admin/kesehatan/kontak-darurat/${item.id}`)}>
|
||||||
</TableTbody>
|
<IconDeviceImacCog size={25} />
|
||||||
</Table>
|
</Button>
|
||||||
</Box>
|
</TableTd>
|
||||||
</Stack>
|
</TableTr>
|
||||||
</Paper>
|
))}
|
||||||
</Box>
|
</TableTbody>
|
||||||
|
</Table>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ function DetailProgramKesehatan() {
|
|||||||
</Box>
|
</Box>
|
||||||
<Paper w={{ base: "100%", md: "50%" }} bg={colors['white-1']} p={'md'}>
|
<Paper w={{ base: "100%", md: "50%" }} bg={colors['white-1']} p={'md'}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Text fz={"xl"} fw={"bold"}>Detail Potensi</Text>
|
<Text fz={"xl"} fw={"bold"}>Detail Program Kesehatan</Text>
|
||||||
{programKesehatanState.findUnique.data ? (
|
{programKesehatanState.findUnique.data ? (
|
||||||
<Paper bg={colors['BG-trans']} p={'md'}>
|
<Paper bg={colors['BG-trans']} p={'md'}>
|
||||||
<Stack gap={"xs"}>
|
<Stack gap={"xs"}>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ function ProgramKesehatan() {
|
|||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<HeaderSearch
|
<HeaderSearch
|
||||||
title='ProgramKesehatan'
|
title='Program Kesehatan'
|
||||||
placeholder='pencarian'
|
placeholder='pencarian'
|
||||||
searchIcon={<IconSearch size={20} />}
|
searchIcon={<IconSearch size={20} />}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ const infoWabahPenyakitDelete = async (context: Context) => {
|
|||||||
try {
|
try {
|
||||||
const filePath = path.join(infoWabahPenyakit.image.path, infoWabahPenyakit.image.name);
|
const filePath = path.join(infoWabahPenyakit.image.path, infoWabahPenyakit.image.name);
|
||||||
await fs.unlink(filePath);
|
await fs.unlink(filePath);
|
||||||
|
await prisma.fileStorage.delete({
|
||||||
|
where: { id: infoWabahPenyakit.image.id },
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Gagal hapus gambar:", err);
|
console.error("Gagal hapus gambar:", err);
|
||||||
}
|
}
|
||||||
@@ -41,7 +44,8 @@ const infoWabahPenyakitDelete = async (context: Context) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: "Info wabah penyakit berhasil dihapus",
|
success: true,
|
||||||
|
message: "Penanganan darurat dan file terkait berhasil dihapus",
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export default infoWabahPenyakitDelete;
|
export default infoWabahPenyakitDelete;
|
||||||
@@ -30,6 +30,9 @@ const kontakDaruratDelete = async (context: Context) => {
|
|||||||
try {
|
try {
|
||||||
const filePath = path.join(kontakDarurat.image.path, kontakDarurat.image.name);
|
const filePath = path.join(kontakDarurat.image.path, kontakDarurat.image.name);
|
||||||
await fs.unlink(filePath);
|
await fs.unlink(filePath);
|
||||||
|
await prisma.fileStorage.delete({
|
||||||
|
where: { id: kontakDarurat.image.id },
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error deleting image file:", error);
|
console.error("Error deleting image file:", error);
|
||||||
}
|
}
|
||||||
@@ -41,7 +44,8 @@ const kontakDaruratDelete = async (context: Context) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: "Kontak darurat berhasil dihapus",
|
success: true,
|
||||||
|
message: "Kontak darurat dan file terkait berhasil dihapus",
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export default kontakDaruratDelete;
|
export default kontakDaruratDelete;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ const KontakDarurat = new Elysia({
|
|||||||
.post("/create", kontakDaruratCreate, {
|
.post("/create", kontakDaruratCreate, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
name: t.String(),
|
name: t.String(),
|
||||||
nomor: t.String(),
|
|
||||||
deskripsi: t.String(),
|
deskripsi: t.String(),
|
||||||
imageId: t.String(),
|
imageId: t.String(),
|
||||||
})
|
})
|
||||||
@@ -32,7 +31,6 @@ const KontakDarurat = new Elysia({
|
|||||||
{
|
{
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
name: t.String(),
|
name: t.String(),
|
||||||
nomor: t.String(),
|
|
||||||
deskripsi: t.String(),
|
deskripsi: t.String(),
|
||||||
imageId: t.String(),
|
imageId: t.String(),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user