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,
|
||||
Text,
|
||||
@@ -31,6 +32,7 @@ function EditDetailDataPengangguran() {
|
||||
const stateDetail = useProxy(jumlahPengangguranState.jumlahPengangguran);
|
||||
const router = useRouter();
|
||||
const params = useParams();
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
// --- state lokal form
|
||||
const [formData, setFormData] = useState({
|
||||
@@ -42,6 +44,15 @@ function EditDetailDataPengangguran() {
|
||||
percentageChange: 0,
|
||||
});
|
||||
|
||||
const [originalData, setOriginalData] = useState({
|
||||
month: '',
|
||||
year: new Date().getFullYear(),
|
||||
educatedUnemployment: 0,
|
||||
uneducatedUnemployment: 0,
|
||||
totalUnemployment: 0,
|
||||
percentageChange: 0,
|
||||
});
|
||||
|
||||
// --- hitung total + persentase perubahan
|
||||
const calculateTotalAndChange = useCallback(
|
||||
async (data: typeof formData) => {
|
||||
@@ -109,6 +120,15 @@ function EditDetailDataPengangguran() {
|
||||
totalUnemployment: data.totalUnemployment,
|
||||
percentageChange: data.percentageChange || 0,
|
||||
});
|
||||
|
||||
setOriginalData({
|
||||
month: data.month,
|
||||
year: yearValue,
|
||||
educatedUnemployment: data.educatedUnemployment,
|
||||
uneducatedUnemployment: data.uneducatedUnemployment,
|
||||
totalUnemployment: data.totalUnemployment,
|
||||
percentageChange: data.percentageChange || 0,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Error loading detail:', err);
|
||||
toast.error('Gagal memuat data detail');
|
||||
@@ -118,9 +138,22 @@ function EditDetailDataPengangguran() {
|
||||
loadDetail();
|
||||
}, [params?.id]);
|
||||
|
||||
const handleResetForm = () => {
|
||||
setFormData({
|
||||
month: originalData.month,
|
||||
year: originalData.year,
|
||||
educatedUnemployment: originalData.educatedUnemployment,
|
||||
uneducatedUnemployment: originalData.uneducatedUnemployment,
|
||||
totalUnemployment: originalData.totalUnemployment,
|
||||
percentageChange: originalData.percentageChange,
|
||||
});
|
||||
toast.info("Form dikembalikan ke data awal");
|
||||
};
|
||||
|
||||
// --- submit form
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
setIsSubmitting(true);
|
||||
const { total, percentageChange } = await calculateTotalAndChange(formData);
|
||||
|
||||
stateDetail.update.form = {
|
||||
@@ -137,6 +170,8 @@ function EditDetailDataPengangguran() {
|
||||
} catch (err) {
|
||||
console.error('Error updating:', err);
|
||||
toast.error('Terjadi kesalahan saat memperbarui data');
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -205,6 +240,17 @@ function EditDetailDataPengangguran() {
|
||||
</Text>
|
||||
|
||||
<Group justify="right">
|
||||
<Button
|
||||
variant="outline"
|
||||
color="gray"
|
||||
radius="md"
|
||||
size="md"
|
||||
onClick={handleResetForm}
|
||||
>
|
||||
Batal
|
||||
</Button>
|
||||
|
||||
{/* Tombol Simpan */}
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
radius="md"
|
||||
@@ -215,7 +261,7 @@ function EditDetailDataPengangguran() {
|
||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
{isSubmitting ? <Loader size="sm" color="white" /> : 'Simpan'}
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
Box,
|
||||
Button,
|
||||
Group,
|
||||
Loader,
|
||||
NumberInput,
|
||||
Paper,
|
||||
Select,
|
||||
@@ -17,12 +18,14 @@ import {
|
||||
import { IconArrowBack } from '@tabler/icons-react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
import { toast } from 'react-toastify';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
|
||||
function CreateJumlahPengangguran() {
|
||||
const stateDetail = useProxy(jumlahPengangguranState.jumlahPengangguran);
|
||||
const [chartData, setChartData] = useState<any[]>([]);
|
||||
const router = useRouter();
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const monthOptions = [
|
||||
'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun',
|
||||
@@ -72,15 +75,23 @@ function CreateJumlahPengangguran() {
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
await calculateTotalAndChange();
|
||||
const id = await stateDetail.create.create();
|
||||
if (id) {
|
||||
await stateDetail.findUnique.load(String(id));
|
||||
if (stateDetail.findUnique.data) {
|
||||
setChartData([stateDetail.findUnique.data]);
|
||||
try {
|
||||
setIsSubmitting(true);
|
||||
await calculateTotalAndChange();
|
||||
const id = await stateDetail.create.create();
|
||||
if (id) {
|
||||
await stateDetail.findUnique.load(String(id));
|
||||
if (stateDetail.findUnique.data) {
|
||||
setChartData([stateDetail.findUnique.data]);
|
||||
}
|
||||
resetForm();
|
||||
router.push('/admin/ekonomi/jumlah-pengangguran');
|
||||
}
|
||||
resetForm();
|
||||
router.push('/admin/ekonomi/jumlah-pengangguran');
|
||||
} catch (error) {
|
||||
console.error("Error creating jumlah pengangguran:", error);
|
||||
toast.error("Gagal menambahkan data pengangguran");
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -176,7 +187,19 @@ function CreateJumlahPengangguran() {
|
||||
</Box>
|
||||
|
||||
{/* Action Button */}
|
||||
<Group justify="right" mt="md">
|
||||
<Group justify="right">
|
||||
{/* Tombol Batal */}
|
||||
<Button
|
||||
variant="outline"
|
||||
color="gray"
|
||||
radius="md"
|
||||
size="md"
|
||||
onClick={resetForm}
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
|
||||
{/* Tombol Simpan */}
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
radius="md"
|
||||
@@ -186,9 +209,8 @@ function CreateJumlahPengangguran() {
|
||||
color: '#fff',
|
||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||
}}
|
||||
disabled={!stateDetail.create.form.month || !stateDetail.create.form.year}
|
||||
>
|
||||
Simpan
|
||||
{isSubmitting ? <Loader size="sm" color="white" /> : 'Simpan'}
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
|
||||
Reference in New Issue
Block a user