153 lines
3.4 KiB
TypeScript
153 lines
3.4 KiB
TypeScript
// src/components/masterData/EditBarangModal.tsx
|
|
|
|
import { useState } from "react";
|
|
|
|
type BarangType = {
|
|
id: number;
|
|
nama: string;
|
|
foto: string;
|
|
kondisi: string;
|
|
disetujui: boolean;
|
|
kategori: string;
|
|
waktu: string;
|
|
};
|
|
|
|
type Props = {
|
|
barang: BarangType;
|
|
onClose: () => void;
|
|
onSave: (
|
|
barang: BarangType
|
|
) => void;
|
|
};
|
|
|
|
export default function EditBarangModal({
|
|
barang,
|
|
onClose,
|
|
onSave,
|
|
}: Props) {
|
|
const [kondisi, setKondisi] =
|
|
useState(
|
|
barang.kondisi
|
|
);
|
|
|
|
const [disetujui, setDisetujui] =
|
|
useState(
|
|
barang.disetujui
|
|
);
|
|
|
|
const handleSubmit = () => {
|
|
onSave({
|
|
...barang,
|
|
kondisi,
|
|
disetujui,
|
|
waktu:
|
|
new Date().toLocaleTimeString(
|
|
"id-ID"
|
|
),
|
|
});
|
|
};
|
|
|
|
return (
|
|
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50">
|
|
<div className="bg-white w-[420px] rounded-3xl shadow-2xl p-6">
|
|
|
|
{/* HEADER */}
|
|
<h2 className="text-xl font-bold text-center mb-5">
|
|
Edit Barang
|
|
</h2>
|
|
|
|
{/* FOTO */}
|
|
<div className="w-28 h-28 mx-auto rounded-2xl overflow-hidden mb-4 bg-gray-100">
|
|
<img
|
|
src={barang.foto}
|
|
alt={barang.nama}
|
|
className="w-full h-full object-cover"
|
|
/>
|
|
</div>
|
|
|
|
{/* NAMA */}
|
|
<p className="text-center font-semibold mb-2">
|
|
{barang.nama}
|
|
</p>
|
|
|
|
{/* WAKTU */}
|
|
<p className="text-center text-sm text-gray-500 mb-4">
|
|
Update:
|
|
{barang.waktu}
|
|
</p>
|
|
|
|
{/* FORM */}
|
|
<div className="space-y-4">
|
|
|
|
{/* KONDISI */}
|
|
<div>
|
|
<label className="block text-sm font-medium mb-1">
|
|
Kondisi
|
|
</label>
|
|
<select
|
|
value={kondisi}
|
|
onChange={(e) =>
|
|
setKondisi(
|
|
e.target.value
|
|
)
|
|
}
|
|
className="w-full border rounded-xl p-3"
|
|
>
|
|
<option value="Bagus">
|
|
Bagus
|
|
</option>
|
|
<option value="Kurang Bagus">
|
|
Kurang Bagus
|
|
</option>
|
|
</select>
|
|
</div>
|
|
|
|
{/* STATUS */}
|
|
<div>
|
|
<label className="block text-sm font-medium mb-1">
|
|
Status Persetujuan
|
|
</label>
|
|
<select
|
|
value={
|
|
disetujui
|
|
? "true"
|
|
: "false"
|
|
}
|
|
onChange={(e) =>
|
|
setDisetujui(
|
|
e.target.value ===
|
|
"true"
|
|
)
|
|
}
|
|
className="w-full border rounded-xl p-3"
|
|
>
|
|
<option value="true">
|
|
Disetujui
|
|
</option>
|
|
<option value="false">
|
|
Belum Disetujui
|
|
</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
{/* BUTTON */}
|
|
<div className="flex justify-end gap-3 mt-6">
|
|
<button
|
|
onClick={onClose}
|
|
className="px-4 py-2 rounded-xl bg-gray-300 hover:bg-gray-400"
|
|
>
|
|
Batal
|
|
</button>
|
|
|
|
<button
|
|
onClick={handleSubmit}
|
|
className="px-4 py-2 rounded-xl bg-blue-600 text-white hover:bg-blue-700"
|
|
>
|
|
Simpan
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
} |