API & UI Menu Lingkungan, Submenu Program Penghijauan
This commit is contained in:
@@ -1446,7 +1446,7 @@ model JenisPengaduan {
|
|||||||
isActive Boolean @default(true)
|
isActive Boolean @default(true)
|
||||||
PengaduanMasyarakat PengaduanMasyarakat[]
|
PengaduanMasyarakat PengaduanMasyarakat[]
|
||||||
}
|
}
|
||||||
|
// ========================================= LINGKUNGAN ========================================= //
|
||||||
// ========================================= PENGELOLAAN SAMPAH ========================================= //
|
// ========================================= PENGELOLAAN SAMPAH ========================================= //
|
||||||
model PengelolaanSampah {
|
model PengelolaanSampah {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
@@ -1472,3 +1472,15 @@ model KeteranganBankSampahTerdekat {
|
|||||||
isActive Boolean @default(true)
|
isActive Boolean @default(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========================================= PORGRAM PENGHIJAUAN ========================================= //
|
||||||
|
model ProgramPenghijauan {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
name String
|
||||||
|
judul String @db.Text //deskripsi singkat
|
||||||
|
deskripsi String @db.Text //deskripsi panjang
|
||||||
|
icon String
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
deletedAt DateTime @default(now())
|
||||||
|
isActive Boolean @default(true)
|
||||||
|
}
|
||||||
@@ -6,16 +6,6 @@ import { useState, useEffect } from 'react';
|
|||||||
import 'leaflet/dist/leaflet.css';
|
import 'leaflet/dist/leaflet.css';
|
||||||
import L, { LeafletMouseEvent } from 'leaflet';
|
import L, { LeafletMouseEvent } from 'leaflet';
|
||||||
|
|
||||||
delete (L.Icon.Default.prototype as any)._getIconUrl;
|
|
||||||
L.Icon.Default.mergeOptions({
|
|
||||||
iconRetinaUrl:
|
|
||||||
'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon-2x.png',
|
|
||||||
iconUrl:
|
|
||||||
'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon.png',
|
|
||||||
shadowUrl:
|
|
||||||
'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-shadow.png',
|
|
||||||
});
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
initialPosition: { lat: number; lng: number };
|
initialPosition: { lat: number; lng: number };
|
||||||
onChange: (pos: { lat: number; lng: number }) => void;
|
onChange: (pos: { lat: number; lng: number }) => void;
|
||||||
@@ -24,6 +14,21 @@ type Props = {
|
|||||||
export default function LeafletMapEdit({ initialPosition, onChange }: Props) {
|
export default function LeafletMapEdit({ initialPosition, onChange }: Props) {
|
||||||
const [markerPos, setMarkerPos] = useState(initialPosition);
|
const [markerPos, setMarkerPos] = useState(initialPosition);
|
||||||
|
|
||||||
|
// ✅ Pastikan icon config cuma jalan di client
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
delete (L.Icon.Default.prototype as any)._getIconUrl;
|
||||||
|
L.Icon.Default.mergeOptions({
|
||||||
|
iconRetinaUrl:
|
||||||
|
'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon-2x.png',
|
||||||
|
iconUrl:
|
||||||
|
'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon.png',
|
||||||
|
shadowUrl:
|
||||||
|
'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-shadow.png',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMarkerPos(initialPosition);
|
setMarkerPos(initialPosition);
|
||||||
}, [initialPosition]);
|
}, [initialPosition]);
|
||||||
|
|||||||
@@ -4,12 +4,16 @@
|
|||||||
import { Box, rem, Select } from '@mantine/core';
|
import { Box, rem, Select } from '@mantine/core';
|
||||||
import {
|
import {
|
||||||
IconChartLine,
|
IconChartLine,
|
||||||
|
IconChristmasTreeFilled,
|
||||||
IconClipboardTextFilled,
|
IconClipboardTextFilled,
|
||||||
|
IconHomeEco,
|
||||||
IconLeaf,
|
IconLeaf,
|
||||||
IconRecycle,
|
IconRecycle,
|
||||||
IconScale,
|
IconScale,
|
||||||
|
IconShieldFilled,
|
||||||
IconTent,
|
IconTent,
|
||||||
IconTrashFilled,
|
IconTrashFilled,
|
||||||
|
IconTrendingUp,
|
||||||
IconTrophy,
|
IconTrophy,
|
||||||
IconTruckFilled,
|
IconTruckFilled,
|
||||||
} from '@tabler/icons-react';
|
} from '@tabler/icons-react';
|
||||||
@@ -25,6 +29,10 @@ const iconMap = {
|
|||||||
scale: { label: 'Scale', icon: IconScale },
|
scale: { label: 'Scale', icon: IconScale },
|
||||||
clipboard: { label: 'Clipboard', icon: IconClipboardTextFilled },
|
clipboard: { label: 'Clipboard', icon: IconClipboardTextFilled },
|
||||||
trash: { label: 'Trash', icon: IconTrashFilled },
|
trash: { label: 'Trash', icon: IconTrashFilled },
|
||||||
|
lingkunganSehat: {label: 'Lingkungan Sehat', icon: IconHomeEco},
|
||||||
|
sumberOksigen: {label: 'Sumber Oksigen', icon: IconChristmasTreeFilled},
|
||||||
|
ekonomiBerkelanjutan: {label: 'Ekonomi Berkelanjutan', icon: IconTrendingUp},
|
||||||
|
mencegahBencana: {label: 'Mencegah Bencana', icon: IconShieldFilled},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -3,12 +3,16 @@
|
|||||||
import { Box, rem, Select } from '@mantine/core';
|
import { Box, rem, Select } from '@mantine/core';
|
||||||
import {
|
import {
|
||||||
IconChartLine,
|
IconChartLine,
|
||||||
|
IconChristmasTreeFilled,
|
||||||
IconClipboardTextFilled,
|
IconClipboardTextFilled,
|
||||||
|
IconHomeEco,
|
||||||
IconLeaf,
|
IconLeaf,
|
||||||
IconRecycle,
|
IconRecycle,
|
||||||
IconScale,
|
IconScale,
|
||||||
|
IconShieldFilled,
|
||||||
IconTent,
|
IconTent,
|
||||||
IconTrashFilled,
|
IconTrashFilled,
|
||||||
|
IconTrendingUp,
|
||||||
IconTrophy,
|
IconTrophy,
|
||||||
IconTruckFilled,
|
IconTruckFilled,
|
||||||
} from '@tabler/icons-react';
|
} from '@tabler/icons-react';
|
||||||
@@ -23,6 +27,10 @@ const iconMap = {
|
|||||||
scale: { label: 'Scale', icon: IconScale },
|
scale: { label: 'Scale', icon: IconScale },
|
||||||
clipboard: { label: 'Clipboard', icon: IconClipboardTextFilled },
|
clipboard: { label: 'Clipboard', icon: IconClipboardTextFilled },
|
||||||
trash: { label: 'Trash', icon: IconTrashFilled },
|
trash: { label: 'Trash', icon: IconTrashFilled },
|
||||||
|
lingkunganSehat: {label: 'Lingkungan Sehat', icon: IconHomeEco},
|
||||||
|
sumberOksigen: {label: 'Sumber Oksigen', icon: IconChristmasTreeFilled},
|
||||||
|
ekonomiBerkelanjutan: {label: 'Ekonomi Berkelanjutan', icon: IconTrendingUp},
|
||||||
|
mencegahBencana: {label: 'Mencegah Bencana', icon: IconShieldFilled},
|
||||||
};
|
};
|
||||||
|
|
||||||
type IconKey = keyof typeof iconMap;
|
type IconKey = keyof typeof iconMap;
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
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(1, "Nama minimal 1 karakter"),
|
||||||
|
deskripsi: z.string().min(1, "Deskripsi minimal 1 karakter"),
|
||||||
|
judul: z.string().min(1, "Judul minimal 1 karakter"),
|
||||||
|
icon: z.string().min(1, "Icon minimal 1 karakter"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const defaultForm = {
|
||||||
|
name: "",
|
||||||
|
deskripsi: "",
|
||||||
|
judul: "",
|
||||||
|
icon: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
const programPenghijauanState = proxy({
|
||||||
|
create: {
|
||||||
|
form: { ...defaultForm },
|
||||||
|
loading: false,
|
||||||
|
async create() {
|
||||||
|
const cek = templateForm.safeParse(programPenghijauanState.create.form);
|
||||||
|
if (!cek.success) {
|
||||||
|
const err = `[${cek.error.issues
|
||||||
|
.map((v) => `${v.path.join(".")}`)
|
||||||
|
.join("\n")}] required`;
|
||||||
|
return toast.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
programPenghijauanState.create.loading = true;
|
||||||
|
const res = await ApiFetch.api.lingkungan.programpenghijauan["create"].post(
|
||||||
|
programPenghijauanState.create.form
|
||||||
|
);
|
||||||
|
if (res.status === 200) {
|
||||||
|
programPenghijauanState.findMany.load();
|
||||||
|
return toast.success("success create");
|
||||||
|
}
|
||||||
|
console.log(res);
|
||||||
|
return toast.error("failed create");
|
||||||
|
} catch (error) {
|
||||||
|
console.log((error as Error).message);
|
||||||
|
} finally {
|
||||||
|
programPenghijauanState.create.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
findMany: {
|
||||||
|
data: null as any[] | null,
|
||||||
|
page: 1,
|
||||||
|
totalPages: 1,
|
||||||
|
total: 0,
|
||||||
|
loading: false,
|
||||||
|
load: async (page = 1, limit = 10) => {
|
||||||
|
// Change to arrow function
|
||||||
|
programPenghijauanState.findMany.loading = true; // Use the full path to access the property
|
||||||
|
programPenghijauanState.findMany.page = page;
|
||||||
|
try {
|
||||||
|
const res = await ApiFetch.api.lingkungan.programpenghijauan["find-many"].get({
|
||||||
|
query: { page, limit },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.status === 200 && res.data?.success) {
|
||||||
|
programPenghijauanState.findMany.data = res.data.data || [];
|
||||||
|
programPenghijauanState.findMany.total = res.data.total || 0;
|
||||||
|
programPenghijauanState.findMany.totalPages = res.data.totalPages || 1;
|
||||||
|
} else {
|
||||||
|
console.error(
|
||||||
|
"Failed to load grafik berdasarkan program penghijauan:",
|
||||||
|
res.data?.message
|
||||||
|
);
|
||||||
|
programPenghijauanState.findMany.data = [];
|
||||||
|
programPenghijauanState.findMany.total = 0;
|
||||||
|
programPenghijauanState.findMany.totalPages = 1;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading grafik berdasarkan program penghijauan:", error);
|
||||||
|
programPenghijauanState.findMany.data = [];
|
||||||
|
programPenghijauanState.findMany.total = 0;
|
||||||
|
programPenghijauanState.findMany.totalPages = 1;
|
||||||
|
} finally {
|
||||||
|
programPenghijauanState.findMany.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
id: "",
|
||||||
|
form: { ...defaultForm },
|
||||||
|
loading: false,
|
||||||
|
async load(id: string) {
|
||||||
|
if (!id) {
|
||||||
|
toast.warn("ID tidak valid");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/lingkungan/programpenghijauan/${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,
|
||||||
|
judul: data.judul,
|
||||||
|
icon: data.icon,
|
||||||
|
};
|
||||||
|
return data;
|
||||||
|
} else {
|
||||||
|
throw new Error(result?.message || "Gagal mengambil data");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading program penghijauan:", error);
|
||||||
|
toast.error(
|
||||||
|
error instanceof Error ? error.message : "Gagal memuat data"
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async submit() {
|
||||||
|
const id = this.id;
|
||||||
|
if (!id) {
|
||||||
|
toast.warn("ID tidak valid");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const cek = templateForm.safeParse(this.form);
|
||||||
|
if (!cek.success) {
|
||||||
|
const err = `[${cek.error.issues
|
||||||
|
.map((v) => `${v.path.join(".")}`)
|
||||||
|
.join("\n")}] required`;
|
||||||
|
toast.error(err);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
this.loading = true;
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/lingkungan/programpenghijauan/${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!");
|
||||||
|
await programPenghijauanState.findMany.load();
|
||||||
|
return result.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error update data:", error);
|
||||||
|
toast.error("Gagal update data program penghijauan");
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
findUnique: {
|
||||||
|
data: null as Prisma.ProgramPenghijauanGetPayload<{
|
||||||
|
omit: { isActive: true };
|
||||||
|
}> | null,
|
||||||
|
async load(id: string) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/lingkungan/programpenghijauan/${id}`);
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
programPenghijauanState.findUnique.data = data.data ?? null;
|
||||||
|
} else {
|
||||||
|
console.error("Failed to fetch data", res.status, res.statusText);
|
||||||
|
programPenghijauanState.findUnique.data = null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading program penghijauan:", error);
|
||||||
|
programPenghijauanState.findUnique.data = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
delete: {
|
||||||
|
loading: false,
|
||||||
|
async byId(id: string) {
|
||||||
|
if (!id) return toast.warn("ID tidak valid");
|
||||||
|
|
||||||
|
try {
|
||||||
|
programPenghijauanState.delete.loading = true;
|
||||||
|
|
||||||
|
const response = await fetch(`/api/lingkungan/programpenghijauan/del/${id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (response.ok && result?.success) {
|
||||||
|
toast.success(result.message || "Program penghijauan berhasil dihapus");
|
||||||
|
await programPenghijauanState.findMany.load(); // refresh list
|
||||||
|
} else {
|
||||||
|
toast.error(result?.message || "Gagal menghapus program penghijauan");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Gagal delete:", error);
|
||||||
|
toast.error("Terjadi kesalahan saat menghapus program penghijauan");
|
||||||
|
} finally {
|
||||||
|
programPenghijauanState.delete.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default programPenghijauanState;
|
||||||
@@ -9,7 +9,7 @@ import { useParams, useRouter } from 'next/navigation';
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
import SelectIconProgramEdit from '../../_lib/selectIconEdit';
|
import SelectIconProgramEdit from '../../../../_com/selectIconEdit';
|
||||||
|
|
||||||
interface FormProgramKreatif {
|
interface FormProgramKreatif {
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Button, Flex, Paper, Skeleton, Stack, Text } from '@mantine/core';
|
import { Box, Button, Flex, Paper, Skeleton, Stack, Text } from '@mantine/core';
|
||||||
import { useShallowEffect } from '@mantine/hooks';
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
import { IconArrowBack, IconChartLine, IconEdit, IconLeaf, IconRecycle, IconTent, IconTrophy, IconX } from '@tabler/icons-react';
|
import { IconArrowBack, IconChartLine, IconChristmasTreeFilled, IconClipboard, IconEdit, IconHomeEco, IconLeaf, IconRecycle, IconScale, IconShieldFilled, IconTent, IconTrash, IconTrendingUp, IconTrophy, IconTruck, IconX } from '@tabler/icons-react';
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
@@ -25,6 +25,14 @@ function DetailProgramKreatifDesa() {
|
|||||||
wisata: IconTent,
|
wisata: IconTent,
|
||||||
ekonomi: IconChartLine,
|
ekonomi: IconChartLine,
|
||||||
sampah: IconRecycle,
|
sampah: IconRecycle,
|
||||||
|
truck: IconTruck,
|
||||||
|
scale: IconScale,
|
||||||
|
clipboard: IconClipboard,
|
||||||
|
trash: IconTrash,
|
||||||
|
lingkunganSehat: IconHomeEco,
|
||||||
|
sumberOksigen: IconChristmasTreeFilled,
|
||||||
|
ekonomiBerkelanjutan: IconTrendingUp,
|
||||||
|
mencegahBencana: IconShieldFilled,
|
||||||
};
|
};
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { useRouter } from 'next/navigation';
|
|||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
import CreateEditor from '../../../_com/createEditor';
|
import CreateEditor from '../../../_com/createEditor';
|
||||||
import programKreatifState from '../../../_state/inovasi/program-kreatif';
|
import programKreatifState from '../../../_state/inovasi/program-kreatif';
|
||||||
import SelectIconProgram from '../_lib/selectIcon';
|
import SelectIconProgram from '../../../_com/selectIcon';
|
||||||
|
|
||||||
|
|
||||||
function CreateProgramKreatifDesa() {
|
function CreateProgramKreatifDesa() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable react-hooks/exhaustive-deps */
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
'use client'
|
'use client'
|
||||||
import pengelolaanSampahState from '@/app/admin/(dashboard)/_state/lingkungan/pengelolaan-sampah';
|
import pengelolaanSampahState from '@/app/admin/(dashboard)/_state/lingkungan/pengelolaan-sampah';
|
||||||
import SelectIconProgramEdit from '@/app/admin/(dashboard)/inovasi/program-kreatif-desa/_lib/selectIconEdit';
|
import SelectIconProgramEdit from '@/app/admin/(dashboard)/_com/selectIconEdit';
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Button, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
import { Box, Button, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
||||||
import { IconArrowBack } from '@tabler/icons-react';
|
import { IconArrowBack } from '@tabler/icons-react';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import pengelolaanSampahState from '@/app/admin/(dashboard)/_state/lingkungan/pengelolaan-sampah';
|
import pengelolaanSampahState from '@/app/admin/(dashboard)/_state/lingkungan/pengelolaan-sampah';
|
||||||
import SelectIconProgram from '@/app/admin/(dashboard)/inovasi/program-kreatif-desa/_lib/selectIcon';
|
import SelectIconProgram from '@/app/admin/(dashboard)/_com/selectIcon';
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Button, Group, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
import { Box, Button, Group, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
||||||
import { IconArrowBack } from '@tabler/icons-react';
|
import { IconArrowBack } from '@tabler/icons-react';
|
||||||
|
|||||||
@@ -0,0 +1,147 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
|
'use client'
|
||||||
|
import EditEditor from '@/app/admin/(dashboard)/_com/editEditor';
|
||||||
|
import SelectIconProgramEdit from '@/app/admin/(dashboard)/_com/selectIconEdit';
|
||||||
|
import programPenghijauanState from '@/app/admin/(dashboard)/_state/lingkungan/program-penghijauan';
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
||||||
|
import { IconArrowBack } 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';
|
||||||
|
|
||||||
|
|
||||||
|
interface FormProgramPenghijauan {
|
||||||
|
name: string;
|
||||||
|
deskripsi: string;
|
||||||
|
judul: string;
|
||||||
|
icon: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type IconKey = 'ekowisata' | 'kompetisi' | 'wisata' | 'ekonomi' | 'sampah' | 'truck' | 'scale' | 'clipboard' | 'trash' | 'lingkunganSehat' | 'sumberOksigen' | 'ekonomiBerkelanjutan' | 'mencegahBencana';
|
||||||
|
|
||||||
|
|
||||||
|
function EditProgramPenghijauan() {
|
||||||
|
const stateProgramPenghijauan = useProxy(programPenghijauanState)
|
||||||
|
const params = useParams()
|
||||||
|
const router = useRouter();
|
||||||
|
const [formData, setFormData] = useState<FormProgramPenghijauan>({
|
||||||
|
name: '',
|
||||||
|
deskripsi: '',
|
||||||
|
judul: '',
|
||||||
|
icon: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadProgramPenghijauan = async () => {
|
||||||
|
const id = params?.id as string;
|
||||||
|
if (!id) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await stateProgramPenghijauan.update.load(id);
|
||||||
|
if (data) {
|
||||||
|
// ⬇️ FIX PENTING: tambahkan ini
|
||||||
|
stateProgramPenghijauan.update.id = id;
|
||||||
|
|
||||||
|
stateProgramPenghijauan.update.form = {
|
||||||
|
name: data.name,
|
||||||
|
judul: data.judul,
|
||||||
|
deskripsi: data.deskripsi,
|
||||||
|
icon: data.icon,
|
||||||
|
};
|
||||||
|
|
||||||
|
setFormData({
|
||||||
|
name: data.name,
|
||||||
|
judul: data.judul,
|
||||||
|
deskripsi: data.deskripsi,
|
||||||
|
icon: data.icon,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading program penghijauan:", error);
|
||||||
|
toast.error("Gagal memuat data program penghijauan");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadProgramPenghijauan();
|
||||||
|
}, [params?.id]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
try {
|
||||||
|
stateProgramPenghijauan.update.form = {
|
||||||
|
...stateProgramPenghijauan.update.form,
|
||||||
|
name: formData.name.trim(),
|
||||||
|
deskripsi: formData.deskripsi.trim(),
|
||||||
|
judul: formData.judul.trim(),
|
||||||
|
icon: formData.icon.trim(),
|
||||||
|
}
|
||||||
|
await stateProgramPenghijauan.update.submit();
|
||||||
|
router.push("/admin/lingkungan/program-penghijauan");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating program penghijauan:", error);
|
||||||
|
toast.error("Gagal memuat data program penghijauan");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box mb={10}>
|
||||||
|
<Button onClick={() => router.back()} variant='subtle' color={'blue'}>
|
||||||
|
<IconArrowBack color={colors['blue-button']} size={25} />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Paper w={{ base: '100%', md: '50%' }} bg={colors['white-1']} p={'md'}>
|
||||||
|
<Stack gap={"xs"}>
|
||||||
|
<Title order={3}>Edit Program Penghijauan</Title>
|
||||||
|
<TextInput
|
||||||
|
value={formData.name}
|
||||||
|
label={<Text fz={"sm"} fw={"bold"}>Nama Program Penghijauan</Text>}
|
||||||
|
placeholder="masukkan nama program penghijauan"
|
||||||
|
onChange={(val) => {
|
||||||
|
setFormData({
|
||||||
|
...formData,
|
||||||
|
name: val.target.value
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
value={formData.judul}
|
||||||
|
label={<Text fz={"sm"} fw={"bold"}>Judul Deskripsi Program Penghijauan</Text>}
|
||||||
|
placeholder="masukkan judul deskripsi program penghijauan"
|
||||||
|
onChange={(val) => {
|
||||||
|
setFormData({
|
||||||
|
...formData,
|
||||||
|
judul: val.target.value
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"sm"} fw={"bold"}>Deskripsi</Text>
|
||||||
|
<EditEditor
|
||||||
|
value={formData.deskripsi}
|
||||||
|
onChange={(htmlContent) => {
|
||||||
|
setFormData((prev) => ({ ...prev, deskripsi: htmlContent }));
|
||||||
|
stateProgramPenghijauan.update.form.deskripsi = htmlContent;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"sm"} fw={"bold"}>Ikon Program Penghijauan</Text>
|
||||||
|
<SelectIconProgramEdit
|
||||||
|
value={formData.icon as IconKey}
|
||||||
|
onChange={(value) => {
|
||||||
|
setFormData((prev) => ({ ...prev, icon: value }));
|
||||||
|
stateProgramPenghijauan.update.form.icon = value;
|
||||||
|
}} />
|
||||||
|
</Box>
|
||||||
|
<Button bg={colors['blue-button']} onClick={handleSubmit}>Simpan</Button>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditProgramPenghijauan;
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Flex, Paper, Skeleton, Stack, Text } from '@mantine/core';
|
||||||
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
|
import { IconArrowBack, IconChartLine, IconChristmasTreeFilled, IconClipboard, IconEdit, IconHomeEco, IconLeaf, IconRecycle, IconScale, IconShieldFilled, IconTent, IconTrash, IconTrendingUp, IconTrophy, IconTruck, IconX } from '@tabler/icons-react';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import React, { useState } from 'react';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import { ModalKonfirmasiHapus } from '../../../_com/modalKonfirmasiHapus';
|
||||||
|
import programPenghijauanState from '../../../_state/lingkungan/program-penghijauan';
|
||||||
|
|
||||||
|
// import { ModalKonfirmasiHapus } from '../../../_com/modalKonfirmasiHapus';
|
||||||
|
|
||||||
|
function DetailProgramPenghijauan() {
|
||||||
|
const [modalHapus, setModalHapus] = useState(false)
|
||||||
|
const stateProgramPenghijauan = useProxy(programPenghijauanState)
|
||||||
|
const router = useRouter()
|
||||||
|
const params = useParams()
|
||||||
|
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||||
|
|
||||||
|
const iconMap: Record<string, React.FC<any>> = {
|
||||||
|
ekowisata: IconLeaf,
|
||||||
|
kompetisi: IconTrophy,
|
||||||
|
wisata: IconTent,
|
||||||
|
ekonomi: IconChartLine,
|
||||||
|
sampah: IconRecycle,
|
||||||
|
truck: IconTruck,
|
||||||
|
scale: IconScale,
|
||||||
|
clipboard: IconClipboard,
|
||||||
|
trash: IconTrash,
|
||||||
|
lingkunganSehat: IconHomeEco,
|
||||||
|
sumberOksigen: IconChristmasTreeFilled,
|
||||||
|
ekonomiBerkelanjutan: IconTrendingUp,
|
||||||
|
mencegahBencana: IconShieldFilled,
|
||||||
|
};
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
stateProgramPenghijauan.findUnique.load(params?.id as string)
|
||||||
|
}, [params?.id])
|
||||||
|
|
||||||
|
const handleHapus = () => {
|
||||||
|
if (selectedId) {
|
||||||
|
stateProgramPenghijauan.delete.byId(selectedId)
|
||||||
|
setModalHapus(false)
|
||||||
|
setSelectedId(null)
|
||||||
|
router.push("/admin/lingkungan/program-penghijauan")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stateProgramPenghijauan.findUnique.data) {
|
||||||
|
return (
|
||||||
|
<Stack>
|
||||||
|
<Skeleton h={500} />
|
||||||
|
</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 Program Penghijauan</Text>
|
||||||
|
|
||||||
|
<Paper bg={colors['BG-trans']} p={'md'}>
|
||||||
|
<Stack gap={"xs"}>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"lg"} fw={"bold"}>Nama Program Penghijauan</Text>
|
||||||
|
<Text fz={"lg"}>{stateProgramPenghijauan.findUnique.data?.name}</Text>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"lg"} fw={"bold"}>Ikon Program Penghijauan</Text>
|
||||||
|
{iconMap[stateProgramPenghijauan.findUnique.data?.icon] && (
|
||||||
|
<Box title={stateProgramPenghijauan.findUnique.data?.icon}>
|
||||||
|
{React.createElement(iconMap[stateProgramPenghijauan.findUnique.data?.icon], { size: 24 })}
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"lg"} fw={"bold"}>Judul Deskripsi Program Penghijauan</Text>
|
||||||
|
<Text fz={"lg"}>{stateProgramPenghijauan.findUnique.data?.judul}</Text>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text fz={"lg"} fw={"bold"}>Deskripsi Program Penghijauan</Text>
|
||||||
|
<Text fz={"lg"} dangerouslySetInnerHTML={{ __html: stateProgramPenghijauan.findUnique.data?.deskripsi }}></Text>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Flex gap={"xs"} mt={10}>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
if (stateProgramPenghijauan.findUnique.data) {
|
||||||
|
setSelectedId(stateProgramPenghijauan.findUnique.data.id);
|
||||||
|
setModalHapus(true);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={stateProgramPenghijauan.delete.loading || !stateProgramPenghijauan.findUnique.data}
|
||||||
|
color={"red"}
|
||||||
|
>
|
||||||
|
<IconX size={20} />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
if (stateProgramPenghijauan.findUnique.data) {
|
||||||
|
router.push(`/admin/lingkungan/program-penghijauan/${stateProgramPenghijauan.findUnique.data.id}/edit`);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={!stateProgramPenghijauan.findUnique.data}
|
||||||
|
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 program penghijauan ini?"
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DetailProgramPenghijauan;
|
||||||
@@ -1,53 +1,71 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Button, Group, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
import { Box, Button, Group, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
||||||
import { IconArrowBack, IconImageInPicture } from '@tabler/icons-react';
|
import { IconArrowBack } from '@tabler/icons-react';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { KeamananEditor } from '../../../keamanan/_com/keamananEditor';
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import CreateEditor from '../../../_com/createEditor';
|
||||||
|
import SelectIconProgram from '../../../_com/selectIcon';
|
||||||
|
import programPenghijauanState from '../../../_state/lingkungan/program-penghijauan';
|
||||||
|
|
||||||
|
|
||||||
function CreateProgramKreatifDesa() {
|
function CreateProgramPenghijauan() {
|
||||||
|
const stateCreate = useProxy(programPenghijauanState)
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
stateCreate.create.form = {
|
||||||
|
name: "",
|
||||||
|
deskripsi: "",
|
||||||
|
judul: "",
|
||||||
|
icon: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
await stateCreate.create.create();
|
||||||
|
resetForm();
|
||||||
|
router.push("/admin/lingkungan/program-penghijauan")
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Box mb={10}>
|
<Box mb={10}>
|
||||||
<Button onClick={() => router.back()} variant='subtle' color={'blue'}>
|
<Button onClick={() => router.back()} variant='subtle' color={'blue'}>
|
||||||
<IconArrowBack color={colors['blue-button']} size={25}/>
|
<IconArrowBack color={colors['blue-button']} size={25} />
|
||||||
</Button>
|
</Button>
|
||||||
</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 gap={"xs"}>
|
<Stack gap={"xs"}>
|
||||||
<Title order={4}>Create Program Penghijauan</Title>
|
<Title order={3}>Create Program Penghijauan</Title>
|
||||||
|
<TextInput
|
||||||
|
label={<Text fz={"sm"} fw={"bold"}>Nama Program Penghijauan</Text>}
|
||||||
|
placeholder="masukkan nama program penghijauan"
|
||||||
|
onChange={(val) => stateCreate.create.form.name = val.target.value}
|
||||||
|
/>
|
||||||
<Box>
|
<Box>
|
||||||
<Text fw={"bold"} fz={"sm"}>Masukkan Image</Text>
|
<Text fz={"sm"} fw={"bold"}>Ikon Program Penghijauan</Text>
|
||||||
<IconImageInPicture size={50} />
|
<SelectIconProgram onChange={(value) => stateCreate.create.form.icon = value} />
|
||||||
</Box>
|
</Box>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={<Text fw={"bold"} fz={"sm"}>Nama Program Penghijauan</Text>}
|
onChange={(e) => stateCreate.create.form.judul = e.currentTarget.value}
|
||||||
placeholder='Masukkan nama program penghijauan'
|
label={<Text fw={"bold"} fz={"sm"}>Judul Deskripsi Program Penghijauan</Text>}
|
||||||
/>
|
placeholder='Masukkan judul deskripsi program penghijauan'
|
||||||
<TextInput
|
|
||||||
label={<Text fw={"bold"} fz={"sm"}>Deskripsi Singkat Program Penghijauan</Text>}
|
|
||||||
placeholder='Masukkan deskripsi singkat program penghijauan'
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
label={<Text fw={"bold"} fz={"sm"}>Jumlah</Text>}
|
|
||||||
placeholder='Masukkan jumlah'
|
|
||||||
/>
|
/>
|
||||||
<Box>
|
<Box>
|
||||||
<Text fw={"bold"} fz={"sm"}>Deskripsi Program Kreatif Desa</Text>
|
<Text fw={"bold"} fz={"sm"}>Deskripsi Program Penghijauan</Text>
|
||||||
<KeamananEditor
|
<CreateEditor
|
||||||
showSubmit={false}
|
value={stateCreate.create.form.deskripsi}
|
||||||
|
onChange={(htmlContent) => stateCreate.create.form.deskripsi = htmlContent}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Group>
|
<Group>
|
||||||
<Button bg={colors['blue-button']}>Submit</Button>
|
<Button bg={colors['blue-button']} onClick={handleSubmit}>Submit</Button>
|
||||||
</Group>
|
</Group>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Paper>
|
</Paper>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CreateProgramKreatifDesa;
|
export default CreateProgramPenghijauan;
|
||||||
|
|||||||
@@ -1,62 +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 DetailProgramPenghijauan() {
|
|
||||||
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 Program Penghijauan</Text>
|
|
||||||
|
|
||||||
<Paper bg={colors['BG-trans']} p={'md'}>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Nama Program Penghijauan</Text>
|
|
||||||
<Text fz={"lg"}>Test Judul</Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Gambar</Text>
|
|
||||||
<Image src={"/"} alt="gambar" />
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"lg"} fw={"bold"}>Deskripsi</Text>
|
|
||||||
<Text fz={"lg"} >Test Deskripsi</Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Flex gap={"xs"}>
|
|
||||||
<Button color="red">
|
|
||||||
<IconX size={20} />
|
|
||||||
</Button>
|
|
||||||
<Button onClick={() => router.push('/admin/lingkungan/program-penghijauan/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 potensi ini?"
|
|
||||||
/> */}
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default DetailProgramPenghijauan;
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
'use client'
|
|
||||||
import colors from '@/con/colors';
|
|
||||||
import { Box, Button, Group, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
|
||||||
import { IconArrowBack, IconImageInPicture } from '@tabler/icons-react';
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
import { KeamananEditor } from '../../../keamanan/_com/keamananEditor';
|
|
||||||
|
|
||||||
|
|
||||||
function EditProgramKreatifDesa() {
|
|
||||||
const router = useRouter();
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<Box mb={10}>
|
|
||||||
<Button onClick={() => router.back()} variant='subtle' color={'blue'}>
|
|
||||||
<IconArrowBack color={colors['blue-button']} size={25}/>
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
<Paper w={{base: '100%', md: '50%'}} bg={colors['white-1']} p={'md'}>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<Title order={4}>Edit Program Penghijauan</Title>
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Masukkan Image</Text>
|
|
||||||
<IconImageInPicture size={50} />
|
|
||||||
</Box>
|
|
||||||
<TextInput
|
|
||||||
label={<Text fw={"bold"} fz={"sm"}>Nama Program Penghijauan</Text>}
|
|
||||||
placeholder='Masukkan nama program penghijauan'
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
label={<Text fw={"bold"} fz={"sm"}>Deskripsi Singkat Program Penghijauan</Text>}
|
|
||||||
placeholder='Masukkan deskripsi singkat program penghijauan'
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
label={<Text fw={"bold"} fz={"sm"}>Jumlah</Text>}
|
|
||||||
placeholder='Masukkan jumlah'
|
|
||||||
/>
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"} fz={"sm"}>Deskripsi Program Kreatif Desa</Text>
|
|
||||||
<KeamananEditor
|
|
||||||
showSubmit={false}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
<Group>
|
|
||||||
<Button bg={colors['blue-button']}>Submit</Button>
|
|
||||||
</Group>
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default EditProgramKreatifDesa;
|
|
||||||
@@ -1,68 +1,163 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
'use client'
|
'use client'
|
||||||
import { Box, Button, Image, Paper, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
|
||||||
import HeaderSearch from '../../_com/header';
|
|
||||||
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import JudulList from '../../_com/judulList';
|
import { Box, Button, Center, Pagination, Paper, Skeleton, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
||||||
|
import {
|
||||||
|
IconChartLine, IconChristmasTreeFilled, IconClipboardTextFilled, IconDeviceImac, IconHomeEco, IconLeaf,
|
||||||
|
IconRecycle, IconScale, IconSearch, IconShieldFilled, IconTent,
|
||||||
|
IconTrashFilled,
|
||||||
|
IconTrendingUp,
|
||||||
|
IconTrophy,
|
||||||
|
IconTruckFilled
|
||||||
|
} from '@tabler/icons-react';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import HeaderSearch from '../../_com/header';
|
||||||
|
import JudulList from '../../_com/judulList';
|
||||||
|
import programPenghijauanState from '../../_state/lingkungan/program-penghijauan';
|
||||||
|
|
||||||
|
|
||||||
function ProgramPenghijauan() {
|
function ProgramPenghijauan() {
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<HeaderSearch
|
<HeaderSearch
|
||||||
title='Program Penghijauan'
|
title='Program Penghijauan'
|
||||||
placeholder='pencarian'
|
placeholder='pencarian'
|
||||||
searchIcon={<IconSearch size={20}/>}
|
searchIcon={<IconSearch size={20} />}
|
||||||
/>
|
value={search}
|
||||||
<ListManfaatPenghijauan/>
|
onChange={(e) => setSearch(e.currentTarget.value)}
|
||||||
</Box>
|
/>
|
||||||
|
<ListProgramPenghijauan search={search} />
|
||||||
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ListManfaatPenghijauan() {
|
function ListProgramPenghijauan({ search }: { search: string }) {
|
||||||
|
const listState = useProxy(programPenghijauanState)
|
||||||
|
const { data, loading, page, totalPages, load } = listState.findMany
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
return (
|
|
||||||
<Box py={10}>
|
useEffect(() => {
|
||||||
<Paper bg={colors['white-1']} p={'md'}>
|
load(page, 10)
|
||||||
<Stack>
|
}, [page])
|
||||||
<JudulList
|
|
||||||
title='List Manfaat Program Penghijauan'
|
const filteredData = (data || []).filter(item => {
|
||||||
href='/admin/lingkungan/program-penghijauan/create'
|
const keyword = search.toLowerCase();
|
||||||
/>
|
return (
|
||||||
<Box style={{ overflowX: "auto" }}>
|
item.name.toLowerCase().includes(keyword) ||
|
||||||
<Table striped withRowBorders withTableBorder style={{ minWidth: '700px' }}>
|
item.deskripsi.toLowerCase().includes(keyword) ||
|
||||||
|
item.judul.toLowerCase().includes(keyword) ||
|
||||||
|
item.icon.toLowerCase().includes(keyword)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const iconMap: Record<string, React.FC<any>> = {
|
||||||
|
ekowisata: IconLeaf,
|
||||||
|
kompetisi: IconTrophy,
|
||||||
|
wisata: IconTent,
|
||||||
|
ekonomi: IconChartLine,
|
||||||
|
sampah: IconRecycle,
|
||||||
|
truck: IconTruckFilled,
|
||||||
|
scale: IconScale,
|
||||||
|
clipboard: IconClipboardTextFilled,
|
||||||
|
trash: IconTrashFilled,
|
||||||
|
lingkunganSehat: IconHomeEco,
|
||||||
|
sumberOksigen: IconChristmasTreeFilled,
|
||||||
|
ekonomiBerkelanjutan: IconTrendingUp,
|
||||||
|
mencegahBencana: IconShieldFilled,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (loading || !data) {
|
||||||
|
return (
|
||||||
|
<Stack py={10}>
|
||||||
|
<Skeleton height={650} />
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (data.length === 0) {
|
||||||
|
return (
|
||||||
|
<Box py={10}>
|
||||||
|
<Paper p="md" >
|
||||||
|
<Stack>
|
||||||
|
<JudulList
|
||||||
|
title='List Program Penghijauan'
|
||||||
|
href='/admin/lingkungan/program-penghijauan/create'
|
||||||
|
/>
|
||||||
|
<Table striped withTableBorder withRowBorders>
|
||||||
<TableThead>
|
<TableThead>
|
||||||
<TableTr>
|
<TableTr>
|
||||||
|
<TableTh>No</TableTh>
|
||||||
<TableTh>Nama Program Penghijauan</TableTh>
|
<TableTh>Nama Program Penghijauan</TableTh>
|
||||||
<TableTh>Gambar</TableTh>
|
<TableTh>Judul Deskripsi Program Penghijauan</TableTh>
|
||||||
<TableTh>Deskripsi</TableTh>
|
<TableTh>Ikon</TableTh>
|
||||||
<TableTh>Detail</TableTh>
|
<TableTh>Detail</TableTh>
|
||||||
</TableTr>
|
</TableTr>
|
||||||
</TableThead>
|
</TableThead>
|
||||||
<TableTbody>
|
</Table>
|
||||||
<TableTr>
|
<Text ta="center">Tidak ada data program penghijauan yang tersedia</Text>
|
||||||
<TableTd>
|
</Stack>
|
||||||
<Box w={100}>
|
</Paper>
|
||||||
<Text truncate="end" fz={"sm"}>Judul</Text>
|
</Box >
|
||||||
</Box>
|
);
|
||||||
</TableTd>
|
}
|
||||||
<TableTd>
|
return (
|
||||||
<Image w={100} alt="image" />
|
<Box py={10}>
|
||||||
|
<Paper bg={colors['white-1']} p={'md'} h={{ base: 'auto', md: 650 }}>
|
||||||
|
<JudulList
|
||||||
|
title='List Program Penghijauan'
|
||||||
|
href='/admin/lingkungan/program-penghijauan/create'
|
||||||
|
/>
|
||||||
|
<Box style={{ overflowY: 'auto' }}>
|
||||||
|
<Table striped withTableBorder withRowBorders>
|
||||||
|
<TableThead>
|
||||||
|
<TableTr>
|
||||||
|
<TableTh style={{ width: '5%', textAlign: 'center' }}>No</TableTh>
|
||||||
|
<TableTh style={{ width: '20%' }}>Nama Program Penghijauan</TableTh>
|
||||||
|
<TableTh style={{ width: '35%' }}>Judul Deskripsi Program Penghijauan</TableTh>
|
||||||
|
<TableTh style={{ width: '10%' }}>Ikon</TableTh>
|
||||||
|
<TableTh style={{ width: '15%', textAlign: 'center' }}>Detail</TableTh>
|
||||||
|
</TableTr>
|
||||||
|
</TableThead>
|
||||||
|
<TableTbody>
|
||||||
|
{filteredData.map((item, index) => (
|
||||||
|
<TableTr key={item.id}>
|
||||||
|
<TableTd style={{ width: '5%', textAlign: 'center' }}>{index + 1}</TableTd>
|
||||||
|
<TableTd style={{ width: '20%', wordWrap: 'break-word' }}>{item.name}</TableTd>
|
||||||
|
<TableTd style={{ width: '35%', wordWrap: 'break-word' }} dangerouslySetInnerHTML={{ __html: item.judul }}></TableTd>
|
||||||
|
<TableTd style={{ width: '10%' }}>
|
||||||
|
{iconMap[item.icon] && (
|
||||||
|
<Box title={item.icon}>
|
||||||
|
{React.createElement(iconMap[item.icon], { size: 24 })}
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
</TableTd>
|
</TableTd>
|
||||||
<TableTd>Deskripsi</TableTd>
|
<TableTd style={{ width: '15%', textAlign: 'center' }}>
|
||||||
<TableTd>
|
<Button onClick={() => router.push(`/admin/lingkungan/program-penghijauan/${item.id}`)}>
|
||||||
<Button onClick={() => router.push('/admin/lingkungan/program-penghijauan/detail')}>
|
<IconDeviceImac size={25} />
|
||||||
<IconDeviceImacCog size={25} />
|
|
||||||
</Button>
|
</Button>
|
||||||
</TableTd>
|
</TableTd>
|
||||||
</TableTr>
|
</TableTr>
|
||||||
</TableTbody>
|
))}
|
||||||
</Table>
|
</TableTbody>
|
||||||
</Box>
|
</Table>
|
||||||
</Stack>
|
</Box>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
<Center>
|
||||||
|
<Pagination
|
||||||
|
value={page}
|
||||||
|
onChange={(newPage) => {
|
||||||
|
load(newPage, 10);
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
}}
|
||||||
|
total={totalPages}
|
||||||
|
mt="md"
|
||||||
|
mb="md"
|
||||||
|
/>
|
||||||
|
</Center>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ProgramPenghijauan;
|
export default ProgramPenghijauan;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import Elysia from "elysia";
|
import Elysia from "elysia";
|
||||||
import PengelolaanSampah from "./pengelolaan-sampah";
|
import PengelolaanSampah from "./pengelolaan-sampah";
|
||||||
|
import ProgramPenghijauan from "./program-penghijauan";
|
||||||
|
|
||||||
const Lingkungan = new Elysia({
|
const Lingkungan = new Elysia({
|
||||||
prefix: "/api/lingkungan",
|
prefix: "/api/lingkungan",
|
||||||
@@ -7,5 +8,6 @@ const Lingkungan = new Elysia({
|
|||||||
})
|
})
|
||||||
|
|
||||||
.use(PengelolaanSampah)
|
.use(PengelolaanSampah)
|
||||||
|
.use(ProgramPenghijauan)
|
||||||
|
|
||||||
export default Lingkungan;
|
export default Lingkungan;
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
type FormCreateProgramPenghijauan = {
|
||||||
|
name: string;
|
||||||
|
judul: string;
|
||||||
|
deskripsi: string;
|
||||||
|
icon: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function programPenghijauanCreate(context: Context){
|
||||||
|
const body = context.body as FormCreateProgramPenghijauan;
|
||||||
|
|
||||||
|
await prisma.programPenghijauan.create({
|
||||||
|
data: {
|
||||||
|
name: body.name,
|
||||||
|
judul: body.judul,
|
||||||
|
deskripsi: body.deskripsi,
|
||||||
|
icon: body.icon,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Success create program kreatif",
|
||||||
|
data: {
|
||||||
|
...body,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function programPenghijauanDelete(context: Context) {
|
||||||
|
const { id } = context.params as { id: string };
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "ID program penghijauan tidak ditemukan",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const deleted = await prisma.programPenghijauan.delete({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Program penghijauan berhasil dihapus",
|
||||||
|
data: deleted,
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error delete program penghijauan:", error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat menghapus program penghijauan",
|
||||||
|
error: error.message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
// Di findMany.ts
|
||||||
|
export default async function programPenghijauanFindMany(context: Context) {
|
||||||
|
const page = Number(context.query.page) || 1;
|
||||||
|
const limit = Number(context.query.limit) || 10;
|
||||||
|
const skip = (page - 1) * limit;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [data, total] = await Promise.all([
|
||||||
|
prisma.programPenghijauan.findMany({
|
||||||
|
where: { isActive: true },
|
||||||
|
skip,
|
||||||
|
take: limit,
|
||||||
|
orderBy: { createdAt: 'desc' },
|
||||||
|
}),
|
||||||
|
prisma.programPenghijauan.count({
|
||||||
|
where: { isActive: true }
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
|
const totalPages = Math.ceil(total / limit);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Success fetch program penghijauan with pagination",
|
||||||
|
data,
|
||||||
|
page,
|
||||||
|
totalPages,
|
||||||
|
total,
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Find many paginated error:", e);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Failed fetch program penghijauan with pagination",
|
||||||
|
data: [],
|
||||||
|
page: 1,
|
||||||
|
totalPages: 1,
|
||||||
|
total: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function programPenghijauanFindUnique(context: Context) {
|
||||||
|
const { id } = context.params as { id: string };
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "ID program penghijauan diperlukan",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const programPenghijauan = await prisma.programPenghijauan.findUnique({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!programPenghijauan) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Program penghijauan tidak ditemukan",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: programPenghijauan,
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error findUnique program penghijauan:", error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mengambil data program penghijauan",
|
||||||
|
error: error.message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import Elysia, { t } from "elysia";
|
||||||
|
import programPenghijauanFindMany from "./findMany";
|
||||||
|
import programPenghijauanFindUnique from "./findUnique";
|
||||||
|
import programPenghijauanCreate from "./create";
|
||||||
|
import programPenghijauanUpdate from "./updt";
|
||||||
|
import programPenghijauanDelete from "./del";
|
||||||
|
|
||||||
|
const ProgramPenghijauan = new Elysia({
|
||||||
|
prefix: "/programpenghijauan",
|
||||||
|
tags: ["Lingkungan/Program Penghijauan"],
|
||||||
|
})
|
||||||
|
.get("/find-many", programPenghijauanFindMany)
|
||||||
|
.get("/:id", async (context) => {
|
||||||
|
const response = await programPenghijauanFindUnique(context);
|
||||||
|
return response;
|
||||||
|
})
|
||||||
|
.post("/create", programPenghijauanCreate, {
|
||||||
|
body: t.Object({
|
||||||
|
name: t.String(),
|
||||||
|
judul: t.String(),
|
||||||
|
deskripsi: t.String(),
|
||||||
|
icon: t.String(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.put(
|
||||||
|
"/:id",
|
||||||
|
async (context) => {
|
||||||
|
const response = await programPenghijauanUpdate(context);
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
body: t.Object({
|
||||||
|
name: t.String(),
|
||||||
|
judul: t.String(),
|
||||||
|
deskripsi: t.String(),
|
||||||
|
icon: t.String(),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.delete("/del/:id", programPenghijauanDelete);
|
||||||
|
export default ProgramPenghijauan;
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
type FormUpdateProgramPenghijauan = {
|
||||||
|
id: string;
|
||||||
|
name?: string;
|
||||||
|
judul?: string;
|
||||||
|
deskripsi?: string;
|
||||||
|
icon?: string;
|
||||||
|
};
|
||||||
|
export default async function programPenghijauanUpdate(context: Context) {
|
||||||
|
const body = context.body as FormUpdateProgramPenghijauan;
|
||||||
|
const id = context.params?.id; // ambil dari URL param
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "ID program penghijauan wajib diisi",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const updated = await prisma.programPenghijauan.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
name: body.name,
|
||||||
|
judul: body.judul,
|
||||||
|
deskripsi: body.deskripsi,
|
||||||
|
icon: body.icon,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Program penghijauan berhasil diupdate",
|
||||||
|
data: updated,
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error update program penghijauan:", error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mengupdate program penghijauan",
|
||||||
|
error: error.message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user