Fix QC Kak Inno Admin, Fix QC Keano UI User, Fix QC Pak jun tabel apbdes
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
Box,
|
||||
Button,
|
||||
Group,
|
||||
Loader,
|
||||
Paper,
|
||||
Stack,
|
||||
TextInput,
|
||||
@@ -22,7 +23,7 @@ function EditJumlahPendudukMiskin() {
|
||||
const router = useRouter();
|
||||
const params = useParams() as { id: string };
|
||||
const stateJPM = useProxy(jumlahPendudukMiskin);
|
||||
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const id = params.id;
|
||||
|
||||
// 🔹 State lokal untuk form
|
||||
@@ -31,6 +32,11 @@ function EditJumlahPendudukMiskin() {
|
||||
totalPoorPopulation: 0,
|
||||
});
|
||||
|
||||
const [originalData, setOriginalData] = useState({
|
||||
year: 0,
|
||||
totalPoorPopulation: 0,
|
||||
});
|
||||
|
||||
// 🔹 Load data awal dari backend
|
||||
useEffect(() => {
|
||||
if (!id) return;
|
||||
@@ -44,6 +50,10 @@ function EditJumlahPendudukMiskin() {
|
||||
year: data.year || 0,
|
||||
totalPoorPopulation: data.totalPoorPopulation || 0,
|
||||
});
|
||||
setOriginalData({
|
||||
year: data.year || 0,
|
||||
totalPoorPopulation: data.totalPoorPopulation || 0,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Gagal memuat data:', error);
|
||||
@@ -62,9 +72,18 @@ function EditJumlahPendudukMiskin() {
|
||||
}));
|
||||
};
|
||||
|
||||
const handleResetForm = () => {
|
||||
setFormData({
|
||||
year: originalData.year,
|
||||
totalPoorPopulation: originalData.totalPoorPopulation,
|
||||
});
|
||||
toast.info('Form dikembalikan ke data awal');
|
||||
};
|
||||
|
||||
// 🔹 Submit form
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
setIsSubmitting(true);
|
||||
stateJPM.update.id = id;
|
||||
// update global state cuma saat submit
|
||||
stateJPM.update.form = { ...formData };
|
||||
@@ -75,6 +94,8 @@ function EditJumlahPendudukMiskin() {
|
||||
} catch (error) {
|
||||
console.error('Gagal menyimpan data:', error);
|
||||
toast.error('Terjadi kesalahan saat menyimpan data');
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -124,6 +145,17 @@ function EditJumlahPendudukMiskin() {
|
||||
/>
|
||||
|
||||
<Group justify="right">
|
||||
<Button
|
||||
variant="outline"
|
||||
color="gray"
|
||||
radius="md"
|
||||
size="md"
|
||||
onClick={handleResetForm}
|
||||
>
|
||||
Batal
|
||||
</Button>
|
||||
|
||||
{/* Tombol Simpan */}
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
radius="md"
|
||||
@@ -134,7 +166,7 @@ function EditJumlahPendudukMiskin() {
|
||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
{isSubmitting ? <Loader size="sm" color="white" /> : 'Simpan'}
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
|
||||
@@ -2,17 +2,19 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
'use client';
|
||||
import colors from '@/con/colors';
|
||||
import { Box, Button, Group, Paper, Stack, TextInput, Title } from '@mantine/core';
|
||||
import { Box, Button, Group, Loader, Paper, Stack, TextInput, Title } from '@mantine/core';
|
||||
import { IconArrowBack } from '@tabler/icons-react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
import jumlahPendudukMiskin from '../../../_state/ekonomi/jumlah-penduduk-miskin';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
export default function CreateJumlahPendudukMiskin() {
|
||||
const stateJPM = useProxy(jumlahPendudukMiskin);
|
||||
const [chartData, setChartData] = useState<any[]>([]);
|
||||
const router = useRouter();
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const resetForm = () => {
|
||||
stateJPM.create.form = {
|
||||
@@ -22,16 +24,24 @@ export default function CreateJumlahPendudukMiskin() {
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const id = await stateJPM.create.create();
|
||||
if (id) {
|
||||
const idStr = String(id);
|
||||
await stateJPM.findUnique.load(idStr);
|
||||
if (stateJPM.findUnique.data) {
|
||||
setChartData([stateJPM.findUnique.data]);
|
||||
try {
|
||||
setIsSubmitting(true);
|
||||
const id = await stateJPM.create.create();
|
||||
if (id) {
|
||||
const idStr = String(id);
|
||||
await stateJPM.findUnique.load(idStr);
|
||||
if (stateJPM.findUnique.data) {
|
||||
setChartData([stateJPM.findUnique.data]);
|
||||
}
|
||||
}
|
||||
resetForm();
|
||||
router.push('/admin/ekonomi/jumlah-penduduk-miskin');
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.error(error instanceof Error ? error.message : "Gagal menambahkan jumlah penduduk miskin")
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
resetForm();
|
||||
router.push('/admin/ekonomi/jumlah-penduduk-miskin');
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -59,7 +69,7 @@ export default function CreateJumlahPendudukMiskin() {
|
||||
<TextInput
|
||||
label="Tahun"
|
||||
type="number"
|
||||
defaultValue={stateJPM.create.form.year || ''}
|
||||
value={stateJPM.create.form.year || ''}
|
||||
placeholder="Masukkan tahun"
|
||||
onChange={(e) => {
|
||||
const value = e.currentTarget.value;
|
||||
@@ -71,7 +81,7 @@ export default function CreateJumlahPendudukMiskin() {
|
||||
<TextInput
|
||||
label="Jumlah Penduduk Miskin"
|
||||
type="number"
|
||||
defaultValue={stateJPM.create.form.totalPoorPopulation}
|
||||
value={stateJPM.create.form.totalPoorPopulation}
|
||||
placeholder="Masukkan jumlah penduduk miskin"
|
||||
onChange={(e) => {
|
||||
stateJPM.create.form.totalPoorPopulation = Number(e.currentTarget.value);
|
||||
@@ -80,6 +90,17 @@ export default function CreateJumlahPendudukMiskin() {
|
||||
/>
|
||||
|
||||
<Group justify="right">
|
||||
<Button
|
||||
variant="outline"
|
||||
color="gray"
|
||||
radius="md"
|
||||
size="md"
|
||||
onClick={resetForm}
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
|
||||
{/* Tombol Simpan */}
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
radius="md"
|
||||
@@ -90,7 +111,7 @@ export default function CreateJumlahPendudukMiskin() {
|
||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
{isSubmitting ? <Loader size="sm" color="white" /> : 'Simpan'}
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
|
||||
Reference in New Issue
Block a user