fix tampilan admin menu inovasi, sisa menu lingkungan
This commit is contained in:
@@ -3,7 +3,17 @@
|
||||
import EditEditor from '@/app/admin/(dashboard)/_com/editEditor';
|
||||
import programKreatifState from '@/app/admin/(dashboard)/_state/inovasi/program-kreatif';
|
||||
import colors from '@/con/colors';
|
||||
import { Box, Button, 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 { useParams, useRouter } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
@@ -19,17 +29,17 @@ interface FormProgramKreatif {
|
||||
icon: string;
|
||||
}
|
||||
|
||||
|
||||
function EditProgramKreatifDesa() {
|
||||
const stateProgramKreatif = useProxy(programKreatifState)
|
||||
const params = useParams()
|
||||
const stateProgramKreatif = useProxy(programKreatifState);
|
||||
const params = useParams();
|
||||
const router = useRouter();
|
||||
|
||||
const [formData, setFormData] = useState<FormProgramKreatif>({
|
||||
name: '',
|
||||
deskripsi: '',
|
||||
slug: '',
|
||||
icon: '',
|
||||
})
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const loadProgramKreatif = async () => {
|
||||
@@ -39,16 +49,13 @@ function EditProgramKreatifDesa() {
|
||||
try {
|
||||
const data = await stateProgramKreatif.update.load(id);
|
||||
if (data) {
|
||||
// ⬇️ FIX PENTING: tambahkan ini
|
||||
stateProgramKreatif.update.id = id;
|
||||
|
||||
stateProgramKreatif.update.form = {
|
||||
name: data.name,
|
||||
slug: data.slug,
|
||||
deskripsi: data.deskripsi,
|
||||
icon: data.icon,
|
||||
};
|
||||
|
||||
setFormData({
|
||||
name: data.name,
|
||||
slug: data.slug,
|
||||
@@ -57,16 +64,14 @@ function EditProgramKreatifDesa() {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error loading program kreatif:", error);
|
||||
toast.error("Gagal memuat data program kreatif");
|
||||
console.error('Error loading program kreatif:', error);
|
||||
toast.error('Gagal memuat data program kreatif');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
loadProgramKreatif();
|
||||
}, [params?.id]);
|
||||
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
stateProgramKreatif.update.form = {
|
||||
@@ -75,49 +80,57 @@ function EditProgramKreatifDesa() {
|
||||
deskripsi: formData.deskripsi.trim(),
|
||||
slug: formData.slug.trim(),
|
||||
icon: formData.icon.trim(),
|
||||
}
|
||||
};
|
||||
await stateProgramKreatif.update.submit();
|
||||
router.push("/admin/inovasi/program-kreatif-desa");
|
||||
router.push('/admin/inovasi/program-kreatif-desa');
|
||||
} catch (error) {
|
||||
console.error("Error updating program kreatif:", error);
|
||||
toast.error("Gagal memuat data program kreatif");
|
||||
console.error('Error updating program kreatif:', error);
|
||||
toast.error('Gagal memuat data program kreatif');
|
||||
}
|
||||
}
|
||||
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 Kreatif Desa</Title>
|
||||
return (
|
||||
<Box px={{ base: 'sm', md: 'lg' }} py="md">
|
||||
<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 Kreatif Desa
|
||||
</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
|
||||
label="Nama Program Kreatif Desa"
|
||||
placeholder="Masukkan nama program kreatif desa"
|
||||
value={formData.name}
|
||||
label={<Text fz={"sm"} fw={"bold"}>Nama Program Kreatif Desa</Text>}
|
||||
placeholder="masukkan nama program kreatif desa"
|
||||
onChange={(val) => {
|
||||
setFormData({
|
||||
...formData,
|
||||
name: val.target.value
|
||||
})
|
||||
}}
|
||||
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
||||
required
|
||||
/>
|
||||
|
||||
<TextInput
|
||||
label="Deskripsi Singkat Program Kreatif Desa"
|
||||
placeholder="Masukkan deskripsi singkat program kreatif desa"
|
||||
value={formData.slug}
|
||||
label={<Text fz={"sm"} fw={"bold"}>Deskripsi Singkat Program Kreatif Desa</Text>}
|
||||
placeholder="masukkan deskripsi singkat program kreatif desa"
|
||||
onChange={(val) => {
|
||||
setFormData({
|
||||
...formData,
|
||||
slug: val.target.value
|
||||
})
|
||||
}}
|
||||
onChange={(e) => setFormData({ ...formData, slug: e.target.value })}
|
||||
required
|
||||
/>
|
||||
|
||||
<Box>
|
||||
<Text fz={"sm"} fw={"bold"}>Deskripsi</Text>
|
||||
<Text fw="bold" fz="sm" mb={6}>
|
||||
Deskripsi
|
||||
</Text>
|
||||
<EditEditor
|
||||
value={formData.deskripsi}
|
||||
onChange={(htmlContent) => {
|
||||
@@ -126,8 +139,11 @@ function EditProgramKreatifDesa() {
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box>
|
||||
<Text fz={"sm"} fw={"bold"}>Ikon Program Kreatif Desa</Text>
|
||||
<Text fw="bold" fz="sm" mb={6}>
|
||||
Ikon Program Kreatif Desa
|
||||
</Text>
|
||||
<SelectIconProgramEdit
|
||||
value={formData.icon as IconKey}
|
||||
onChange={(value) => {
|
||||
@@ -135,10 +151,22 @@ function EditProgramKreatifDesa() {
|
||||
stateProgramKreatif.update.form.icon = value;
|
||||
}}
|
||||
/>
|
||||
|
||||
|
||||
</Box>
|
||||
<Button bg={colors['blue-button']} onClick={handleSubmit}>Edit Berita</Button>
|
||||
|
||||
<Group justify="right">
|
||||
<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>
|
||||
</Box>
|
||||
|
||||
Reference in New Issue
Block a user