Fix QC Kak Inno Admin, Fix QC Keano UI User, Fix QC Pak jun tabel apbdes

This commit is contained in:
2025-11-12 17:42:31 +08:00
parent 417a8937f5
commit 9622eb5a9a
354 changed files with 11444 additions and 4012 deletions

View File

@@ -8,6 +8,7 @@ import {
Box,
Button,
Group,
Loader,
Paper,
Stack,
Text,
@@ -24,6 +25,7 @@ function EditKontakItem() {
const router = useRouter();
const kontakState = useProxy(kontakDarurat.kontakDaruratItem);
const params = useParams();
const [isSubmitting, setIsSubmitting] = useState(false);
const [formData, setFormData] = useState({
name: '',
@@ -31,6 +33,12 @@ function EditKontakItem() {
icon: '',
});
const [originalData, setOriginalData] = useState({
name: '',
nomorTelepon: '',
icon: '',
});
// Load data sekali dari global state
useEffect(() => {
const loadKontakDarurat = async () => {
@@ -45,6 +53,11 @@ function EditKontakItem() {
nomorTelepon: data.nomorTelepon || '',
icon: data.icon || '',
});
setOriginalData({
name: data.nama || '',
nomorTelepon: data.nomorTelepon || '',
icon: data.icon || '',
});
}
} catch (error) {
console.error('Error loading kontak darurat:', error);
@@ -62,8 +75,18 @@ function EditKontakItem() {
}));
};
const handleResetForm = () => {
setFormData({
name: originalData.name,
nomorTelepon: originalData.nomorTelepon,
icon: originalData.icon,
});
toast.info('Form dikembalikan ke data awal');
};
const handleSubmit = async () => {
try {
setIsSubmitting(true);
// Update global state sekali pas submit
kontakState.update.form = {
...kontakState.update.form,
@@ -78,6 +101,8 @@ function EditKontakItem() {
} catch (error) {
console.error('Error updating kontak darurat:', error);
toast.error('Terjadi kesalahan saat memperbarui kontak darurat');
} finally {
setIsSubmitting(false);
}
};
@@ -130,6 +155,17 @@ function EditKontakItem() {
</Box>
<Group justify="right">
<Button
variant="outline"
color="gray"
radius="md"
size="md"
onClick={handleResetForm}
>
Batal
</Button>
{/* Tombol Simpan */}
<Button
onClick={handleSubmit}
radius="md"
@@ -140,7 +176,7 @@ function EditKontakItem() {
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
}}
>
Simpan
{isSubmitting ? <Loader size="sm" color="white" /> : 'Simpan'}
</Button>
</Group>
</Stack>

View File

@@ -6,6 +6,7 @@ import {
Box,
Button,
Group,
Loader,
Paper,
Stack,
Text,
@@ -14,11 +15,14 @@ import {
} from '@mantine/core';
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 CreateKontakItem() {
const kontakState = useProxy(kontakDarurat.kontakDaruratItem);
const router = useRouter();
const [isSubmitting, setIsSubmitting] = useState(false);
const resetForm = () => {
kontakState.create.form = {
nama: '',
@@ -28,9 +32,17 @@ function CreateKontakItem() {
};
const handleSubmit = async () => {
await kontakState.create.create();
resetForm();
router.push('/admin/keamanan/kontak-darurat/kontak-darurat-item');
try {
setIsSubmitting(true);
await kontakState.create.create();
resetForm();
router.push('/admin/keamanan/kontak-darurat/kontak-darurat-item');
} catch (error) {
console.error("Error creating kontak darurat item:", error);
toast.error("Gagal menambahkan kontak darurat item");
} finally {
setIsSubmitting(false);
}
};
return (
@@ -62,7 +74,7 @@ function CreateKontakItem() {
<Stack gap="md">
{/* Input Nama Kategori */}
<TextInput
defaultValue={kontakState.create.form.nama}
value={kontakState.create.form.nama}
onChange={(val) => {
kontakState.create.form.nama = val.target.value;
}}
@@ -74,7 +86,7 @@ function CreateKontakItem() {
<TextInput
label={<Text fw="bold" fz="sm">Nomor Telepon Kontak</Text>}
placeholder="Masukkan nomor telepon"
defaultValue={kontakState.create.form.nomorTelepon}
value={kontakState.create.form.nomorTelepon}
onChange={(val) => {
kontakState.create.form.nomorTelepon = val.target.value;
}}
@@ -88,6 +100,17 @@ function CreateKontakItem() {
{/* Tombol Submit */}
<Group justify="right">
<Button
variant="outline"
color="gray"
radius="md"
size="md"
onClick={resetForm}
>
Reset
</Button>
{/* Tombol Simpan */}
<Button
onClick={handleSubmit}
radius="md"
@@ -98,7 +121,7 @@ function CreateKontakItem() {
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
}}
>
Simpan
{isSubmitting ? <Loader size="sm" color="white" /> : 'Simpan'}
</Button>
</Group>
</Stack>