UI & API Struktur organisasi sudah bisa aktif & tidak aktif

This commit is contained in:
2025-07-07 21:41:27 +08:00
parent a2e25a3e3a
commit c0b941395d
4 changed files with 19 additions and 12 deletions

View File

@@ -55,6 +55,11 @@ export default function EditPegawai() {
isActive: true,
});
const statusOptions = [
{ value: true, label: 'Aktif' },
{ value: false, label: 'Tidak Aktif' },
];
// Format date to YYYY-MM-DD for date input
const formatDateForInput = (dateString: string) => {
if (!dateString) return '';
@@ -249,18 +254,16 @@ export default function EditPegawai() {
/>
<Select
label="Status Pegawai"
placeholder="Pilih status"
data={[
{ value: 'true', label: 'Aktif' },
{ value: 'false', label: 'Tidak Aktif' },
]}
data={statusOptions.map((s) => ({
value: String(s.value),
label: s.label,
}))}
value={String(formData.isActive)}
onChange={(val) => {
if (val !== null) {
setFormData({ ...formData, isActive: val === 'true' });
}
setFormData({ ...formData, isActive: val === 'true' });
}}
/>
<Group>
<Button
onClick={handleSubmit}

View File

@@ -17,7 +17,7 @@ type FormCreatePegawai = {
export default async function pegawaiCreate(context: Context) {
const body = await context.body as FormCreatePegawai;
if (!body) {
if (!body || typeof body !== 'object') {
return {
success: false,
message: "Data tidak valid",
@@ -42,7 +42,7 @@ export default async function pegawaiCreate(context: Context) {
telepon: body.telepon,
alamat: body.alamat,
posisiId: body.posisiId,
isActive: body.isActive !== false // default true kalau tidak dikirim
isActive: body.isActive ?? true, // default true kalau tidak dikirim
},
});

View File

@@ -4,7 +4,6 @@ import prisma from "@/lib/prisma";
export default async function pegawaiFindMany() {
try {
const pegawaiList = await prisma.pegawai.findMany({
where: { isActive: true }, // Using the correct field name from Prisma model
orderBy: { createdAt: "desc" },
include: {
posisi: true,

View File

@@ -25,6 +25,11 @@ export default async function pegawaiUpdate(context: Context) {
};
}
if (typeof body.isActive !== 'boolean') {
body.isActive = true; // fallback
}
try {
const updated = await prisma.pegawai.update({
where: { id: body.id },
@@ -37,7 +42,7 @@ export default async function pegawaiUpdate(context: Context) {
telepon: body.telepon,
alamat: body.alamat,
posisiId: body.posisiId,
isActive: body.isActive === true, // Konversi ke boolean
isActive: body.isActive ?? true, // default true kalau tidak dikirim
updatedAt: new Date(),
},
include: {