feat: Add CRUD functionality for books, categories, and loans
- Implemented Create, Edit, and Index pages for Buku (Books) with form handling and validation. - Added Create, Edit, and Index pages for Kategori (Categories) with form handling and validation. - Developed Create and Index pages for Peminjaman (Loans) with form handling and validation. - Integrated status management and action buttons for loan records. - Enhanced UI with responsive design and user-friendly navigation.
This commit is contained in:
158
resources/js/Pages/Anggota/Create.jsx
Normal file
158
resources/js/Pages/Anggota/Create.jsx
Normal file
@@ -0,0 +1,158 @@
|
||||
import MainLayout from "@/Layouts/MainLayout";
|
||||
import { Head, useForm, Link } from "@inertiajs/react";
|
||||
|
||||
export default function AnggotaCreate() {
|
||||
const { data, setData, post, processing, errors } = useForm({
|
||||
nama: "",
|
||||
email: "",
|
||||
no_telepon: "",
|
||||
alamat: "",
|
||||
tanggal_bergabung: "",
|
||||
status: "aktif",
|
||||
});
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
post("/anggota");
|
||||
};
|
||||
|
||||
return (
|
||||
<MainLayout>
|
||||
<Head title="Tambah Anggota" />
|
||||
|
||||
<div className="max-w-2xl mx-auto">
|
||||
<div className="flex items-center gap-2 mb-6">
|
||||
<Link
|
||||
href="/anggota"
|
||||
className="text-indigo-600 hover:underline"
|
||||
>
|
||||
← Kembali
|
||||
</Link>
|
||||
<span className="text-gray-400">/</span>
|
||||
<span className="text-gray-600">Tambah Anggota</span>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-xl shadow p-6">
|
||||
<h1 className="text-xl font-bold text-gray-800 mb-6">
|
||||
👥 Tambah Anggota Baru
|
||||
</h1>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<FormField label="Nama Lengkap" error={errors.nama}>
|
||||
<input
|
||||
type="text"
|
||||
value={data.nama}
|
||||
onChange={(e) =>
|
||||
setData("nama", e.target.value)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
placeholder="Masukkan nama lengkap"
|
||||
/>
|
||||
</FormField>
|
||||
|
||||
<FormField label="Email" error={errors.email}>
|
||||
<input
|
||||
type="email"
|
||||
value={data.email}
|
||||
onChange={(e) =>
|
||||
setData("email", e.target.value)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
placeholder="contoh@email.com"
|
||||
/>
|
||||
</FormField>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<FormField
|
||||
label="No Telepon"
|
||||
error={errors.no_telepon}
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
value={data.no_telepon}
|
||||
onChange={(e) =>
|
||||
setData("no_telepon", e.target.value)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
placeholder="08xxxxxxxxxx"
|
||||
/>
|
||||
</FormField>
|
||||
|
||||
<FormField
|
||||
label="Tanggal Bergabung"
|
||||
error={errors.tanggal_bergabung}
|
||||
>
|
||||
<input
|
||||
type="date"
|
||||
value={data.tanggal_bergabung}
|
||||
onChange={(e) =>
|
||||
setData(
|
||||
"tanggal_bergabung",
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
/>
|
||||
</FormField>
|
||||
</div>
|
||||
|
||||
<FormField label="Alamat" error={errors.alamat}>
|
||||
<textarea
|
||||
value={data.alamat}
|
||||
onChange={(e) =>
|
||||
setData("alamat", e.target.value)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
rows={3}
|
||||
placeholder="Masukkan alamat lengkap"
|
||||
/>
|
||||
</FormField>
|
||||
|
||||
<FormField label="Status" error={errors.status}>
|
||||
<select
|
||||
value={data.status}
|
||||
onChange={(e) =>
|
||||
setData("status", e.target.value)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
>
|
||||
<option value="aktif">Aktif</option>
|
||||
<option value="nonaktif">Non Aktif</option>
|
||||
</select>
|
||||
</FormField>
|
||||
|
||||
<div className="flex gap-3 pt-4">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={processing}
|
||||
className="bg-indigo-600 text-white px-6 py-2 rounded-lg hover:bg-indigo-700 disabled:opacity-50 transition-colors"
|
||||
>
|
||||
{processing
|
||||
? "Menyimpan..."
|
||||
: "💾 Simpan Anggota"}
|
||||
</button>
|
||||
<Link
|
||||
href="/anggota"
|
||||
className="bg-gray-200 text-gray-700 px-6 py-2 rounded-lg hover:bg-gray-300 transition-colors"
|
||||
>
|
||||
Batal
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</MainLayout>
|
||||
);
|
||||
}
|
||||
|
||||
function FormField({ label, error, children }) {
|
||||
return (
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||
{label}
|
||||
</label>
|
||||
{children}
|
||||
{error && <p className="text-red-500 text-xs mt-1">{error}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
154
resources/js/Pages/Anggota/Edit.jsx
Normal file
154
resources/js/Pages/Anggota/Edit.jsx
Normal file
@@ -0,0 +1,154 @@
|
||||
import MainLayout from "@/Layouts/MainLayout";
|
||||
import { Head, useForm, Link } from "@inertiajs/react";
|
||||
|
||||
export default function AnggotaEdit({ anggota }) {
|
||||
const { data, setData, put, processing, errors } = useForm({
|
||||
nama: anggota.nama,
|
||||
email: anggota.email,
|
||||
no_telepon: anggota.no_telepon ?? "",
|
||||
alamat: anggota.alamat ?? "",
|
||||
tanggal_bergabung: anggota.tanggal_bergabung,
|
||||
status: anggota.status,
|
||||
});
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
put(`/anggota/${anggota.id}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<MainLayout>
|
||||
<Head title="Edit Anggota" />
|
||||
|
||||
<div className="max-w-2xl mx-auto">
|
||||
<div className="flex items-center gap-2 mb-6">
|
||||
<Link
|
||||
href="/anggota"
|
||||
className="text-indigo-600 hover:underline"
|
||||
>
|
||||
← Kembali
|
||||
</Link>
|
||||
<span className="text-gray-400">/</span>
|
||||
<span className="text-gray-600">Edit Anggota</span>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-xl shadow p-6">
|
||||
<h1 className="text-xl font-bold text-gray-800 mb-6">
|
||||
✏️ Edit Anggota
|
||||
</h1>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<FormField label="Nama Lengkap" error={errors.nama}>
|
||||
<input
|
||||
type="text"
|
||||
value={data.nama}
|
||||
onChange={(e) =>
|
||||
setData("nama", e.target.value)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
/>
|
||||
</FormField>
|
||||
|
||||
<FormField label="Email" error={errors.email}>
|
||||
<input
|
||||
type="email"
|
||||
value={data.email}
|
||||
onChange={(e) =>
|
||||
setData("email", e.target.value)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
/>
|
||||
</FormField>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<FormField
|
||||
label="No Telepon"
|
||||
error={errors.no_telepon}
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
value={data.no_telepon}
|
||||
onChange={(e) =>
|
||||
setData("no_telepon", e.target.value)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
/>
|
||||
</FormField>
|
||||
|
||||
<FormField
|
||||
label="Tanggal Bergabung"
|
||||
error={errors.tanggal_bergabung}
|
||||
>
|
||||
<input
|
||||
type="date"
|
||||
value={data.tanggal_bergabung}
|
||||
onChange={(e) =>
|
||||
setData(
|
||||
"tanggal_bergabung",
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
/>
|
||||
</FormField>
|
||||
</div>
|
||||
|
||||
<FormField label="Alamat" error={errors.alamat}>
|
||||
<textarea
|
||||
value={data.alamat}
|
||||
onChange={(e) =>
|
||||
setData("alamat", e.target.value)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
rows={3}
|
||||
/>
|
||||
</FormField>
|
||||
|
||||
<FormField label="Status" error={errors.status}>
|
||||
<select
|
||||
value={data.status}
|
||||
onChange={(e) =>
|
||||
setData("status", e.target.value)
|
||||
}
|
||||
className="w-full border rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-400 focus:outline-none"
|
||||
>
|
||||
<option value="aktif">Aktif</option>
|
||||
<option value="nonaktif">Non Aktif</option>
|
||||
</select>
|
||||
</FormField>
|
||||
|
||||
<div className="flex gap-3 pt-4">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={processing}
|
||||
className="bg-indigo-600 text-white px-6 py-2 rounded-lg hover:bg-indigo-700 disabled:opacity-50 transition-colors"
|
||||
>
|
||||
{processing
|
||||
? "Menyimpan..."
|
||||
: "💾 Update Anggota"}
|
||||
</button>
|
||||
<Link
|
||||
href="/anggota"
|
||||
className="bg-gray-200 text-gray-700 px-6 py-2 rounded-lg hover:bg-gray-300 transition-colors"
|
||||
>
|
||||
Batal
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</MainLayout>
|
||||
);
|
||||
}
|
||||
|
||||
function FormField({ label, error, children }) {
|
||||
return (
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||
{label}
|
||||
</label>
|
||||
{children}
|
||||
{error && <p className="text-red-500 text-xs mt-1">{error}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
142
resources/js/Pages/Anggota/Index.jsx
Normal file
142
resources/js/Pages/Anggota/Index.jsx
Normal file
@@ -0,0 +1,142 @@
|
||||
import MainLayout from "@/Layouts/MainLayout";
|
||||
import { Head, Link, router } from "@inertiajs/react";
|
||||
|
||||
export default function AnggotaIndex({ anggotas }) {
|
||||
const handleDelete = (id) => {
|
||||
if (confirm("Yakin ingin menghapus anggota ini?")) {
|
||||
router.delete(`/anggota/${id}`);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<MainLayout>
|
||||
<Head title="Data Anggota" />
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-bold text-gray-800">
|
||||
👥 Data Anggota
|
||||
</h1>
|
||||
<Link
|
||||
href="/anggota/create"
|
||||
className="bg-indigo-600 text-white px-4 py-2 rounded-lg hover:bg-indigo-700 transition-colors"
|
||||
>
|
||||
+ Tambah Anggota
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-xl shadow overflow-hidden">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-gray-50 border-b">
|
||||
<tr>
|
||||
<th className="px-4 py-3 text-left text-gray-600">
|
||||
No
|
||||
</th>
|
||||
<th className="px-4 py-3 text-left text-gray-600">
|
||||
Nama
|
||||
</th>
|
||||
<th className="px-4 py-3 text-left text-gray-600">
|
||||
Email
|
||||
</th>
|
||||
<th className="px-4 py-3 text-left text-gray-600">
|
||||
No Telepon
|
||||
</th>
|
||||
<th className="px-4 py-3 text-left text-gray-600">
|
||||
Tgl Bergabung
|
||||
</th>
|
||||
<th className="px-4 py-3 text-left text-gray-600">
|
||||
Status
|
||||
</th>
|
||||
<th className="px-4 py-3 text-center text-gray-600">
|
||||
Aksi
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100">
|
||||
{anggotas.data.map((anggota, index) => (
|
||||
<tr
|
||||
key={anggota.id}
|
||||
className="hover:bg-gray-50"
|
||||
>
|
||||
<td className="px-4 py-3 text-gray-500">
|
||||
{(anggotas.current_page - 1) *
|
||||
anggotas.per_page +
|
||||
index +
|
||||
1}
|
||||
</td>
|
||||
<td className="px-4 py-3 font-medium">
|
||||
{anggota.nama}
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
{anggota.email}
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
{anggota.no_telepon ?? "-"}
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
{anggota.tanggal_bergabung}
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<span
|
||||
className={`px-2 py-1 rounded-full text-xs font-medium ${
|
||||
anggota.status === "aktif"
|
||||
? "bg-green-100 text-green-700"
|
||||
: "bg-red-100 text-red-700"
|
||||
}`}
|
||||
>
|
||||
{anggota.status}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
<Link
|
||||
href={`/anggota/${anggota.id}/edit`}
|
||||
className="text-blue-600 hover:text-blue-800 text-xs bg-blue-50 px-2 py-1 rounded"
|
||||
>
|
||||
Edit
|
||||
</Link>
|
||||
<button
|
||||
onClick={() =>
|
||||
handleDelete(anggota.id)
|
||||
}
|
||||
className="text-red-600 hover:text-red-800 text-xs bg-red-50 px-2 py-1 rounded"
|
||||
>
|
||||
Hapus
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/* Pagination */}
|
||||
<div className="px-4 py-3 border-t flex items-center justify-between">
|
||||
<p className="text-sm text-gray-500">
|
||||
Menampilkan {anggotas.from} - {anggotas.to} dari{" "}
|
||||
{anggotas.total} data
|
||||
</p>
|
||||
<div className="flex gap-1">
|
||||
{anggotas.links.map((link, i) => (
|
||||
<Link
|
||||
key={i}
|
||||
href={link.url || "#"}
|
||||
className={`px-3 py-1 text-sm rounded ${
|
||||
link.active
|
||||
? "bg-indigo-600 text-white"
|
||||
: "bg-gray-100 text-gray-600 hover:bg-gray-200"
|
||||
}`}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: link.label,
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</MainLayout>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user