update 15 mei
This commit is contained in:
@@ -1,245 +1,149 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import axios from "axios";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Calendar, Clock, Save, X, AlertTriangle } from "lucide-react";
|
||||
import { CalendarPlus, Clock, FileText, MapPin, CheckCircle2 } from "lucide-react";
|
||||
|
||||
export default function AddBookingPage() {
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [rooms, setRooms] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [submitLoading, setSubmitLoading] = useState(false);
|
||||
|
||||
// State untuk form input
|
||||
const [formData, setFormData] = useState({
|
||||
room: "Ruang T-301",
|
||||
date: "",
|
||||
startTime: "",
|
||||
endTime: "",
|
||||
purpose: "",
|
||||
});
|
||||
// State Form
|
||||
const [selectedRoomId, setSelectedRoomId] = useState("");
|
||||
const [startTime, setStartTime] = useState("");
|
||||
const [endTime, setEndTime] = useState("");
|
||||
const [purpose, setPurpose] = useState("");
|
||||
|
||||
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;
|
||||
// Ambil daftar ruangan untuk Dropdown
|
||||
useEffect(() => {
|
||||
const fetchRooms = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem("token");
|
||||
const res = await axios.get("http://localhost:8080/api/rooms", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
setRooms(res.data.data);
|
||||
} catch (error) {
|
||||
console.error("Gagal memuat ruangan", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
fetchRooms();
|
||||
}, []);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!selectedRoomId) return alert("Pilih ruangan terlebih dahulu!");
|
||||
|
||||
// Jalankan validasi
|
||||
if (!validateBookingRules()) return;
|
||||
setSubmitLoading(true);
|
||||
const token = localStorage.getItem("token");
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const startISO = new Date(startTime).toISOString();
|
||||
const endISO = new Date(endTime).toISOString();
|
||||
|
||||
// --- MOCK API CALL ---
|
||||
console.log("Mengirim Data:", formData);
|
||||
await axios.post("http://localhost:8080/api/bookings", {
|
||||
room_id: parseInt(selectedRoomId),
|
||||
start_time: startISO,
|
||||
end_time: endISO,
|
||||
purpose: purpose,
|
||||
}, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
alert("Berhasil! Jadwal telah disimpan.");
|
||||
setIsLoading(false);
|
||||
// Redirect kembali ke halaman List Booking
|
||||
router.push("/dashboard/bookings");
|
||||
}, 1500);
|
||||
alert("Booking Berhasil Diajukan!");
|
||||
router.push("/dashboard/bookings/calendar"); // Arahkan ke jadwal setelah sukses
|
||||
|
||||
} catch (error: any) {
|
||||
alert("GAGAL: " + (error.response?.data?.error || "Terjadi kesalahan"));
|
||||
} finally {
|
||||
setSubmitLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) return <div className="p-8 text-gray-500 font-medium">Memuat formulir...</div>;
|
||||
|
||||
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 className="max-w-3xl mx-auto bg-white rounded-xl shadow-sm border border-gray-100 p-8">
|
||||
<div className="flex items-center gap-3 mb-8 border-b pb-4">
|
||||
<div className="bg-blue-100 p-3 rounded-lg text-blue-600">
|
||||
<CalendarPlus size={28} />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold text-gray-800">Buat Booking Baru</h2>
|
||||
<p className="text-gray-500 text-sm mt-1">Isi detail di bawah ini untuk memesan ruangan kelas S-CLASS.</p>
|
||||
</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>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
{/* Pilih Ruangan */}
|
||||
<div>
|
||||
<label className="block text-sm font-semibold text-gray-700 mb-2">Pilih Ruangan</label>
|
||||
<div className="relative">
|
||||
<MapPin className="absolute left-3 top-3 text-gray-400 h-5 w-5" />
|
||||
<select
|
||||
required
|
||||
className="pl-10 w-full border border-gray-300 rounded-lg p-3 text-sm font-medium focus:ring-2 focus:ring-blue-500 outline-none bg-white appearance-none"
|
||||
value={selectedRoomId}
|
||||
onChange={(e) => setSelectedRoomId(e.target.value)}
|
||||
>
|
||||
<option value="" disabled>-- Pilih Ruangan yang Tersedia --</option>
|
||||
{rooms.map(room => (
|
||||
<option key={room.room_id} value={room.room_id}>
|
||||
{room.name} (Kapasitas: {room.capacity} | {room.floor})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Waktu Mulai & Selesai (Grid 2 Kolom) */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label className="block text-sm font-semibold text-gray-700 mb-2">Waktu Mulai</label>
|
||||
<div className="relative">
|
||||
<Clock className="absolute left-3 top-3 text-gray-400 h-5 w-5" />
|
||||
<input type="datetime-local" required
|
||||
className="pl-10 w-full border border-gray-300 rounded-lg p-3 text-sm focus:ring-2 focus:ring-blue-500 outline-none"
|
||||
value={startTime} onChange={(e) => setStartTime(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-semibold text-gray-700 mb-2">Waktu Selesai</label>
|
||||
<div className="relative">
|
||||
<Clock className="absolute left-3 top-3 text-gray-400 h-5 w-5" />
|
||||
<input type="datetime-local" required
|
||||
className="pl-10 w-full border border-gray-300 rounded-lg p-3 text-sm focus:ring-2 focus:ring-blue-500 outline-none"
|
||||
value={endTime} onChange={(e) => setEndTime(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Keperluan */}
|
||||
<div>
|
||||
<label className="block text-sm font-semibold text-gray-700 mb-2">Keperluan Kegiatan</label>
|
||||
<div className="relative">
|
||||
<FileText className="absolute left-3 top-3 text-gray-400 h-5 w-5" />
|
||||
<textarea required rows={4} placeholder="Jelaskan keperluan peminjaman ruangan ini..."
|
||||
className="pl-10 w-full border border-gray-300 rounded-lg p-3 text-sm focus:ring-2 focus:ring-blue-500 outline-none"
|
||||
value={purpose} onChange={(e) => setPurpose(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" disabled={submitLoading}
|
||||
className={`w-full flex items-center justify-center gap-2 py-3.5 rounded-lg text-white font-bold transition-all shadow-sm
|
||||
${submitLoading ? 'bg-blue-400 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-700'}`}
|
||||
>
|
||||
{submitLoading ? 'Memproses...' : <><CheckCircle2 size={20} /> Ajukan Booking Sekarang</>}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,246 +1,225 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { ChevronLeft, ChevronRight, Calendar as CalendarIcon, Clock, MapPin } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import axios from "axios";
|
||||
import { CalendarDays, MapPin, Clock, ChevronLeft, ChevronRight, Calendar as CalendarIcon } 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";
|
||||
};
|
||||
export default function CalendarViewPage() {
|
||||
const [bookings, setBookings] = useState<any[]>([]);
|
||||
const [rooms, setRooms] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
// --- 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",
|
||||
},
|
||||
];
|
||||
// --- STATE UNTUK NAVIGASI MINGGU ---
|
||||
const [startDate, setStartDate] = useState(() => {
|
||||
const d = new Date();
|
||||
d.setHours(0, 0, 0, 0);
|
||||
return d;
|
||||
});
|
||||
|
||||
export default function CalendarPage() {
|
||||
const [currentDate, setCurrentDate] = useState(new Date(2026, 1)); // Februari 2026
|
||||
const [selectedDate, setSelectedDate] = useState<string | null>(null);
|
||||
// Generate 7 Hari ke depan berdasarkan startDate
|
||||
const weekDates = Array.from({ length: 7 }).map((_, i) => {
|
||||
const d = new Date(startDate);
|
||||
d.setDate(startDate.getDate() + i);
|
||||
return d;
|
||||
});
|
||||
|
||||
// --- 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();
|
||||
// FORMAT RENTANG TANGGAL
|
||||
const firstDay = weekDates[0].toLocaleDateString('id-ID', { day: 'numeric', month: 'short' });
|
||||
const lastDay = weekDates[6].toLocaleDateString('id-ID', { day: 'numeric', month: 'short', year: 'numeric' });
|
||||
const dateRangeLabel = `${firstDay} - ${lastDay}`;
|
||||
|
||||
const handlePrevMonth = () => {
|
||||
setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() - 1));
|
||||
setSelectedDate(null);
|
||||
// Fungsi Navigasi
|
||||
const goToPreviousWeek = () => {
|
||||
setStartDate(prev => {
|
||||
const newDate = new Date(prev);
|
||||
newDate.setDate(prev.getDate() - 7);
|
||||
return newDate;
|
||||
});
|
||||
};
|
||||
|
||||
const handleNextMonth = () => {
|
||||
setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() + 1));
|
||||
setSelectedDate(null);
|
||||
const goToNextWeek = () => {
|
||||
setStartDate(prev => {
|
||||
const newDate = new Date(prev);
|
||||
newDate.setDate(prev.getDate() + 7);
|
||||
return newDate;
|
||||
});
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
const goToToday = () => {
|
||||
const d = new Date();
|
||||
d.setHours(0, 0, 0, 0);
|
||||
setStartDate(d);
|
||||
};
|
||||
// ------------------------------------------
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem("token");
|
||||
const [roomsRes, bookingsRes] = await Promise.all([
|
||||
axios.get("http://localhost:8080/api/rooms", { headers: { Authorization: `Bearer ${token}` } }),
|
||||
axios.get("http://localhost:8080/api/bookings", { headers: { Authorization: `Bearer ${token}` } })
|
||||
]);
|
||||
|
||||
setRooms(roomsRes.data.data || []);
|
||||
setBookings(bookingsRes.data.data || []);
|
||||
} catch (error) {
|
||||
console.error("Gagal memuat data", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
// Fungsi memfilter booking
|
||||
const getBookingsForCell = (roomId: number, dateObj: Date) => {
|
||||
return bookings.filter(b => {
|
||||
if (b.room_id !== roomId) return false;
|
||||
const bDate = new Date(b.start_time);
|
||||
return (
|
||||
bDate.getDate() === dateObj.getDate() &&
|
||||
bDate.getMonth() === dateObj.getMonth() &&
|
||||
bDate.getFullYear() === dateObj.getFullYear()
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
// --- 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);
|
||||
// Format Jam
|
||||
const formatTime = (isoString: string) => {
|
||||
return new Date(isoString).toLocaleTimeString('id-ID', { hour: '2-digit', minute: '2-digit' });
|
||||
};
|
||||
|
||||
// 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);
|
||||
if (loading) return <div className="p-8 text-gray-500 font-medium">Menyusun matriks jadwal...</div>;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6 lg:flex-row">
|
||||
<div className="w-full">
|
||||
|
||||
{/* --- 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>
|
||||
{/* HEADER & NAVIGASI */}
|
||||
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4 mb-8">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="bg-blue-100 p-3 rounded-lg text-blue-600">
|
||||
<CalendarDays size={28} />
|
||||
</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>
|
||||
<h2 className="text-2xl font-bold text-gray-800">Weekly Calendar View</h2>
|
||||
<p className="text-gray-500 text-sm mt-1">Pantau kepadatan jadwal ruangan S-CLASS.</p>
|
||||
</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>
|
||||
{/* Kontrol Navigasi Minggu */}
|
||||
<div className="flex items-center bg-white border border-gray-200 rounded-lg p-1 shadow-sm w-fit">
|
||||
<button
|
||||
onClick={goToPreviousWeek}
|
||||
className="p-2 hover:bg-gray-100 rounded-md transition-colors text-gray-600 hover:text-blue-600 shrink-0"
|
||||
title="Minggu Sebelumnya"
|
||||
>
|
||||
<ChevronLeft size={20} />
|
||||
</button>
|
||||
|
||||
<div className="w-px h-6 bg-gray-200 mx-1"></div>
|
||||
|
||||
{/* TULISAN RENTANG TANGGAL DINAMIS (Lebar Fix w-44 untuk menghilangkan warning Tailwind) */}
|
||||
<button
|
||||
onClick={goToToday}
|
||||
title="Kembali ke minggu ini"
|
||||
className="w-44 py-2 hover:bg-gray-100 rounded-md transition-colors text-sm font-semibold text-gray-700 hover:text-blue-600 flex items-center justify-center gap-2"
|
||||
>
|
||||
<CalendarIcon size={16} className="shrink-0" />
|
||||
<span className="truncate">{dateRangeLabel}</span>
|
||||
</button>
|
||||
|
||||
{/* 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>
|
||||
))}
|
||||
<div className="w-px h-6 bg-gray-200 mx-1"></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>
|
||||
<button
|
||||
onClick={goToNextWeek}
|
||||
className="p-2 hover:bg-gray-100 rounded-md transition-colors text-gray-600 hover:text-blue-600 shrink-0"
|
||||
title="Minggu Depan"
|
||||
>
|
||||
<ChevronRight size={20} />
|
||||
</button>
|
||||
</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>
|
||||
{/* Pembungkus Tabel */}
|
||||
<div className="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden relative">
|
||||
<div className="overflow-x-auto">
|
||||
{/* Lebar tabel dipertahankan menggunakan min-w-[1000px] karena ini ukuran presisi khusus */}
|
||||
<table className="w-full min-w-250 text-left border-collapse">
|
||||
|
||||
{/* HEADER TABEL: Sumbu X (Tanggal) */}
|
||||
<thead className="bg-gray-50">
|
||||
<tr>
|
||||
<th className="sticky left-0 z-10 bg-gray-50 border-b border-r border-gray-200 p-4 font-bold text-gray-700 w-48 shadow-[2px_0_5px_-2px_rgba(0,0,0,0.1)]">
|
||||
<div className="flex items-center gap-2">
|
||||
<MapPin size={18} className="text-blue-500" /> Ruangan
|
||||
</div>
|
||||
</th>
|
||||
|
||||
{weekDates.map((date, idx) => (
|
||||
<th key={idx} className="border-b border-gray-200 p-4 min-w-50 text-center">
|
||||
<div className="font-bold text-gray-800">
|
||||
{date.toLocaleDateString('id-ID', { weekday: 'long' })}
|
||||
</div>
|
||||
<div className="text-xs font-medium text-gray-500 mt-0.5">
|
||||
{date.toLocaleDateString('id-ID', { day: 'numeric', month: 'short', year: 'numeric' })}
|
||||
</div>
|
||||
</th>
|
||||
))}
|
||||
</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>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
{/* BODY TABEL: Sumbu Y (Ruangan) */}
|
||||
<tbody>
|
||||
{rooms.map((room) => (
|
||||
<tr key={room.room_id} className="hover:bg-blue-50/30 transition-colors">
|
||||
|
||||
<td className="sticky left-0 z-10 bg-white border-b border-r border-gray-200 p-4 shadow-[2px_0_5px_-2px_rgba(0,0,0,0.1)] group-hover:bg-blue-50/30 transition-colors">
|
||||
<div className="font-bold text-gray-800">{room.name}</div>
|
||||
<div className="text-xs text-gray-500">{room.category}</div>
|
||||
</td>
|
||||
|
||||
{weekDates.map((date, idx) => {
|
||||
const dailyBookings = getBookingsForCell(room.room_id, date);
|
||||
|
||||
return (
|
||||
<td key={idx} className="border-b border-gray-100 border-r border-r-gray-50 p-2 align-top">
|
||||
{dailyBookings.length > 0 ? (
|
||||
<div className="space-y-2">
|
||||
{dailyBookings.map((b, i) => (
|
||||
<div key={i} className={`border rounded-md p-2 shadow-sm border-l-4
|
||||
${b.status === 'Approved' ? 'bg-green-50 border-green-200 border-l-green-500' :
|
||||
b.status === 'Pending' ? 'bg-yellow-50 border-yellow-200 border-l-yellow-500' :
|
||||
'bg-blue-50 border-blue-200 border-l-blue-500'}`}>
|
||||
<p className="text-xs font-bold text-gray-800 truncate" title={b.purpose}>
|
||||
{b.purpose}
|
||||
</p>
|
||||
<div className="flex flex-wrap items-center gap-1 text-[10px] text-gray-600 font-semibold mt-1">
|
||||
<Clock size={10} />
|
||||
{formatTime(b.start_time)} - {formatTime(b.end_time)}
|
||||
<span className="ml-auto text-[9px] uppercase bg-white/60 px-1 rounded border border-gray-100">
|
||||
{b.status || 'Pending'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="h-full w-full min-h-10 flex items-center justify-center text-gray-300 text-xs">
|
||||
-
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,26 +1,128 @@
|
||||
import Header from "@/components/Header";
|
||||
import Sidebar from "@/components/Sidebar";
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useRouter, usePathname } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
LogOut,
|
||||
LayoutDashboard,
|
||||
CalendarPlus,
|
||||
CalendarDays
|
||||
} from "lucide-react";
|
||||
|
||||
export default function DashboardLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="dark:bg-boxdark-2 bg-gray-100 min-h-screen">
|
||||
<div className="flex h-screen overflow-hidden">
|
||||
{/* Sidebar akan tampil di sini */}
|
||||
<Sidebar />
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const [user, setUser] = useState<any>(null);
|
||||
|
||||
{/* Area Konten Utama */}
|
||||
<div className="relative flex flex-1 flex-col overflow-y-auto overflow-x-hidden">
|
||||
<Header />
|
||||
<main>
|
||||
<div className="mx-auto max-w-screen-2xl p-4 md:p-6 2xl:p-10">
|
||||
{children}
|
||||
</div>
|
||||
</main>
|
||||
useEffect(() => {
|
||||
const userData = localStorage.getItem("user");
|
||||
if (userData) {
|
||||
setUser(JSON.parse(userData));
|
||||
} else {
|
||||
router.push("/login");
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("user");
|
||||
router.push("/login");
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-white flex flex-col font-sans">
|
||||
|
||||
{/* HEADER TINGKAT ATAS */}
|
||||
<header className="bg-[#e5e7eb] flex items-center justify-between px-6 py-4 shadow-sm z-20 relative">
|
||||
{/* Logo Kiri */}
|
||||
<div>
|
||||
<h2 className="text-blue-600 text-sm font-medium mb-1">Welcome to,</h2>
|
||||
<h1 className="text-blue-600 text-3xl font-bold">S-CLASS</h1>
|
||||
</div>
|
||||
|
||||
{/* Profil & Logout Kanan */}
|
||||
<div className="flex items-center gap-8">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="bg-blue-600 text-white rounded-full h-10 w-10 flex items-center justify-center text-lg font-bold shadow-sm">
|
||||
{user?.full_name ? user.full_name.charAt(0).toUpperCase() : "V"}
|
||||
</div>
|
||||
<div className="hidden sm:flex flex-col">
|
||||
<span className="font-semibold text-gray-800 text-sm">
|
||||
{user?.full_name || "Valentino Heman Budiarto"}
|
||||
</span>
|
||||
<span className="font-medium text-gray-500 text-xs capitalize">
|
||||
{user?.role === 'admin' ? 'Administrator' : 'Mahasiswa'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="flex items-center gap-2 text-red-500 font-medium hover:text-red-600 transition-colors"
|
||||
>
|
||||
Log Out <LogOut size={20} />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* AREA BAWAH (SIDEBAR + KONTEN) */}
|
||||
<div className="flex flex-1 overflow-hidden relative">
|
||||
|
||||
{/* SIDEBAR KIRI (Kini Permanen/Statis) */}
|
||||
<aside className="bg-[#b0c4d9] w-64 flex flex-col py-10 shadow-inner z-10">
|
||||
<nav className="flex flex-col gap-6 px-4">
|
||||
|
||||
{/* Menu 1: View Rooms */}
|
||||
<Link
|
||||
href="/dashboard"
|
||||
className={`flex items-center gap-4 cursor-pointer font-semibold transition-colors group
|
||||
${pathname === '/dashboard' ? 'text-blue-700' : 'text-gray-800 hover:text-blue-700'}`}
|
||||
>
|
||||
<div className={`p-2 rounded-lg transition-colors
|
||||
${pathname === '/dashboard' ? 'bg-white/60 shadow-sm' : 'bg-white/30 group-hover:bg-white/50'}`}>
|
||||
<LayoutDashboard size={22} />
|
||||
</div>
|
||||
<span>View Rooms</span>
|
||||
</Link>
|
||||
|
||||
{/* Menu 2: Add Booking */}
|
||||
<Link
|
||||
href="/dashboard/bookings/add"
|
||||
className={`flex items-center gap-4 cursor-pointer font-semibold transition-colors group
|
||||
${pathname === '/dashboard/bookings/add' ? 'text-blue-700' : 'text-gray-800 hover:text-blue-700'}`}
|
||||
>
|
||||
<div className={`p-2 rounded-lg transition-colors
|
||||
${pathname === '/dashboard/bookings/add' ? 'bg-white/60 shadow-sm' : 'bg-white/30 group-hover:bg-white/50'}`}>
|
||||
<CalendarPlus size={22} />
|
||||
</div>
|
||||
<span>Add Booking</span>
|
||||
</Link>
|
||||
|
||||
{/* Menu 3: Calendar View */}
|
||||
<Link
|
||||
href="/dashboard/bookings/calendar"
|
||||
className={`flex items-center gap-4 cursor-pointer font-semibold transition-colors group
|
||||
${pathname === '/dashboard/bookings/calendar' ? 'text-blue-700' : 'text-gray-800 hover:text-blue-700'}`}
|
||||
>
|
||||
<div className={`p-2 rounded-lg transition-colors
|
||||
${pathname === '/dashboard/bookings/calendar' ? 'bg-white/60 shadow-sm' : 'bg-white/30 group-hover:bg-white/50'}`}>
|
||||
<CalendarDays size={22} />
|
||||
</div>
|
||||
<span>Calendar View</span>
|
||||
</Link>
|
||||
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
{/* KONTEN UTAMA */}
|
||||
<main className="flex-1 overflow-y-auto bg-[#f8fafc] p-8">
|
||||
{children}
|
||||
</main>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import axios from "axios";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { LogOut, MapPin, Users, Calendar, X, Clock, FileText } from "lucide-react";
|
||||
import { MapPin, Users, Calendar, X, Clock, FileText } from "lucide-react";
|
||||
|
||||
// Tipe Data
|
||||
interface Room {
|
||||
@@ -57,12 +57,6 @@ export default function Dashboard() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("user");
|
||||
router.push("/login");
|
||||
};
|
||||
|
||||
// --- BUKA MODAL ---
|
||||
const openBookingModal = (room: Room) => {
|
||||
setSelectedRoom(room);
|
||||
@@ -81,8 +75,6 @@ export default function Dashboard() {
|
||||
const token = localStorage.getItem("token");
|
||||
|
||||
try {
|
||||
// Perlu convert string datetime-local ke Format ISO string (RFC3339) buat Golang
|
||||
// Contoh input: "2026-02-06T14:30" -> Output: "2026-02-06T14:30:00.000Z"
|
||||
const startISO = new Date(startTime).toISOString();
|
||||
const endISO = new Date(endTime).toISOString();
|
||||
|
||||
@@ -103,7 +95,6 @@ export default function Dashboard() {
|
||||
setIsModalOpen(false); // Tutup modal
|
||||
|
||||
} catch (error: any) {
|
||||
// Tangkap error dari Backend (Misal: Bentrok / 409 Conflict)
|
||||
const errorMsg = error.response?.data?.error || "Gagal melakukan booking.";
|
||||
alert("GAGAL: " + errorMsg);
|
||||
} finally {
|
||||
@@ -114,78 +105,64 @@ export default function Dashboard() {
|
||||
if (loading) return <div className="p-10 text-center">Memuat data...</div>;
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50 relative">
|
||||
{/* Navbar */}
|
||||
<nav className="bg-white shadow-sm px-6 py-4 flex justify-between items-center sticky top-0 z-10">
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-blue-600">S-CLASS</h1>
|
||||
<p className="text-xs text-gray-500">Welcome, {user?.full_name}</p>
|
||||
</div>
|
||||
<div className="flex gap-4">
|
||||
{/* Tombol Cek History (Nanti kita buat halamannya) */}
|
||||
<button
|
||||
onClick={() => router.push('/history')}
|
||||
className="text-sm text-gray-600 hover:text-blue-600 font-medium"
|
||||
>
|
||||
Riwayat Saya
|
||||
</button>
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="flex items-center gap-2 text-sm text-red-500 hover:bg-red-50 px-3 py-2 rounded-lg transition"
|
||||
>
|
||||
<LogOut size={16} /> Keluar
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{/* Konten Utama */}
|
||||
<main className="max-w-6xl mx-auto p-6">
|
||||
<h2 className="text-2xl font-bold text-gray-800 mb-6">Pilih Ruangan</h2>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{rooms.map((room) => (
|
||||
<div key={room.room_id} className="bg-white rounded-xl shadow-sm border border-gray-100 p-5 flex flex-col justify-between">
|
||||
<div>
|
||||
<div className="flex justify-between items-start mb-3">
|
||||
<span className={`px-2 py-1 text-xs font-semibold rounded-full ${
|
||||
room.status === 'Available' ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'
|
||||
}`}>
|
||||
{room.status}
|
||||
</span>
|
||||
<span className="text-gray-400 text-xs">{room.category}</span>
|
||||
</div>
|
||||
<h3 className="text-lg font-bold text-gray-800 mb-1">{room.name}</h3>
|
||||
<div className="space-y-2 text-sm text-gray-600 mt-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<MapPin size={16} className="text-blue-400" /> {room.floor}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Users size={16} className="text-blue-400" /> Kapasitas: {room.capacity}
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
|
||||
{/* Header Konten: Judul & Tombol Riwayat */}
|
||||
<div className="flex items-center justify-between mb-8">
|
||||
<h2 className="text-2xl font-bold text-gray-800">Pilih Ruangan</h2>
|
||||
<button
|
||||
onClick={() => router.push('/history')}
|
||||
className="flex items-center gap-2 bg-white border border-gray-300 text-gray-700 hover:bg-blue-50 hover:text-blue-600 hover:border-blue-300 px-4 py-2 rounded-lg text-sm font-medium shadow-sm transition-all"
|
||||
>
|
||||
<Clock size={18} />
|
||||
Lihat Riwayat Booking
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Grid Daftar Kelas */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{rooms.map((room) => (
|
||||
<div key={room.room_id} className="bg-white rounded-xl shadow-sm border border-gray-100 p-5 flex flex-col justify-between hover:shadow-md transition-shadow">
|
||||
<div>
|
||||
<div className="flex justify-between items-start mb-3">
|
||||
<span className={`px-2 py-1 text-xs font-semibold rounded-full ${
|
||||
room.status === 'Available' ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'
|
||||
}`}>
|
||||
{room.status}
|
||||
</span>
|
||||
<span className="text-gray-400 text-xs font-medium">{room.category}</span>
|
||||
</div>
|
||||
<h3 className="text-lg font-bold text-gray-800 mb-1">{room.name}</h3>
|
||||
<div className="space-y-2 text-sm text-gray-600 mt-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<MapPin size={16} className="text-blue-500" /> {room.floor}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Users size={16} className="text-blue-500" /> Kapasitas: {room.capacity}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
className="mt-5 w-full bg-blue-600 text-white py-2 rounded-lg hover:bg-blue-700 transition flex justify-center items-center gap-2"
|
||||
onClick={() => openBookingModal(room)}
|
||||
>
|
||||
<Calendar size={16} />
|
||||
Booking Ruangan
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<button
|
||||
className="mt-6 w-full bg-blue-600 text-white font-medium py-2 rounded-lg hover:bg-blue-700 transition flex justify-center items-center gap-2 shadow-sm"
|
||||
onClick={() => openBookingModal(room)}
|
||||
>
|
||||
<Calendar size={16} />
|
||||
Booking Ruangan
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* --- MODAL POPUP FORMULIR --- */}
|
||||
{isModalOpen && selectedRoom && (
|
||||
<div className="fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4">
|
||||
<div className="bg-white rounded-2xl w-full max-w-md shadow-2xl overflow-hidden">
|
||||
<div className="fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4 backdrop-blur-sm">
|
||||
<div className="bg-white rounded-2xl w-full max-w-md shadow-xl overflow-hidden border border-gray-100">
|
||||
|
||||
{/* Header Modal */}
|
||||
<div className="bg-blue-600 p-4 flex justify-between items-center text-white">
|
||||
<h3 className="font-bold text-lg">Form Peminjaman</h3>
|
||||
<button onClick={() => setIsModalOpen(false)} className="hover:bg-blue-700 p-1 rounded">
|
||||
<h3 className="font-semibold text-lg">Form Peminjaman</h3>
|
||||
<button onClick={() => setIsModalOpen(false)} className="hover:bg-blue-700 p-1 rounded-lg transition-colors">
|
||||
<X size={20} />
|
||||
</button>
|
||||
</div>
|
||||
@@ -194,7 +171,7 @@ export default function Dashboard() {
|
||||
<form onSubmit={handleBookingSubmit} className="p-6 space-y-4">
|
||||
<div className="bg-blue-50 p-3 rounded-lg border border-blue-100 mb-2">
|
||||
<p className="text-sm text-blue-800 font-semibold">Ruangan: {selectedRoom.name}</p>
|
||||
<p className="text-xs text-blue-600">{selectedRoom.floor}</p>
|
||||
<p className="text-xs text-blue-600 mt-0.5">{selectedRoom.floor}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -204,7 +181,7 @@ export default function Dashboard() {
|
||||
<input
|
||||
type="datetime-local"
|
||||
required
|
||||
className="pl-9 w-full border border-gray-300 rounded-lg p-2 text-sm focus:ring-blue-500 focus:border-blue-500"
|
||||
className="pl-9 w-full border border-gray-300 rounded-lg p-2 text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none transition-all"
|
||||
value={startTime}
|
||||
onChange={(e) => setStartTime(e.target.value)}
|
||||
/>
|
||||
@@ -218,7 +195,7 @@ export default function Dashboard() {
|
||||
<input
|
||||
type="datetime-local"
|
||||
required
|
||||
className="pl-9 w-full border border-gray-300 rounded-lg p-2 text-sm focus:ring-blue-500 focus:border-blue-500"
|
||||
className="pl-9 w-full border border-gray-300 rounded-lg p-2 text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none transition-all"
|
||||
value={endTime}
|
||||
onChange={(e) => setEndTime(e.target.value)}
|
||||
/>
|
||||
@@ -228,30 +205,30 @@ export default function Dashboard() {
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Keperluan / Kegiatan</label>
|
||||
<div className="relative">
|
||||
<FileText className="absolute left-3 top-3 text-gray-400 h-4 w-4" />
|
||||
<FileText className="absolute left-3 top-2.5 text-gray-400 h-4 w-4" />
|
||||
<textarea
|
||||
required
|
||||
rows={3}
|
||||
placeholder="Contoh: Rapat Progres Skripsi"
|
||||
className="pl-9 w-full border border-gray-300 rounded-lg p-2 text-sm focus:ring-blue-500 focus:border-blue-500"
|
||||
className="pl-9 w-full border border-gray-300 rounded-lg p-2 text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none transition-all"
|
||||
value={purpose}
|
||||
onChange={(e) => setPurpose(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-2 flex gap-3">
|
||||
<div className="pt-3 flex gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsModalOpen(false)}
|
||||
className="flex-1 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 text-sm font-medium"
|
||||
className="flex-1 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 text-sm font-medium transition-all"
|
||||
>
|
||||
Batal
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={submitLoading}
|
||||
className={`flex-1 py-2 rounded-lg text-white text-sm font-medium
|
||||
className={`flex-1 py-2 rounded-lg text-white text-sm font-medium shadow-sm transition-all
|
||||
${submitLoading ? 'bg-blue-400 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-700'}`}
|
||||
>
|
||||
{submitLoading ? 'Mengirim...' : 'Ajukan Booking'}
|
||||
@@ -263,4 +240,4 @@ export default function Dashboard() {
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user