This commit is contained in:
[Valentino Heman Budiarto]
2026-02-19 18:14:19 +07:00
parent d09c21a41f
commit 9d4cc8bfed
29 changed files with 8582 additions and 1 deletions
@@ -0,0 +1,245 @@
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { Calendar, Clock, Save, X, AlertTriangle } from "lucide-react";
export default function AddBookingPage() {
const router = useRouter();
const [isLoading, setIsLoading] = useState(false);
// State untuk form input
const [formData, setFormData] = useState({
room: "Ruang T-301",
date: "",
startTime: "",
endTime: "",
purpose: "",
});
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => {
setFormData({ ...formData, [e.target.name]: e.target.value });
};
// --- LOGIKA VALIDASI (Business Logic) ---
const validateBookingRules = () => {
// 1. Cek kelengkapan data dasar
if (!formData.date || !formData.startTime || !formData.endTime) {
alert("Mohon lengkapi Tanggal dan Jam terlebih dahulu.");
return false;
}
// 2. Ambil Jam Mulai
const startHour = parseInt(formData.startTime.split(":")[0]);
// 3. Cek Jam Khusus (Diatas 21:00 ATAU Sebelum 06:00)
const isSpecialTime = startHour >= 21 || startHour < 6;
if (isSpecialTime) {
const bookingDate = new Date(formData.date);
const today = new Date();
// Reset jam agar perhitungan murni berdasarkan tanggal
bookingDate.setHours(0, 0, 0, 0);
today.setHours(0, 0, 0, 0);
// Hitung selisih hari
const diffTime = bookingDate.getTime() - today.getTime();
const diffDays = diffTime / (1000 * 3600 * 24);
// ATURAN: Harus H-3
if (diffDays < 3) {
alert(
`Gagal! Peminjaman di jam khusus (${formData.startTime}) harus dilakukan minimal 3 hari sebelumnya.\n\n` +
`Jarak peminjaman Anda: ${diffDays} hari dari sekarang.`
);
return false;
}
}
return true;
};
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
// Jalankan validasi
if (!validateBookingRules()) return;
setIsLoading(true);
// --- MOCK API CALL ---
console.log("Mengirim Data:", formData);
setTimeout(() => {
alert("Berhasil! Jadwal telah disimpan.");
setIsLoading(false);
// Redirect kembali ke halaman List Booking
router.push("/dashboard/bookings");
}, 1500);
};
return (
<div className="mx-auto max-w-270">
{/* Header Halaman */}
<div className="mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<h2 className="text-2xl font-bold text-black">
Buat Peminjaman Baru
</h2>
<nav>
<ol className="flex items-center gap-2 text-sm">
<li><a className="font-medium text-gray-500" href="/dashboard/bookings">Booking /</a></li>
<li className="font-medium text-yellow-500">Add</li>
</ol>
</nav>
</div>
{/* Form Container */}
<div className="rounded-xl border border-stroke bg-white shadow-sm border-gray-200 dark:bg-boxdark">
<div className="border-b border-stroke py-4 px-6.5 border-gray-200">
<h3 className="font-medium text-black ">
Formulir Pengajuan Jadwal
</h3>
</div>
<form onSubmit={handleSubmit}>
<div className="p-6.5">
{/* --- Baris 1: Ruangan & Tanggal --- */}
<div className="mb-4.5 flex flex-col gap-6 xl:flex-row">
{/* Input Ruangan */}
<div className="w-full xl:w-1/2">
<label className="mb-2.5 block text-black font-medium">
Pilih Ruangan <span className="text-red-500">*</span>
</label>
<div className="relative z-20 bg-white border border-gray-300 text-gray-900 focus:ring-yellow-500">
<select
name="room"
value={formData.room}
onChange={handleChange}
className="relative z-20 w-full appearance-none rounded border border-stroke bg-transparent py-3 px-5 outline-none transition focus:border-yellow-500 active:border-yellow-500 dark:border-form-strokedark dark:bg-form-input dark:focus:border-yellow-500 text-black "
>
<option value="Ruang T-301">Ruang T-301 (Teori)</option>
<option value="Ruang T-302">Ruang T-302 (Teori)</option>
<option value="Lab Kendali">Lab Sistem Kendali</option>
<option value="Lab IoT">Lab IoT & Embedded</option>
<option value="Ruang Sidang">Ruang Sidang TA</option>
</select>
<span className="absolute top-1/2 right-4 z-30 -translate-y-1/2">
<svg className="fill-current" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6.98438 9.98438H17.0156C17.3781 9.98438 17.5656 10.4219 17.3094 10.6781L12.3094 15.6781C12.1406 15.8469 11.8594 15.8469 11.6906 15.6781L6.69062 10.6781C6.43438 10.4219 6.62188 9.98438 6.98438 9.98438Z" fill="gray" /></svg>
</span>
</div>
</div>
{/* Input Tanggal */}
<div className="w-full xl:w-1/2">
<label className="mb-2.5 block text-black font-medium">
Tanggal Peminjaman <span className="text-red-500">*</span>
</label>
<div className="relative">
<input
type="date"
name="date"
required
value={formData.date}
onChange={handleChange}
className="w-full rounded border border-stroke bg-gray-50 py-3 pl-11.5 pr-4.5 text-black focus:border-yellow-500 focus-visible:outline-none border-gray-200 dark:focus:border-yellow-500"
/>
<Calendar className="absolute left-4.5 top-3 text-gray-400" size={20} />
</div>
</div>
</div>
{/* --- Baris 2: Waktu Mulai & Selesai --- */}
<div className="mb-4.5 flex flex-col gap-6 xl:flex-row">
<div className="w-full xl:w-1/2">
<label className="mb-2.5 block text-black font-medium">
Waktu Mulai <span className="text-red-500">*</span>
</label>
<div className="relative">
<input
type="time"
name="startTime"
required
value={formData.startTime}
onChange={handleChange}
className="w-full rounded border border-stroke bg-gray-50 py-3 pl-11.5 pr-4.5 text-black focus:border-yellow-500 focus-visible:outline-none border-gray-200 dark:focus:border-yellow-500"
/>
<Clock className="absolute left-4.5 top-3 text-gray-400" size={20} />
</div>
{/* Info Validasi */}
<p className="mt-2 text-xs text-orange-500 flex items-center gap-1">
<AlertTriangle size={12} />
Peminjaman jam 21:00 - 06:00 wajib H-3.
</p>
</div>
<div className="w-full xl:w-1/2">
<label className="mb-2.5 block text-black font-medium">
Waktu Selesai <span className="text-red-500">*</span>
</label>
<div className="relative">
<input
type="time"
name="endTime"
required
value={formData.endTime}
onChange={handleChange}
className="w-full rounded border border-stroke bg-gray-50 py-3 pl-11.5 pr-4.5 text-black focus:border-yellow-500 focus-visible:outline-none border-gray-200 dark:focus:border-yellow-500"
/>
<Clock className="absolute left-4.5 top-3 text-gray-400" size={20} />
</div>
</div>
</div>
{/* --- Baris 3: Keperluan --- */}
<div className="mb-6">
<label className="mb-2.5 block text-black font-medium">
Keperluan / Mata Kuliah <span className="text-red-500">*</span>
</label>
<textarea
rows={4}
name="purpose"
required
placeholder="Jelaskan keperluan peminjaman ruang..."
value={formData.purpose}
onChange={handleChange}
className="w-full rounded border border-stroke bg-transparent py-3 px-5 text-black outline-none transition focus:border-yellow-500 active:border-yellow-500 dark:border-form-strokedark dark:bg-form-input dark:focus:border-yellow-500"
></textarea>
</div>
{/* --- Tombol Aksi --- */}
<div className="flex gap-4 justify-end">
<button
type="button"
onClick={() => router.push("/dashboard/bookings")}
className="flex items-center justify-center gap-2 rounded border border-stroke py-2.5 px-6 font-medium text-black hover:shadow-1 border-gray-200 transition-all hover:bg-gray-100"
>
<X size={18} />
Batal
</button>
<button
type="submit"
disabled={isLoading}
className={`flex items-center justify-center gap-2 rounded bg-yellow-500 py-2.5 px-6 font-medium text-white hover:bg-yellow-600 transition-all ${
isLoading ? "opacity-70 cursor-not-allowed" : ""
}`}
>
{isLoading ? (
"Menyimpan..."
) : (
<>
<Save size={18} />
Simpan Jadwal
</>
)}
</button>
</div>
</div>
</form>
</div>
</div>
);
}
@@ -0,0 +1,247 @@
"use client";
import { useState } from "react";
import { ChevronLeft, ChevronRight, Calendar as CalendarIcon, Clock, MapPin } from "lucide-react";
// --- Tipe Data Mock ---
type Booking = {
id: number;
room: string;
date: string; // Format YYYY-MM-DD
startTime: string;
endTime: string;
purpose: string;
status: "Approved" | "Pending";
};
// --- Data Dummy (Mock Data) ---
const mockBookings: Booking[] = [
{
id: 1,
room: "Ruang T-301",
date: "2026-02-05",
startTime: "07:30",
endTime: "10:00",
purpose: "Kuliah Sistem Kendali",
status: "Approved",
},
{
id: 2,
room: "Lab IoT",
date: "2026-02-05", // Tanggal sama dengan atas
startTime: "13:00",
endTime: "15:00",
purpose: "Praktikum Embedded System",
status: "Approved",
},
{
id: 3,
room: "Ruang T-302",
date: "2026-02-12",
startTime: "09:00",
endTime: "11:30",
purpose: "Seminar Proposal",
status: "Pending",
},
{
id: 4,
room: "Lab Kendali",
date: "2026-02-20",
startTime: "10:00",
endTime: "12:00",
purpose: "Riset Skripsi",
status: "Approved",
},
];
export default function CalendarPage() {
const [currentDate, setCurrentDate] = useState(new Date(2026, 1)); // Februari 2026
const [selectedDate, setSelectedDate] = useState<string | null>(null);
// --- Helper Functions ---
const getDaysInMonth = (year: number, month: number) => new Date(year, month + 1, 0).getDate();
const getFirstDayOfMonth = (year: number, month: number) => new Date(year, month, 1).getDay();
const handlePrevMonth = () => {
setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() - 1));
setSelectedDate(null);
};
const handleNextMonth = () => {
setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() + 1));
setSelectedDate(null);
};
const handleDateClick = (day: number) => {
const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2, "0");
const dateStr = String(day).padStart(2, "0");
const fullDate = `${year}-${month}-${dateStr}`;
// Toggle seleksi: Jika diklik lagi, tutup detailnya
if (selectedDate === fullDate) {
setSelectedDate(null);
} else {
setSelectedDate(fullDate);
}
};
// --- Generate Calendar Grid ---
const year = currentDate.getFullYear();
const month = currentDate.getMonth();
const daysInMonth = getDaysInMonth(year, month);
const firstDay = getFirstDayOfMonth(year, month);
// Array kosong untuk padding hari sebelum tanggal 1
const emptyDays = Array.from({ length: firstDay }, (_, i) => i);
// Array tanggal 1 sampai akhir bulan
const days = Array.from({ length: daysInMonth }, (_, i) => i + 1);
// Nama Bulan
const monthNames = [
"Januari", "Februari", "Maret", "April", "Mei", "Juni",
"Juli", "Agustus", "September", "Oktober", "November", "Desember"
];
// Filter booking untuk tanggal yang dipilih
const selectedBookings = mockBookings.filter((b) => b.date === selectedDate);
return (
<div className="flex flex-col gap-6 lg:flex-row">
{/* --- KIRI: KALENDER --- */}
<div className="flex-1 rounded-xl border border-stroke bg-white shadow-sm border-gray-200 dark:bg-boxdark">
{/* Header Kalender */}
<div className="flex items-center justify-between border-b border-stroke p-4 border-gray-200 sm:p-6">
<div className="flex items-center gap-2">
<div className="h-10 w-10 flex items-center justify-center rounded-full bg-yellow-50 text-yellow-600">
<CalendarIcon size={20} />
</div>
<div>
<h2 className="text-lg font-bold text-black ">
{monthNames[month]} {year}
</h2>
<p className="text-xs text-gray-500">Pilih tanggal untuk melihat detail.</p>
</div>
</div>
<div className="flex gap-2">
<button onClick={handlePrevMonth} className="p-2 rounded hover:bg-gray-100 dark:hover:bg-meta-4 transition">
<ChevronLeft size={20} />
</button>
<button onClick={handleNextMonth} className="p-2 rounded hover:bg-gray-100 dark:hover:bg-meta-4 transition">
<ChevronRight size={20} />
</button>
</div>
</div>
{/* Grid Kalender */}
<div className="p-4 sm:p-6">
{/* Nama Hari */}
<div className="grid grid-cols-7 mb-2">
{["Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"].map((d) => (
<span key={d} className="text-center text-sm font-medium text-gray-500 py-2">
{d}
</span>
))}
</div>
{/* Tanggal */}
<div className="grid grid-cols-7 gap-2">
{/* Render Empty Cells */}
{emptyDays.map((_, i) => (
<div key={`empty-${i}`} className="h-24 sm:h-32"></div>
))}
{/* Render Date Cells */}
{days.map((day) => {
// Format tanggal hari ini untuk pengecekan data
const currentDayStr = `${year}-${String(month + 1).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
const hasBooking = mockBookings.some((b) => b.date === currentDayStr);
const isSelected = selectedDate === currentDayStr;
return (
<div
key={day}
onClick={() => handleDateClick(day)}
className={`relative flex h-24 sm:h-32 cursor-pointer flex-col justify-between rounded border p-2 transition hover:bg-gray-50 dark:hover:bg-meta-4
${isSelected
? "border-yellow-500 bg-yellow-50 dark:bg-slate-800"
: "border-stroke border-gray-200 bg-white dark:bg-boxdark"
}`}
>
<span className={`text-sm font-medium ${isSelected ? "text-yellow-600" : "text-black "}`}>
{day}
</span>
{/* Indikator Booking (Dot / Bar) */}
{hasBooking && (
<div className="flex flex-col gap-1">
{mockBookings
.filter(b => b.date === currentDayStr)
.slice(0, 2) // Batasi tampilan max 2 baris di grid
.map((b, idx) => (
<div key={idx} className="truncate rounded-sm bg-blue-100 px-1 py-0.5 text-[10px] font-medium text-blue-700 dark:bg-blue-900 dark:text-blue-100">
{b.startTime} - {b.room}
</div>
))}
{mockBookings.filter(b => b.date === currentDayStr).length > 2 && (
<span className="text-[10px] text-gray-400 text-center">+ Lainnya</span>
)}
</div>
)}
</div>
);
})}
</div>
</div>
</div>
{/* --- KANAN: DETAIL SIDEBAR --- */}
{selectedDate && (
<div className="w-full lg:w-80 shrink-0 animate-in fade-in slide-in-from-right duration-300">
<div className="rounded-xl border border-stroke bg-white p-6 shadow-sm border-gray-200 dark:bg-boxdark">
<h3 className="mb-4 text-xl font-bold text-black border-b border-stroke pb-2 border-gray-200">
Jadwal {selectedDate}
</h3>
{selectedBookings.length > 0 ? (
<div className="flex flex-col gap-4">
{selectedBookings.map((booking) => (
<div key={booking.id} className="rounded-lg border border-gray-100 bg-gray-50 p-4 border-gray-200 bg-gray-50">
<div className="flex items-center justify-between mb-2">
<span className={`px-2 py-0.5 rounded text-xs font-medium ${
booking.status === "Approved"
? "bg-green-100 text-green-700"
: "bg-yellow-100 text-yellow-700"
}`}>
{booking.status}
</span>
</div>
<h4 className="font-bold text-black mb-1">{booking.purpose}</h4>
<div className="flex items-center gap-2 text-sm text-gray-500 mt-2">
<MapPin size={16} /> {booking.room}
</div>
<div className="flex items-center gap-2 text-sm text-gray-500 mt-1">
<Clock size={16} /> {booking.startTime} - {booking.endTime}
</div>
</div>
))}
</div>
) : (
<div className="py-10 text-center">
<p className="text-gray-400 text-sm">Tidak ada jadwal pada tanggal ini.</p>
<button className="mt-4 text-sm font-medium text-yellow-600 hover:underline">
+ Tambah Jadwal
</button>
</div>
)}
</div>
</div>
)}
</div>
);
}
+189
View File
@@ -0,0 +1,189 @@
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
export default function BookingPage() {
const router = useRouter();
const [isLoading, setIsLoading] = useState(false);
// State untuk form input
const [formData, setFormData] = useState({
room: "Ruang T-301",
date: "",
startTime: "",
endTime: "",
purpose: "",
});
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => {
setFormData({ ...formData, [e.target.name]: e.target.value });
};
// --- LOGIKA VALIDASI KHUSUS ---
const validateBookingRules = () => {
// 1. Pastikan tanggal dan jam sudah diisi
if (!formData.date || !formData.startTime) {
alert("Mohon lengkapi Tanggal dan Jam Mulai terlebih dahulu.");
return false;
}
// 2. Ambil Jam dari input (Format "HH:mm", kita ambil HH nya saja)
const startHour = parseInt(formData.startTime.split(":")[0]);
// 3. Cek apakah jam termasuk "Jam Khusus" (Diatas 21:00 ATAU Sebelum 06:00)
// Note: startHour >= 21 artinya jam 21:00 ke atas. startHour < 6 artinya jam 00:00 - 05:59
const isSpecialTime = startHour >= 21 || startHour < 6;
if (isSpecialTime) {
// Hitung selisih hari antara HARI INI dan TANGGAL BOOKING
const bookingDate = new Date(formData.date);
const today = new Date();
// Reset jam ke 00:00:00 agar perhitungan murni berdasarkan tanggal
bookingDate.setHours(0, 0, 0, 0);
today.setHours(0, 0, 0, 0);
// Hitung selisih waktu dalam milidetik
const diffTime = bookingDate.getTime() - today.getTime();
// Konversi milidetik ke hari (1 hari = 1000ms * 3600detik * 24jam)
const diffDays = diffTime / (1000 * 3600 * 24);
// ATURAN: Jika selisih kurang dari 3 hari, tolak!
if (diffDays < 3) {
alert(
`Gagal! Peminjaman di jam khusus (${formData.startTime}) harus dilakukan minimal 3 hari sebelumnya.\n\n` +
`Jarak peminjaman Anda: ${diffDays} hari dari sekarang.`
);
return false; // Validasi Gagal
}
}
return true; // Validasi Berhasil
};
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
// Jalankan validasi sebelum proses loading
const isValid = validateBookingRules();
if (!isValid) {
return; // Berhenti di sini jika validasi gagal
}
setIsLoading(true);
// --- LOGIKA SEMENTARA (MOCK) ---
console.log("Data Booking dikirim:", formData);
setTimeout(() => {
alert("Peminjaman Berhasil! Token akses Anda telah dibuat.");
setIsLoading(false);
router.push("/dashboard");
}, 1500);
};
return (
<div className="min-h-screen bg-gray-50 p-6 flex items-center justify-center">
<div className="w-full max-w-lg bg-white rounded-xl shadow-md border border-gray-200 overflow-hidden">
{/* Header Form */}
<div className="bg-yellow-500 px-6 py-4 flex justify-between items-center">
<h1 className="text-xl font-bold text-white">Formulir Peminjaman Ruang</h1>
<button
onClick={() => router.back()}
className="text-white/80 hover:text-white text-sm"
>
&larr; Batal
</button>
</div>
<form onSubmit={handleSubmit} className="p-8 space-y-6">
{/* Pilihan Ruangan */}
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">Pilih Ruangan</label>
<select
name="room"
value={formData.room}
onChange={handleChange}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-yellow-400 outline-none text-gray-900"
>
<option value="Ruang T-301">Ruang T-301 (Teori)</option>
<option value="Ruang T-302">Ruang T-302 (Teori)</option>
<option value="Lab Kendali">Lab Sistem Kendali</option>
<option value="Lab IoT">Lab IoT & Embedded</option>
</select>
</div>
{/* Tanggal */}
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">Tanggal Peminjaman</label>
<input
type="date"
name="date"
required
value={formData.date}
onChange={handleChange}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-yellow-400 outline-none text-gray-900"
/>
</div>
{/* Waktu Mulai & Selesai */}
<div className="grid grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">Waktu Mulai</label>
<input
type="time"
name="startTime"
required
value={formData.startTime}
onChange={handleChange}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-yellow-400 outline-none text-gray-900"
/>
<p className="text-xs text-gray-400 mt-1">*Jam 21:00-06:00 butuh H-3</p>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">Waktu Selesai</label>
<input
type="time"
name="endTime"
required
value={formData.endTime}
onChange={handleChange}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-yellow-400 outline-none text-gray-900"
/>
</div>
</div>
{/* Keperluan */}
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">Keperluan</label>
<textarea
name="purpose"
rows={3}
placeholder="Contoh: Kuliah Pengganti Sistem Kendali Digital"
value={formData.purpose}
onChange={handleChange}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-yellow-400 outline-none text-gray-900"
></textarea>
</div>
{/* Tombol Submit */}
<button
type="submit"
disabled={isLoading}
className={`w-full py-3 rounded-lg text-white font-bold shadow transition-all
${isLoading
? "bg-gray-400 cursor-not-allowed"
: "bg-blue-600 hover:bg-blue-700 active:scale-95"
}`}
>
{isLoading ? "Memproses Jadwal..." : "Ajukan Peminjaman"}
</button>
</form>
</div>
</div>
);
}