UI & API Struktur organisasi sudah bisa aktif & tidak aktif
This commit is contained in:
@@ -55,6 +55,11 @@ export default function EditPegawai() {
|
|||||||
isActive: true,
|
isActive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const statusOptions = [
|
||||||
|
{ value: true, label: 'Aktif' },
|
||||||
|
{ value: false, label: 'Tidak Aktif' },
|
||||||
|
];
|
||||||
|
|
||||||
// Format date to YYYY-MM-DD for date input
|
// Format date to YYYY-MM-DD for date input
|
||||||
const formatDateForInput = (dateString: string) => {
|
const formatDateForInput = (dateString: string) => {
|
||||||
if (!dateString) return '';
|
if (!dateString) return '';
|
||||||
@@ -249,18 +254,16 @@ export default function EditPegawai() {
|
|||||||
/>
|
/>
|
||||||
<Select
|
<Select
|
||||||
label="Status Pegawai"
|
label="Status Pegawai"
|
||||||
placeholder="Pilih status"
|
data={statusOptions.map((s) => ({
|
||||||
data={[
|
value: String(s.value),
|
||||||
{ value: 'true', label: 'Aktif' },
|
label: s.label,
|
||||||
{ value: 'false', label: 'Tidak Aktif' },
|
}))}
|
||||||
]}
|
|
||||||
value={String(formData.isActive)}
|
value={String(formData.isActive)}
|
||||||
onChange={(val) => {
|
onChange={(val) => {
|
||||||
if (val !== null) {
|
|
||||||
setFormData({ ...formData, isActive: val === 'true' });
|
setFormData({ ...formData, isActive: val === 'true' });
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ type FormCreatePegawai = {
|
|||||||
export default async function pegawaiCreate(context: Context) {
|
export default async function pegawaiCreate(context: Context) {
|
||||||
const body = await context.body as FormCreatePegawai;
|
const body = await context.body as FormCreatePegawai;
|
||||||
|
|
||||||
if (!body) {
|
if (!body || typeof body !== 'object') {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: "Data tidak valid",
|
message: "Data tidak valid",
|
||||||
@@ -42,7 +42,7 @@ export default async function pegawaiCreate(context: Context) {
|
|||||||
telepon: body.telepon,
|
telepon: body.telepon,
|
||||||
alamat: body.alamat,
|
alamat: body.alamat,
|
||||||
posisiId: body.posisiId,
|
posisiId: body.posisiId,
|
||||||
isActive: body.isActive !== false // default true kalau tidak dikirim
|
isActive: body.isActive ?? true, // default true kalau tidak dikirim
|
||||||
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import prisma from "@/lib/prisma";
|
|||||||
export default async function pegawaiFindMany() {
|
export default async function pegawaiFindMany() {
|
||||||
try {
|
try {
|
||||||
const pegawaiList = await prisma.pegawai.findMany({
|
const pegawaiList = await prisma.pegawai.findMany({
|
||||||
where: { isActive: true }, // Using the correct field name from Prisma model
|
|
||||||
orderBy: { createdAt: "desc" },
|
orderBy: { createdAt: "desc" },
|
||||||
include: {
|
include: {
|
||||||
posisi: true,
|
posisi: true,
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ export default async function pegawaiUpdate(context: Context) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof body.isActive !== 'boolean') {
|
||||||
|
body.isActive = true; // fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updated = await prisma.pegawai.update({
|
const updated = await prisma.pegawai.update({
|
||||||
where: { id: body.id },
|
where: { id: body.id },
|
||||||
@@ -37,7 +42,7 @@ export default async function pegawaiUpdate(context: Context) {
|
|||||||
telepon: body.telepon,
|
telepon: body.telepon,
|
||||||
alamat: body.alamat,
|
alamat: body.alamat,
|
||||||
posisiId: body.posisiId,
|
posisiId: body.posisiId,
|
||||||
isActive: body.isActive === true, // Konversi ke boolean
|
isActive: body.isActive ?? true, // default true kalau tidak dikirim
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
|
|||||||
Reference in New Issue
Block a user