API & UI Menu Inovasi, Submenu Layanan Online Desa: Tab 1-4

This commit is contained in:
2025-07-17 11:44:53 +08:00
parent 55433128a9
commit cde6c91cd4
22 changed files with 1573 additions and 54 deletions

View File

@@ -1,3 +1,4 @@
'use client'
import colors from '@/con/colors';
import { Box, SimpleGrid, Stack, Text } from '@mantine/core';

View File

@@ -1,26 +1,211 @@
/* eslint-disable react-hooks/exhaustive-deps */
'use client'
import CreateEditor from '@/app/admin/(dashboard)/_com/createEditor';
import layananonlineDesa from '@/app/admin/(dashboard)/_state/inovasi/layanan-online-desa';
import colors from '@/con/colors';
import { Box, Paper, Stack, Text } from '@mantine/core';
import { IconMessageCircleQuestion } from '@tabler/icons-react';
import ApiFetch from '@/lib/api-fetch';
import { Box, Button, Center, Group, Image, Modal, Paper, Select, Stack, Text, TextInput, Title } from '@mantine/core';
import { Dropzone } from '@mantine/dropzone';
import { useDisclosure } from '@mantine/hooks';
import { IconImageInPicture, IconMessageCircleQuestion, IconPhoto, IconUpload, IconX } from '@tabler/icons-react';
import { motion } from 'framer-motion';
import { useState, useEffect } from 'react';
import { toast } from 'react-toastify';
import { useProxy } from 'valtio/utils';
function PengaduanMasyarakat() {
const [opened, { open, close }] = useDisclosure(false);
const state = useProxy(layananonlineDesa);
const [previewImage, setPreviewImage] = useState<string | null>(null);
const [file, setFile] = useState<File | null>(null);
useEffect(() => {
// ✅ Panggil load data jenis layanan dari backend
if (!state.jenisPengaduan.findMany.data) {
state.jenisPengaduan.findMany.load();
}
}, []);
const resetForm = () => {
state.pengaduanMasyarakat.create.form = {
name: '',
email: '',
nomorTelepon: '',
nik: '',
judulPengaduan: '',
lokasiKejadian: '',
deskripsiPengaduan: '',
jenisPengaduanId: '',
imageId: '',
};
};
const handleSubmit = async () => {
if (!file) {
return toast.error("Silahkan pilih file gambar terlebih dahulu")
}
try {
// Upload the image first
const uploadRes = await ApiFetch.api.fileStorage.create.post({
file: file,
name: file.name
})
const uploaded = uploadRes.data?.data
if (!uploaded?.id) {
return toast.error("Gagal upload gambar")
}
// Set the image ID in the form
state.pengaduanMasyarakat.create.form.imageId = uploaded.id
// Submit the form
const success = await state.pengaduanMasyarakat.create.create()
if (success) {
resetForm()
close()
}
} catch (error) {
console.error("Error in handleSubmit:", error)
toast.error("Terjadi kesalahan saat menyimpan data")
}
};
return (
<Box>
<Stack >
<motion.div
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.8 }}
>
<Paper p={'xl'} >
<Box>
<IconMessageCircleQuestion size={50} color={colors['blue-button']} />,
</Box>
<Text fz={'h3'} fw={'bold'} c={colors['blue-button']}>Pengaduan Masyarakat</Text>
<Text fz={'lg'} c={'black'}>Sampaikan keluhan dan aspirasi Anda melalui platform digital kami</Text>
</Paper>
onClick={open}
>
<Paper p={'xl'} >
<Box>
<IconMessageCircleQuestion size={50} color={colors['blue-button']} />,
</Box>
<Text fz={'h3'} fw={'bold'} c={colors['blue-button']}>Pengaduan Masyarakat</Text>
<Text fz={'lg'} c={'black'}>Sampaikan keluhan dan aspirasi Anda melalui platform digital kami</Text>
</Paper>
</motion.div>
</Stack>
<Modal
opened={opened}
onClose={close}
radius={0}
transitionProps={{ transition: 'fade', duration: 200 }}
>
<Paper p="md" withBorder>
<Stack gap="xs">
<Title order={3}>Ajukan Administrasi Online</Title>
<TextInput
label={<Text fz="sm" fw="bold">Nama</Text>}
placeholder="masukkan nama"
onChange={(val) => (state.pengaduanMasyarakat.create.form.name = val.target.value)}
/>
<TextInput
label={<Text fz="sm" fw="bold">Email</Text>}
placeholder="masukkan email"
onChange={(val) => (state.pengaduanMasyarakat.create.form.email = val.target.value)}
/>
<TextInput
type="number"
label={<Text fz="sm" fw="bold">Nomor Telepon</Text>}
placeholder="masukkan nomor telepon"
onChange={(val) => (state.pengaduanMasyarakat.create.form.nomorTelepon = val.target.value)}
/>
<TextInput
label={<Text fz="sm" fw="bold">NIK</Text>}
placeholder="masukkan nik"
onChange={(val) => (state.pengaduanMasyarakat.create.form.nik = val.target.value)}
/>
<TextInput
label={<Text fz="sm" fw="bold">Judul Pengaduan</Text>}
placeholder="masukkan judul pengaduan"
onChange={(val) => (state.pengaduanMasyarakat.create.form.judulPengaduan = val.target.value)}
/>
<TextInput
label={<Text fz="sm" fw="bold">Lokasi Kejadian</Text>}
placeholder="masukkan lokasi kejadian"
onChange={(val) => (state.pengaduanMasyarakat.create.form.lokasiKejadian = val.target.value)}
/>
<Box>
<Text fz={"sm"} fw={"bold"}>Deskripsi</Text>
<CreateEditor
value={state.pengaduanMasyarakat.create.form.deskripsiPengaduan}
onChange={(htmlContent) => {
state.pengaduanMasyarakat.create.form.deskripsiPengaduan = htmlContent;
}}
/>
</Box>
<Select
value={state.pengaduanMasyarakat.create.form.jenisPengaduanId}
onChange={(val) => {
state.pengaduanMasyarakat.create.form.jenisPengaduanId = val ?? "";
}}
label={<Text fw={"bold"} fz={"sm"}>Jenis Pengaduan</Text>}
placeholder="Pilih kategori produk"
data={
state.jenisPengaduan.findMany.data?.map((v) => ({
value: v.id,
label: v.nama,
})) || []
}
/>
<Box>
<Text fz={"md"} fw={"bold"}>Gambar</Text>
<Box>
<Stack gap="xs">
<Dropzone
onDrop={(files) => {
const selectedFile = files[0]; // Ambil file pertama
if (selectedFile) {
setFile(selectedFile);
setPreviewImage(URL.createObjectURL(selectedFile)); // Buat preview
}
}}
onReject={() => toast.error('File tidak valid.')}
maxSize={5 * 1024 ** 2} // Maks 5MB
accept={{ 'image/*': [] }}
>
<Group justify="center" gap="xl" mih={220} style={{ pointerEvents: 'none' }}>
<Dropzone.Accept>
<IconUpload size={52} color="var(--mantine-color-blue-6)" stroke={1.5} />
</Dropzone.Accept>
<Dropzone.Reject>
<IconX size={52} color="var(--mantine-color-red-6)" stroke={1.5} />
</Dropzone.Reject>
<Dropzone.Idle>
<IconPhoto size={52} color="var(--mantine-color-dimmed)" stroke={1.5} />
</Dropzone.Idle>
<div>
<Text size="xl" inline>
Drag images here or click to select files
</Text>
<Text size="sm" c="dimmed" inline mt={7}>
Attach as many files as you like, each file should not exceed 5mb
</Text>
</div>
</Group>
</Dropzone>
{previewImage ? (
<Image alt="" src={previewImage} w={200} h={200} />
) : (
<Center w={200} h={200} bg={"gray"}>
<IconImageInPicture />
</Center>
)}
</Stack>
</Box>
</Box>
<Button bg={colors['blue-button']} onClick={handleSubmit}>
Simpan
</Button>
</Stack>
</Paper>
</Modal>
</Box>
);
}