QC Tampilan Admin & User, Api berfungsi
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
'use client'
|
||||
|
||||
import EditEditor from '@/app/admin/(dashboard)/_com/editEditor';
|
||||
import { IconKey } from '@/app/admin/(dashboard)/_com/iconMap';
|
||||
import SelectIconProgramEdit from '@/app/admin/(dashboard)/_com/selectIconEdit';
|
||||
import programKemiskinanState from '@/app/admin/(dashboard)/_state/ekonomi/program-kemiskinan';
|
||||
import colors from '@/con/colors';
|
||||
import {
|
||||
@@ -13,11 +15,13 @@ import {
|
||||
Text,
|
||||
TextInput,
|
||||
Title,
|
||||
Tooltip,
|
||||
} from '@mantine/core';
|
||||
import { IconArrowBack } from '@tabler/icons-react';
|
||||
import { useRouter, useParams } from 'next/navigation';
|
||||
import { useParams, useRouter } from 'next/navigation';
|
||||
import { useEffect } from 'react';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
function EditProgramKemiskinan() {
|
||||
const router = useRouter();
|
||||
@@ -33,46 +37,74 @@ function EditProgramKemiskinan() {
|
||||
stateProgram.update.form = {
|
||||
nama: data.nama || '',
|
||||
deskripsi: data.deskripsi || '',
|
||||
ikonUrl: data.ikonUrl || '',
|
||||
icon: data.icon || '',
|
||||
statistik: {
|
||||
tahun: data.statistik?.tahun?.toString() || '',
|
||||
jumlah: data.statistik?.jumlah?.toString() || '',
|
||||
},
|
||||
};
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.error("Error load data:", err);
|
||||
toast.error("Gagal mengambil data program");
|
||||
});
|
||||
}
|
||||
}, [id]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
stateProgram.update.id = id;
|
||||
await stateProgram.update.update();
|
||||
router.push('/admin/ekonomi/program-kemiskinan');
|
||||
try {
|
||||
stateProgram.update.id = id;
|
||||
await stateProgram.update.update();
|
||||
toast.success("Program berhasil diperbarui!");
|
||||
router.push('/admin/ekonomi/program-kemiskinan');
|
||||
} catch (error) {
|
||||
console.error("Error update program:", error);
|
||||
toast.error("Terjadi kesalahan saat memperbarui program");
|
||||
}
|
||||
};
|
||||
|
||||
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 Kemiskinan</Title>
|
||||
<Box px={{ base: 'sm', md: 'lg' }} py="md">
|
||||
{/* Header dengan tombol kembali */}
|
||||
<Group mb="md">
|
||||
<Tooltip label="Kembali ke halaman sebelumnya" withArrow>
|
||||
<Button
|
||||
variant="subtle"
|
||||
onClick={() => router.back()}
|
||||
p="xs"
|
||||
radius="md"
|
||||
>
|
||||
<IconArrowBack color={colors['blue-button']} size={24} />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Title order={4} ml="sm" c="dark">
|
||||
Edit Program Kemiskinan
|
||||
</Title>
|
||||
</Group>
|
||||
|
||||
<Paper
|
||||
w={{ base: '100%', md: '50%' }}
|
||||
bg={colors['white-1']}
|
||||
p="lg"
|
||||
radius="md"
|
||||
shadow="sm"
|
||||
style={{ border: '1px solid #e0e0e0' }}
|
||||
>
|
||||
<Stack gap="md">
|
||||
<TextInput
|
||||
value={stateProgram.update.form.nama}
|
||||
onChange={(e) => {
|
||||
stateProgram.update.form.nama = e.target.value;
|
||||
}}
|
||||
label={<Text fw="bold" fz="md">Judul Program</Text>}
|
||||
label={<Text fw="bold" fz="sm">Judul Program</Text>}
|
||||
placeholder="Masukkan judul program"
|
||||
required
|
||||
/>
|
||||
|
||||
<Box>
|
||||
<Text fw="bold" fz="md">Deskripsi</Text>
|
||||
<Text fw="bold" fz="sm" mb={6}>
|
||||
Deskripsi
|
||||
</Text>
|
||||
<EditEditor
|
||||
value={stateProgram.update.form.deskripsi}
|
||||
onChange={(val) => {
|
||||
@@ -81,40 +113,58 @@ function EditProgramKemiskinan() {
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<TextInput
|
||||
value={stateProgram.update.form.ikonUrl}
|
||||
onChange={(e) => {
|
||||
stateProgram.update.form.ikonUrl = e.target.value;
|
||||
}}
|
||||
label={<Text fw="bold" fz="md">Ikon URL</Text>}
|
||||
placeholder="Masukkan ikon url"
|
||||
/>
|
||||
<Box>
|
||||
<Text fw="bold" fz="sm" mb={6}>
|
||||
Ikon Program Kreatif Desa
|
||||
</Text>
|
||||
<SelectIconProgramEdit
|
||||
value={stateProgram.update.form.icon as IconKey}
|
||||
onChange={(value) => {
|
||||
stateProgram.update.form.icon = value;
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Text fw="bold" fz="md">Statistik Jumlah Masyarakat Miskin</Text>
|
||||
<Box>
|
||||
<Text fw="bold" fz="sm" mb={6}>
|
||||
Statistik Jumlah Masyarakat Miskin
|
||||
</Text>
|
||||
<TextInput
|
||||
type="number"
|
||||
value={stateProgram.update.form.statistik.jumlah}
|
||||
onChange={(e) => {
|
||||
stateProgram.update.form.statistik.jumlah = e.target.value;
|
||||
}}
|
||||
label="Jumlah Masyarakat Miskin"
|
||||
placeholder="Masukkan jumlah masyarakat miskin"
|
||||
required
|
||||
/>
|
||||
|
||||
<TextInput
|
||||
type="number"
|
||||
value={stateProgram.update.form.statistik.jumlah}
|
||||
onChange={(e) => {
|
||||
stateProgram.update.form.statistik.jumlah = e.target.value;
|
||||
}}
|
||||
label={<Text fw="bold" fz="md">Jumlah Masyarakat Miskin</Text>}
|
||||
placeholder="Masukkan jumlah masyarakat miskin"
|
||||
/>
|
||||
<TextInput
|
||||
type="number"
|
||||
value={stateProgram.update.form.statistik.tahun}
|
||||
onChange={(e) => {
|
||||
stateProgram.update.form.statistik.tahun = e.target.value;
|
||||
}}
|
||||
label="Tahun"
|
||||
placeholder="Masukkan tahun"
|
||||
required
|
||||
mt="sm"
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<TextInput
|
||||
type="number"
|
||||
value={stateProgram.update.form.statistik.tahun}
|
||||
onChange={(e) => {
|
||||
stateProgram.update.form.statistik.tahun = e.target.value;
|
||||
}}
|
||||
label={<Text fw="bold" fz="md">Tahun</Text>}
|
||||
placeholder="Masukkan tahun"
|
||||
/>
|
||||
|
||||
<Group>
|
||||
<Button bg={colors['blue-button']} onClick={handleSubmit}>
|
||||
Submit
|
||||
<Group justify="right" mt="md">
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
radius="md"
|
||||
size="md"
|
||||
style={{
|
||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||
color: '#fff',
|
||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
|
||||
@@ -1,115 +1,169 @@
|
||||
'use client'
|
||||
|
||||
import colors from '@/con/colors';
|
||||
import { Box, Button, Flex, Paper, Skeleton, Stack, Text } from '@mantine/core';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Group,
|
||||
Paper,
|
||||
Skeleton,
|
||||
Stack,
|
||||
Text,
|
||||
Tooltip,
|
||||
} from '@mantine/core';
|
||||
import { useShallowEffect } from '@mantine/hooks';
|
||||
import { IconArrowBack, IconEdit, IconX } from '@tabler/icons-react';
|
||||
import { IconArrowBack, IconEdit, IconTrash } 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 programKemiskinanState from '../../../_state/ekonomi/program-kemiskinan';
|
||||
|
||||
import { IconKey, IconMapper } from '../../../_com/iconMap';
|
||||
|
||||
function DetailProgramKemiskinan() {
|
||||
const programState = useProxy(programKemiskinanState)
|
||||
const [modalHapus, setModalHapus] = useState(false)
|
||||
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||
const programState = useProxy(programKemiskinanState);
|
||||
const [modalHapus, setModalHapus] = useState(false);
|
||||
const [selectedId, setSelectedId] = useState<string | null>(null);
|
||||
const router = useRouter();
|
||||
const params = useParams()
|
||||
const params = useParams();
|
||||
|
||||
useShallowEffect(() => {
|
||||
programState.findUnique.load(params?.id as string)
|
||||
}, [])
|
||||
programState.findUnique.load(params?.id as string);
|
||||
}, []);
|
||||
|
||||
const handleHapus = () => {
|
||||
if (selectedId) {
|
||||
programState.delete.delete(selectedId)
|
||||
setModalHapus(false)
|
||||
setSelectedId(null)
|
||||
router.push("/admin/ekonomi/program-kemiskinan")
|
||||
programState.delete.delete(selectedId);
|
||||
setModalHapus(false);
|
||||
setSelectedId(null);
|
||||
router.push("/admin/ekonomi/program-kemiskinan");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (!programState.findUnique.data) {
|
||||
return (
|
||||
<Stack py={10}>
|
||||
<Skeleton h={40} />
|
||||
<Skeleton height={500} radius="md" />
|
||||
</Stack>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const data = programState.findUnique.data;
|
||||
|
||||
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 Kemiskinan</Text>
|
||||
<Paper bg={colors['BG-trans']} p={'md'}>
|
||||
<Stack gap={"xs"}>
|
||||
<Box py={10}>
|
||||
{/* Tombol Kembali */}
|
||||
<Button
|
||||
variant="subtle"
|
||||
onClick={() => router.back()}
|
||||
leftSection={<IconArrowBack size={24} color={colors['blue-button']} />}
|
||||
mb={15}
|
||||
>
|
||||
Kembali
|
||||
</Button>
|
||||
|
||||
{/* Card utama */}
|
||||
<Paper
|
||||
withBorder
|
||||
w={{ base: "100%", md: "60%" }}
|
||||
bg={colors['white-1']}
|
||||
p="lg"
|
||||
radius="md"
|
||||
shadow="sm"
|
||||
>
|
||||
<Stack gap="md">
|
||||
<Text fz="2xl" fw="bold" c={colors['blue-button']}>
|
||||
Detail Program Kemiskinan
|
||||
</Text>
|
||||
|
||||
{/* Detail Content */}
|
||||
<Paper bg="#ECEEF8" p="md" radius="md" shadow="xs">
|
||||
<Stack gap="sm">
|
||||
<Box>
|
||||
<Text fw={"bold"}>Judul Program</Text>
|
||||
<Text fz={"md"}>{programState.findUnique.data?.nama}</Text>
|
||||
<Text fz="lg" fw="bold">Judul Program</Text>
|
||||
<Text fz="md" c="dimmed">{data.nama || '-'}</Text>
|
||||
</Box>
|
||||
|
||||
<Box>
|
||||
<Text fw={"bold"}>Deskripsi Singkat</Text>
|
||||
<Text fz={"md"} dangerouslySetInnerHTML={{ __html: programState.findUnique.data?.deskripsi }}></Text>
|
||||
<Text fz="lg" fw="bold">Deskripsi Singkat</Text>
|
||||
<Text
|
||||
fz="md"
|
||||
c="dimmed"
|
||||
dangerouslySetInnerHTML={{ __html: data.deskripsi || '-' }}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box>
|
||||
<Text fw={"bold"}>Ikon URL</Text>
|
||||
<Text fz={"md"}>{programState.findUnique.data?.ikonUrl}</Text>
|
||||
<Text fz="lg" fw="bold">Ikon Program</Text>
|
||||
{data.icon ? (
|
||||
<IconMapper
|
||||
name={data.icon as IconKey}
|
||||
size={32}
|
||||
color={colors['blue-button']}
|
||||
/>
|
||||
) : (
|
||||
<Text fz="sm" c="dimmed">Tidak ada ikon</Text>
|
||||
)}
|
||||
</Box>
|
||||
<Text fw={"bold"}>Statistik Jumlah Masyarakat Miskin</Text>
|
||||
|
||||
<Box>
|
||||
<Text fw={"bold"}>Jumlah Masyarakat Miskin</Text>
|
||||
<Text fz={"md"}>{programState.findUnique.data?.statistik?.jumlah}</Text>
|
||||
<Text fz="lg" fw="bold">Statistik Jumlah Masyarakat Miskin</Text>
|
||||
<Stack gap="xs" pl="sm">
|
||||
<Box>
|
||||
<Text fw="bold">Jumlah</Text>
|
||||
<Text fz="md" c="dimmed">{data.statistik?.jumlah || '-'}</Text>
|
||||
</Box>
|
||||
<Box>
|
||||
<Text fw="bold">Tahun</Text>
|
||||
<Text fz="md" c="dimmed">{data.statistik?.tahun || '-'}</Text>
|
||||
</Box>
|
||||
</Stack>
|
||||
</Box>
|
||||
<Box>
|
||||
<Text fw={"bold"}>Tahun</Text>
|
||||
<Text fz={"md"}>{programState.findUnique.data?.statistik?.tahun}</Text>
|
||||
</Box>
|
||||
<Flex gap={"xs"} mt={10}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (programState.findUnique.data) {
|
||||
setSelectedId(programState.findUnique.data.id);
|
||||
|
||||
{/* Action Buttons */}
|
||||
<Group gap="sm" mt="sm">
|
||||
<Tooltip label="Hapus Program" withArrow position="top">
|
||||
<Button
|
||||
color="red"
|
||||
onClick={() => {
|
||||
setSelectedId(data.id);
|
||||
setModalHapus(true);
|
||||
}
|
||||
}}
|
||||
disabled={programState.delete.loading || !programState.findUnique.data}
|
||||
color={"red"}
|
||||
>
|
||||
<IconX size={20} />
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (programState.findUnique.data) {
|
||||
router.push(`/admin/ekonomi/program-kemiskinan/${programState.findUnique.data.id}/edit`);
|
||||
}
|
||||
}}
|
||||
disabled={!programState.findUnique.data}
|
||||
color={"green"}
|
||||
>
|
||||
<IconEdit size={20} />
|
||||
</Button>
|
||||
</Flex>
|
||||
}}
|
||||
variant="light"
|
||||
radius="md"
|
||||
size="md"
|
||||
disabled={programState.delete.loading}
|
||||
>
|
||||
<IconTrash size={20} />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip label="Edit Program" withArrow position="top">
|
||||
<Button
|
||||
color="green"
|
||||
onClick={() => router.push(`/admin/ekonomi/program-kemiskinan/${data.id}/edit`)}
|
||||
variant="light"
|
||||
radius="md"
|
||||
size="md"
|
||||
>
|
||||
<IconEdit size={20} />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Paper>
|
||||
</Stack>
|
||||
</Paper>
|
||||
|
||||
{/* Modal Hapus */}
|
||||
{/* Modal Konfirmasi Hapus */}
|
||||
<ModalKonfirmasiHapus
|
||||
opened={modalHapus}
|
||||
onClose={() => setModalHapus(false)}
|
||||
onConfirm={handleHapus}
|
||||
text="Apakah anda yakin ingin menghapus program kemiskinan ini?"
|
||||
text="Apakah Anda yakin ingin menghapus program kemiskinan ini?"
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default DetailProgramKemiskinan;
|
||||
|
||||
|
||||
@@ -1,34 +1,50 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
'use client'
|
||||
'use client';
|
||||
|
||||
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,
|
||||
Tooltip,
|
||||
} from '@mantine/core';
|
||||
import { IconArrowBack } from '@tabler/icons-react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
import programKemiskinanState from '../../../_state/ekonomi/program-kemiskinan';
|
||||
import CreateEditor from '../../../_com/createEditor';
|
||||
import SelectIconProgram from '../../../_com/selectIcon';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
function CreateProgramKemiskinan() {
|
||||
const programState = useProxy(programKemiskinanState)
|
||||
const programState = useProxy(programKemiskinanState);
|
||||
const router = useRouter();
|
||||
const [lineChart, setLineChart] = useState<any[]>([]);
|
||||
|
||||
const resetForm = () => {
|
||||
programState.create.form = {
|
||||
nama: "",
|
||||
deskripsi: "",
|
||||
ikonUrl: "",
|
||||
nama: '',
|
||||
deskripsi: '',
|
||||
icon: '',
|
||||
statistik: {
|
||||
tahun: "",
|
||||
jumlah: "",
|
||||
}
|
||||
}
|
||||
}
|
||||
tahun: '',
|
||||
jumlah: '',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!programState.create.form.nama || !programState.create.form.deskripsi) {
|
||||
return toast.warn('Judul dan deskripsi wajib diisi');
|
||||
}
|
||||
|
||||
const id = await programState.create.create();
|
||||
if (id) {
|
||||
const idStr = String(id);
|
||||
@@ -36,68 +52,116 @@ function CreateProgramKemiskinan() {
|
||||
if (programState.findUnique.data) {
|
||||
setLineChart([programState.findUnique.data]);
|
||||
}
|
||||
toast.success('Program berhasil ditambahkan');
|
||||
} else {
|
||||
toast.error('Gagal menambahkan program, coba lagi');
|
||||
}
|
||||
resetForm()
|
||||
router.push("/admin/ekonomi/program-kemiskinan")
|
||||
}
|
||||
|
||||
resetForm();
|
||||
router.push('/admin/ekonomi/program-kemiskinan');
|
||||
};
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Box mb={10}>
|
||||
<Button onClick={() => router.back()} variant='subtle' color={'blue'}>
|
||||
<IconArrowBack color={colors['blue-button']} size={25} />
|
||||
</Button>
|
||||
</Box>
|
||||
<Box px={{ base: 'sm', md: 'lg' }} py="md">
|
||||
{/* Header dengan tombol back */}
|
||||
<Group mb="md">
|
||||
<Tooltip label="Kembali ke halaman sebelumnya" withArrow>
|
||||
<Button
|
||||
variant="subtle"
|
||||
onClick={() => router.back()}
|
||||
p="xs"
|
||||
radius="md"
|
||||
>
|
||||
<IconArrowBack color={colors['blue-button']} size={24} />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Title order={4} ml="sm" c="dark">
|
||||
Tambah Program Kemiskinan
|
||||
</Title>
|
||||
</Group>
|
||||
|
||||
<Paper w={{ base: '100%', md: '50%' }} bg={colors['white-1']} p={'md'}>
|
||||
<Stack gap={"xs"}>
|
||||
<Title order={4}>Create Program Kemiskinan</Title>
|
||||
<Paper
|
||||
w={{ base: '100%', md: '50%' }}
|
||||
bg={colors['white-1']}
|
||||
p="lg"
|
||||
radius="md"
|
||||
shadow="sm"
|
||||
style={{ border: '1px solid #e0e0e0' }}
|
||||
>
|
||||
<Stack gap="md">
|
||||
{/* Judul Program */}
|
||||
<TextInput
|
||||
label="Judul Program"
|
||||
placeholder="Masukkan judul program"
|
||||
value={programState.create.form.nama}
|
||||
onChange={(val) => {
|
||||
programState.create.form.nama = val.target.value;
|
||||
}}
|
||||
label={<Text fw={"bold"} fz={"md"}>Judul Program</Text>}
|
||||
placeholder='Masukkan judul program'
|
||||
onChange={(val) => (programState.create.form.nama = val.target.value)}
|
||||
required
|
||||
/>
|
||||
<Box>
|
||||
<Text fw={"bold"} fz={"md"}>Deskripsi</Text>
|
||||
<CreateEditor
|
||||
value={programState.create.form.deskripsi}
|
||||
onChange={(val) => {
|
||||
programState.create.form.deskripsi = val;
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
<TextInput
|
||||
value={programState.create.form.ikonUrl}
|
||||
onChange={(val) => {
|
||||
programState.create.form.ikonUrl = val.target.value;
|
||||
}}
|
||||
label={<Text fw={"bold"} fz={"md"}>Ikon URL</Text>}
|
||||
placeholder='Masukkan ikon url'
|
||||
/>
|
||||
<Text fw={"bold"} fz={"md"}>Statistik Jumlah Masyarakat Miskin</Text>
|
||||
<TextInput
|
||||
type='number'
|
||||
value={programState.create.form.statistik.jumlah}
|
||||
onChange={(val) => {
|
||||
programState.create.form.statistik.jumlah = val.target.value;
|
||||
}}
|
||||
label={<Text fw={"bold"} fz={"md"}>Jumlah Masyarakat Miskin</Text>}
|
||||
placeholder='Masukkan jumlah masyarakat miskin'
|
||||
/>
|
||||
<TextInput
|
||||
type='number'
|
||||
value={programState.create.form.statistik.tahun}
|
||||
onChange={(val) => {
|
||||
programState.create.form.statistik.tahun = val.target.value;
|
||||
}}
|
||||
label={<Text fw={"bold"} fz={"md"}>Tahun</Text>}
|
||||
placeholder='Masukkan tahun'
|
||||
/>
|
||||
<Group>
|
||||
<Button bg={colors['blue-button']} onClick={handleSubmit}>Submit</Button>
|
||||
|
||||
{/* Ikon Program */}
|
||||
<Box>
|
||||
<Text fw="bold" fz="sm" mb={6}>
|
||||
Ikon Program Kreatif Desa
|
||||
</Text>
|
||||
<SelectIconProgram
|
||||
onChange={(value) => (programState.create.form.icon = value)}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
{/* Deskripsi */}
|
||||
<Box>
|
||||
<Text fw="bold" fz="sm" mb={6}>
|
||||
Deskripsi
|
||||
</Text>
|
||||
<CreateEditor
|
||||
value={programState.create.form.deskripsi}
|
||||
onChange={(val) => {
|
||||
programState.create.form.deskripsi = val;
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
{/* Statistik */}
|
||||
<Text fw="bold" fz="sm">
|
||||
Statistik Jumlah Masyarakat Miskin
|
||||
</Text>
|
||||
<Group grow>
|
||||
<TextInput
|
||||
type="number"
|
||||
value={programState.create.form.statistik.jumlah}
|
||||
onChange={(val) =>
|
||||
(programState.create.form.statistik.jumlah = val.target.value)
|
||||
}
|
||||
label="Jumlah"
|
||||
placeholder="Masukkan jumlah masyarakat miskin"
|
||||
required
|
||||
/>
|
||||
<TextInput
|
||||
type="number"
|
||||
value={programState.create.form.statistik.tahun}
|
||||
onChange={(val) =>
|
||||
(programState.create.form.statistik.tahun = val.target.value)
|
||||
}
|
||||
label="Tahun"
|
||||
placeholder="Masukkan tahun"
|
||||
required
|
||||
/>
|
||||
</Group>
|
||||
|
||||
{/* Tombol Submit */}
|
||||
<Group justify="right" mt="sm">
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
radius="md"
|
||||
size="md"
|
||||
style={{
|
||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||
color: '#fff',
|
||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Paper>
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
'use client'
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import colors from '@/con/colors';
|
||||
import { Box, Button, Center, Pagination, Paper, Skeleton, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text, Title } from '@mantine/core';
|
||||
import { IconDeviceImac, IconSearch } from '@tabler/icons-react';
|
||||
import HeaderSearch from '../../_com/header';
|
||||
import JudulList from '../../_com/judulList';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
import programKemiskinanState from '../../_state/ekonomi/program-kemiskinan';
|
||||
import { Box, Button, Center, Group, Pagination, Paper, Skeleton, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text, Title, Tooltip } from '@mantine/core';
|
||||
import { useShallowEffect } from '@mantine/hooks';
|
||||
import { IconDeviceImac, IconPlus, IconSearch } from '@tabler/icons-react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { CartesianGrid, Legend, Line, LineChart, Tooltip, XAxis, YAxis } from 'recharts';
|
||||
import { CartesianGrid, Legend, Line, LineChart, Tooltip as RechartTooltip, XAxis, YAxis } from 'recharts';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
import HeaderSearch from '../../_com/header';
|
||||
import programKemiskinanState from '../../_state/ekonomi/program-kemiskinan';
|
||||
|
||||
function ProgramKemiskinan() {
|
||||
const [search, setSearch] = useState("");
|
||||
@@ -18,7 +17,7 @@ function ProgramKemiskinan() {
|
||||
<Box>
|
||||
<HeaderSearch
|
||||
title='Program Kemiskinan'
|
||||
placeholder='pencarian'
|
||||
placeholder='Cari judul program atau deskripsi...'
|
||||
searchIcon={<IconSearch size={20} />}
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.currentTarget.value)}
|
||||
@@ -29,23 +28,17 @@ function ProgramKemiskinan() {
|
||||
}
|
||||
|
||||
function ListProgramKemiskinan({ search }: { search: string }) {
|
||||
const programState = useProxy(programKemiskinanState)
|
||||
const programState = useProxy(programKemiskinanState);
|
||||
const router = useRouter();
|
||||
const [lineChart, setLineChart] = useState<any[]>([]);
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
const {
|
||||
data,
|
||||
page,
|
||||
totalPages,
|
||||
loading,
|
||||
load,
|
||||
} = programState.findMany;
|
||||
const { data, page, totalPages, loading, load } = programState.findMany;
|
||||
|
||||
useShallowEffect(() => {
|
||||
setMounted(true)
|
||||
load(page, 10, search)
|
||||
}, [])
|
||||
setMounted(true);
|
||||
load(page, 10, search);
|
||||
}, [page, search]);
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
@@ -55,103 +48,118 @@ function ListProgramKemiskinan({ search }: { search: string }) {
|
||||
tahun: item.statistik?.tahun,
|
||||
jumlah: Number(item.statistik?.jumlah)
|
||||
}))
|
||||
.sort((a, b) => (a.tahun || 0) - (b.tahun || 0)); // opsional, urutkan tahun
|
||||
.sort((a, b) => (a.tahun || 0) - (b.tahun || 0));
|
||||
|
||||
setLineChart(chartData);
|
||||
|
||||
}
|
||||
}, [data])
|
||||
}, [data]);
|
||||
|
||||
const filteredData = data || []
|
||||
const filteredData = data || [];
|
||||
|
||||
if (loading || !data) {
|
||||
return (
|
||||
<Stack py={10}>
|
||||
<Skeleton h={500} />
|
||||
<Skeleton height={600} radius="md" />
|
||||
</Stack>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box py={10}>
|
||||
<Paper bg={colors['white-1']} p={'md'}>
|
||||
<JudulList
|
||||
title='List Program Kemiskinan'
|
||||
href='/admin/ekonomi/program-kemiskinan/create'
|
||||
/>
|
||||
<Table striped withTableBorder withRowBorders>
|
||||
<TableThead>
|
||||
<TableTr>
|
||||
<TableTh>Judul Program</TableTh>
|
||||
<TableTh>Deskripsi Singkat</TableTh>
|
||||
<TableTh>Jumlah Masyarakat Miskin</TableTh>
|
||||
<TableTh>Detail</TableTh>
|
||||
</TableTr>
|
||||
</TableThead>
|
||||
<TableTbody>
|
||||
{filteredData.map((item) => (
|
||||
<TableTr key={item.id}>
|
||||
<TableTd>{item.nama}</TableTd>
|
||||
<TableTd>
|
||||
<Text fz={'sm'} dangerouslySetInnerHTML={{ __html: item.deskripsi }} />
|
||||
</TableTd>
|
||||
<TableTd>{item.statistik?.jumlah}</TableTd>
|
||||
<TableTd>
|
||||
<Button onClick={() => router.push(`/admin/ekonomi/program-kemiskinan/${item.id}`)}>
|
||||
<IconDeviceImac size={20} />
|
||||
</Button>
|
||||
</TableTd>
|
||||
<Paper withBorder bg={colors['white-1']} p={'lg'} shadow="md" radius="md">
|
||||
<Group justify="space-between" mb="md">
|
||||
<Title order={4}>Daftar Program Kemiskinan</Title>
|
||||
<Tooltip label="Tambah Program Kemiskinan" withArrow>
|
||||
<Button leftSection={<IconPlus size={18} />} color="blue" variant="light" onClick={() => router.push('/admin/ekonomi/program-kemiskinan/create')}>
|
||||
Tambah Baru
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Group>
|
||||
<Box style={{ overflowX: 'auto' }}>
|
||||
<Table highlightOnHover>
|
||||
<TableThead>
|
||||
<TableTr>
|
||||
<TableTh style={{ width: '30%' }}>Judul Program</TableTh>
|
||||
<TableTh style={{ width: '40%' }}>Deskripsi Singkat</TableTh>
|
||||
<TableTh style={{ width: '20%' }}>Jumlah Masyarakat Miskin</TableTh>
|
||||
<TableTh style={{ width: '10%' }}>Aksi</TableTh>
|
||||
</TableTr>
|
||||
))}
|
||||
</TableTbody>
|
||||
</Table>
|
||||
</TableThead>
|
||||
<TableTbody>
|
||||
{filteredData.length > 0 ? (
|
||||
filteredData.map(item => (
|
||||
<TableTr key={item.id}>
|
||||
<TableTd>
|
||||
<Text fw={500} truncate lineClamp={1}>{item.nama}</Text>
|
||||
</TableTd>
|
||||
<TableTd>
|
||||
<Text fz="sm" truncate lineClamp={2} dangerouslySetInnerHTML={{ __html: item.deskripsi }} />
|
||||
</TableTd>
|
||||
<TableTd>{item.statistik?.jumlah || '-'}</TableTd>
|
||||
<TableTd>
|
||||
<Button
|
||||
variant="light"
|
||||
color="blue"
|
||||
onClick={() => router.push(`/admin/ekonomi/program-kemiskinan/${item.id}`)}
|
||||
>
|
||||
<IconDeviceImac size={20} />
|
||||
<Text ml={5}>Detail</Text>
|
||||
</Button>
|
||||
</TableTd>
|
||||
</TableTr>
|
||||
))
|
||||
) : (
|
||||
<TableTr>
|
||||
<TableTd colSpan={4}>
|
||||
<Center py={20}>
|
||||
<Text color="dimmed">Tidak ada data program kemiskinan yang cocok</Text>
|
||||
</Center>
|
||||
</TableTd>
|
||||
</TableTr>
|
||||
)}
|
||||
</TableTbody>
|
||||
</Table>
|
||||
</Box>
|
||||
</Paper>
|
||||
|
||||
{/* Pagination */}
|
||||
<Center>
|
||||
<Pagination
|
||||
value={page}
|
||||
onChange={(newPage) => {
|
||||
load(newPage, 10);
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}}
|
||||
total={totalPages}
|
||||
mt="md"
|
||||
mb="md"
|
||||
color="blue"
|
||||
radius="md"
|
||||
/>
|
||||
</Center>
|
||||
|
||||
{/* Chart */}
|
||||
<Box>
|
||||
<Paper bg={colors['white-1']} p={'md'} >
|
||||
<Stack>
|
||||
<Box >
|
||||
<Title pb={10} order={3}>Grafik Berdasarkan Responden</Title>
|
||||
{mounted && lineChart.length > 0 ? (<Box style={{ width: '100%', height: 'auto', }}>
|
||||
<Box w={"100%"} style={{ overflowX: 'auto' }}>
|
||||
<LineChart
|
||||
width={820}
|
||||
height={300}
|
||||
data={lineChart}
|
||||
>
|
||||
<CartesianGrid strokeDasharray="3 3" />
|
||||
<XAxis dataKey="tahun" />
|
||||
<YAxis />
|
||||
<Tooltip
|
||||
formatter={(value: any, name: string) => [`${value} orang`, name]}
|
||||
labelFormatter={(label: any) => `Tahun: ${label}`}
|
||||
/>
|
||||
<Legend />
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="jumlah"
|
||||
name="Jumlah per Tahun"
|
||||
stroke={colors['blue-button']}
|
||||
/>
|
||||
</LineChart>
|
||||
</Box>
|
||||
|
||||
|
||||
</Box>
|
||||
) : (
|
||||
<Text c='dimmed'>Belum ada data untuk ditampilkan dalam grafik</Text>
|
||||
)}
|
||||
<Box py={10}>
|
||||
<Paper withBorder bg={colors['white-1']} p={'lg'} shadow="md" radius="md">
|
||||
<Title pb={10} order={3}>Grafik Berdasarkan Responden</Title>
|
||||
{mounted && lineChart.length > 0 ? (
|
||||
<Box style={{ width: '100%', overflowX: 'auto' }}>
|
||||
<LineChart width={820} height={300} data={lineChart}>
|
||||
<CartesianGrid strokeDasharray="3 3" />
|
||||
<XAxis dataKey="tahun" />
|
||||
<YAxis />
|
||||
<RechartTooltip
|
||||
formatter={(value: any, name: string) => [`${value} orang`, name]}
|
||||
labelFormatter={(label: any) => `Tahun: ${label}`}
|
||||
/>
|
||||
<Legend />
|
||||
<Line type="monotone" dataKey="jumlah" name="Jumlah per Tahun" stroke={colors['blue-button']} />
|
||||
</LineChart>
|
||||
</Box>
|
||||
</Stack>
|
||||
) : (
|
||||
<Text c='dimmed'>Belum ada data untuk ditampilkan dalam grafik</Text>
|
||||
)}
|
||||
</Paper>
|
||||
<Center>
|
||||
<Pagination
|
||||
value={page}
|
||||
onChange={(newPage) => load(newPage)}
|
||||
total={totalPages}
|
||||
my={"md"}
|
||||
/>
|
||||
</Center>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user