Fix QC Kak Inno Admin, Fix QC Keano UI User, Fix QC Pak jun tabel apbdes
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
Button,
|
||||
Card,
|
||||
Group,
|
||||
Loader,
|
||||
Modal,
|
||||
Paper,
|
||||
Select,
|
||||
@@ -38,6 +39,7 @@ function EditPolsekTerdekat() {
|
||||
null
|
||||
);
|
||||
const [namaLayananUpdate, setNamaLayananUpdate] = useState("");
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [formData, setFormData] = useState({
|
||||
nama: "",
|
||||
jarakKeDesa: "",
|
||||
@@ -51,6 +53,19 @@ function EditPolsekTerdekat() {
|
||||
layananPolsekId: "",
|
||||
});
|
||||
|
||||
const [originalData, setOriginalData] = useState({
|
||||
nama: "",
|
||||
jarakKeDesa: "",
|
||||
alamat: "",
|
||||
nomorTelepon: "",
|
||||
jamOperasional: "",
|
||||
embedMapUrl: "",
|
||||
namaTempatMaps: "",
|
||||
alamatMaps: "",
|
||||
linkPetunjukArah: "",
|
||||
layananPolsekId: "",
|
||||
});
|
||||
|
||||
// load data untuk form edit
|
||||
useEffect(() => {
|
||||
const loadPolsekTerdekat = async () => {
|
||||
@@ -72,6 +87,19 @@ function EditPolsekTerdekat() {
|
||||
linkPetunjukArah: data.linkPetunjukArah || "",
|
||||
layananPolsekId: data.layananPolsekId || "",
|
||||
});
|
||||
|
||||
setOriginalData({
|
||||
nama: data.nama || "",
|
||||
jarakKeDesa: data.jarakKeDesa || "",
|
||||
alamat: data.alamat || "",
|
||||
nomorTelepon: data.nomorTelepon || "",
|
||||
jamOperasional: data.jamOperasional || "",
|
||||
embedMapUrl: data.embedMapUrl || "",
|
||||
namaTempatMaps: data.namaTempatMaps || "",
|
||||
alamatMaps: data.alamatMaps || "",
|
||||
linkPetunjukArah: data.linkPetunjukArah || "",
|
||||
layananPolsekId: data.layananPolsekId || "",
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error loading polsek terdekat:", error);
|
||||
@@ -187,8 +215,25 @@ function EditPolsekTerdekat() {
|
||||
setFormData(prev => ({ ...prev, [field]: value }));
|
||||
};
|
||||
|
||||
const handleResetForm = () => {
|
||||
setFormData({
|
||||
nama: originalData.nama,
|
||||
jarakKeDesa: originalData.jarakKeDesa,
|
||||
alamat: originalData.alamat,
|
||||
nomorTelepon: originalData.nomorTelepon,
|
||||
jamOperasional: originalData.jamOperasional,
|
||||
embedMapUrl: originalData.embedMapUrl,
|
||||
namaTempatMaps: originalData.namaTempatMaps,
|
||||
alamatMaps: originalData.alamatMaps,
|
||||
linkPetunjukArah: originalData.linkPetunjukArah,
|
||||
layananPolsekId: originalData.layananPolsekId,
|
||||
});
|
||||
toast.info("Form dikembalikan ke data awal");
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
setIsSubmitting(true);
|
||||
polsekState.edit.form = { ...formData }; // update global state hanya di sini
|
||||
await polsekState.edit.update();
|
||||
toast.success("Polsek terdekat berhasil diperbarui!");
|
||||
@@ -196,6 +241,8 @@ function EditPolsekTerdekat() {
|
||||
} catch (error) {
|
||||
console.error("Error updating polsek terdekat:", error);
|
||||
toast.error("Gagal memperbarui data polsek terdekat");
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -212,7 +259,7 @@ function EditPolsekTerdekat() {
|
||||
<TextInput
|
||||
label="Nama Layanan"
|
||||
placeholder="Masukkan nama layanan"
|
||||
defaultValue={namaLayananBaru}
|
||||
value={namaLayananBaru}
|
||||
onChange={(e) => setNamaLayananBaru(e.currentTarget.value)}
|
||||
/>
|
||||
<Button onClick={handleTambahLayanan}>Simpan</Button>
|
||||
@@ -230,7 +277,7 @@ function EditPolsekTerdekat() {
|
||||
<TextInput
|
||||
label="Nama Layanan"
|
||||
placeholder="Masukkan nama layanan"
|
||||
defaultValue={namaLayananUpdate}
|
||||
value={namaLayananUpdate}
|
||||
onChange={(e) => setNamaLayananUpdate(e.currentTarget.value)}
|
||||
/>
|
||||
<Button
|
||||
@@ -376,17 +423,29 @@ function EditPolsekTerdekat() {
|
||||
|
||||
{/* Submit */}
|
||||
<Group justify="right">
|
||||
{/* Tombol Batal */}
|
||||
<Button
|
||||
variant="outline"
|
||||
color="gray"
|
||||
radius="md"
|
||||
size="md"
|
||||
onClick={handleResetForm}
|
||||
>
|
||||
Batal
|
||||
</Button>
|
||||
|
||||
{/* Tombol Simpan */}
|
||||
<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)",
|
||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||
color: '#fff',
|
||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
{isSubmitting ? <Loader size="sm" color="white" /> : 'Simpan'}
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
Box,
|
||||
Button,
|
||||
Group,
|
||||
Loader,
|
||||
Modal,
|
||||
Paper,
|
||||
Select,
|
||||
@@ -26,6 +27,7 @@ function CreatePolsekTerdekat() {
|
||||
const [layananOptions, setLayananOptions] = useState<{ value: string; label: string }[]>([]);
|
||||
const [modalOpen, setModalOpen] = useState(false);
|
||||
const [namaLayananBaru, setNamaLayananBaru] = useState("");
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const resetForm = () => {
|
||||
polsekState.create.form = {
|
||||
@@ -43,9 +45,17 @@ function CreatePolsekTerdekat() {
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
await polsekState.create.create();
|
||||
resetForm();
|
||||
router.push("/admin/keamanan/polsek-terdekat");
|
||||
try {
|
||||
setIsSubmitting(true);
|
||||
await polsekState.create.create();
|
||||
resetForm();
|
||||
router.push("/admin/keamanan/polsek-terdekat");
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.error("Gagal menambah polsek terdekat");
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchLayanan = async () => {
|
||||
@@ -112,7 +122,7 @@ function CreatePolsekTerdekat() {
|
||||
<TextInput
|
||||
label="Nama Layanan"
|
||||
placeholder="Masukkan nama layanan"
|
||||
defaultValue={namaLayananBaru}
|
||||
value={namaLayananBaru}
|
||||
onChange={(e) => setNamaLayananBaru(e.currentTarget.value)}
|
||||
/>
|
||||
<Button onClick={handleTambahLayanan}>Simpan</Button>
|
||||
@@ -145,71 +155,84 @@ function CreatePolsekTerdekat() {
|
||||
>
|
||||
<Stack gap="md">
|
||||
<TextInput
|
||||
defaultValue={polsekState.create.form.nama}
|
||||
value={polsekState.create.form.nama}
|
||||
onChange={(val) => (polsekState.create.form.nama = val.target.value)}
|
||||
label={<Text fw="bold" fz="sm">Nama Polsek Terdekat</Text>}
|
||||
placeholder="Masukkan nama Polsek Terdekat"
|
||||
required
|
||||
/>
|
||||
<TextInput
|
||||
defaultValue={polsekState.create.form.jarakKeDesa}
|
||||
value={polsekState.create.form.jarakKeDesa}
|
||||
onChange={(val) => (polsekState.create.form.jarakKeDesa = val.target.value)}
|
||||
label={<Text fw="bold" fz="sm">Jarak Polsek Terdekat</Text>}
|
||||
placeholder="Masukkan jarak Polsek Terdekat"
|
||||
required
|
||||
/>
|
||||
<TextInput
|
||||
defaultValue={polsekState.create.form.alamat}
|
||||
value={polsekState.create.form.alamat}
|
||||
onChange={(val) => (polsekState.create.form.alamat = val.target.value)}
|
||||
label={<Text fw="bold" fz="sm">Alamat Polsek Terdekat</Text>}
|
||||
placeholder="Masukkan alamat Polsek Terdekat"
|
||||
required
|
||||
/>
|
||||
<TextInput
|
||||
defaultValue={polsekState.create.form.nomorTelepon}
|
||||
value={polsekState.create.form.nomorTelepon}
|
||||
onChange={(val) => (polsekState.create.form.nomorTelepon = val.target.value)}
|
||||
label={<Text fw="bold" fz="sm">Nomor Telepon Polsek Terdekat</Text>}
|
||||
placeholder="Masukkan nomor telepon Polsek Terdekat"
|
||||
required
|
||||
/>
|
||||
<TextInput
|
||||
defaultValue={polsekState.create.form.jamOperasional}
|
||||
value={polsekState.create.form.jamOperasional}
|
||||
onChange={(val) => (polsekState.create.form.jamOperasional = val.target.value)}
|
||||
label={<Text fw="bold" fz="sm">Jam Operasional Polsek Terdekat</Text>}
|
||||
placeholder="Masukkan jam operasional Polsek Terdekat"
|
||||
/>
|
||||
<TextInput
|
||||
defaultValue={polsekState.create.form.embedMapUrl}
|
||||
value={polsekState.create.form.embedMapUrl}
|
||||
onChange={(val) => (polsekState.create.form.embedMapUrl = val.target.value)}
|
||||
label={<Text fw="bold" fz="sm">Embed Map URL</Text>}
|
||||
placeholder="Masukkan embed map url"
|
||||
/>
|
||||
<TextInput
|
||||
defaultValue={polsekState.create.form.namaTempatMaps}
|
||||
value={polsekState.create.form.namaTempatMaps}
|
||||
onChange={(val) => (polsekState.create.form.namaTempatMaps = val.target.value)}
|
||||
label={<Text fw="bold" fz="sm">Nama Tempat Maps</Text>}
|
||||
placeholder="Masukkan nama tempat maps"
|
||||
/>
|
||||
<TextInput
|
||||
defaultValue={polsekState.create.form.alamatMaps}
|
||||
value={polsekState.create.form.alamatMaps}
|
||||
onChange={(val) => (polsekState.create.form.alamatMaps = val.target.value)}
|
||||
label={<Text fw="bold" fz="sm">Alamat Maps</Text>}
|
||||
placeholder="Masukkan alamat maps"
|
||||
/>
|
||||
<TextInput
|
||||
defaultValue={polsekState.create.form.linkPetunjukArah}
|
||||
value={polsekState.create.form.linkPetunjukArah}
|
||||
onChange={(val) => (polsekState.create.form.linkPetunjukArah = val.target.value)}
|
||||
label={<Text fw="bold" fz="sm">Link Petunjuk Arah</Text>}
|
||||
placeholder="Masukkan link petunjuk arah"
|
||||
/>
|
||||
|
||||
{/* Dropdown Select */}
|
||||
<Select
|
||||
label={<Text fw="bold" fz="sm">Layanan Polsek</Text>}
|
||||
label="Layanan Polsek"
|
||||
placeholder="Pilih layanan polsek"
|
||||
data={layananOptions}
|
||||
value={polsekState.create.form.layananPolsekId}
|
||||
onChange={(val) => (polsekState.create.form.layananPolsekId = val || "")}
|
||||
value={polsekState.create.form.layananPolsekId || null}
|
||||
onChange={(val: string | null) => {
|
||||
if (val) {
|
||||
const selected = layananOptions.find(
|
||||
(item) => item.value === val
|
||||
);
|
||||
if (selected) {
|
||||
polsekState.create.form.layananPolsekId = selected.value;
|
||||
}
|
||||
} else {
|
||||
polsekState.create.form.layananPolsekId = '';
|
||||
}
|
||||
}}
|
||||
searchable
|
||||
clearable
|
||||
nothingFoundMessage="Tidak ditemukan"
|
||||
required
|
||||
/>
|
||||
<Button
|
||||
variant="light"
|
||||
@@ -221,6 +244,17 @@ function CreatePolsekTerdekat() {
|
||||
|
||||
{/* 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"
|
||||
@@ -231,7 +265,7 @@ function CreatePolsekTerdekat() {
|
||||
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