mirror of
https://github.com/Since-3/Kuma.git
synced 2026-10-12 21:41:17 +00:00
added connection to course with room
This commit is contained in:
parent
ea887baa7b
commit
73b1a9f0e1
2 changed files with 38 additions and 10 deletions
|
|
@ -9,6 +9,7 @@ import { Button } from "@/src/components/ui/button";
|
|||
import { Checkbox } from "@/src/components/ui/checkbox";
|
||||
import { Label } from "@/src/components/ui/label";
|
||||
import { createCourse, updateCourse } from "../../actions/course-actions";
|
||||
import { getAllRooms } from "@/src/modules/rooms/actions/room-actions";
|
||||
import { toast } from "sonner";
|
||||
import { Course } from "../../types/course.types";
|
||||
|
||||
|
|
@ -29,14 +30,6 @@ const TRAINERS = [
|
|||
{ value: "trainer4", label: "Lisa Müller" },
|
||||
];
|
||||
|
||||
const ROOMS = [
|
||||
{ value: "room1", label: "Sporthalle 1" },
|
||||
{ value: "room2", label: "Sporthalle 2" },
|
||||
{ value: "room3", label: "Gymnastikraum" },
|
||||
{ value: "room4", label: "Schwimmbad" },
|
||||
{ value: "room5", label: "Tennisplatz" },
|
||||
];
|
||||
|
||||
const FREQUENCIES = [
|
||||
{ value: "daily", label: "Täglich" },
|
||||
{ value: "weekly", label: "Wöchentlich" },
|
||||
|
|
@ -80,6 +73,24 @@ const CourseCreateView = ({
|
|||
const [selectedWeekdays, setSelectedWeekdays] = useState<string[]>([]);
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [rooms, setRooms] = useState<Array<{ value: string; label: string }>>([]);
|
||||
|
||||
// Load rooms from database
|
||||
useEffect(() => {
|
||||
const loadRooms = async () => {
|
||||
const result = await getAllRooms();
|
||||
if (result.success) {
|
||||
const roomOptions = result.rooms.map((room) => ({
|
||||
value: room.id,
|
||||
label: room.name,
|
||||
}));
|
||||
setRooms(roomOptions);
|
||||
} else {
|
||||
toast.error("Fehler beim Laden der Räume");
|
||||
}
|
||||
};
|
||||
loadRooms();
|
||||
}, []);
|
||||
|
||||
// Load initial data when in edit mode
|
||||
useEffect(() => {
|
||||
|
|
@ -260,7 +271,7 @@ const CourseCreateView = ({
|
|||
label="Raum"
|
||||
selected={selectedRoom}
|
||||
onSelect={setSelectedRoom}
|
||||
options={ROOMS}
|
||||
options={rooms}
|
||||
error={errors.room}
|
||||
/>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
"use client";
|
||||
import { useEffect, useState } from "react";
|
||||
import { getMyCourses, deleteCourse } from "../../actions/course-actions";
|
||||
import { getAllRooms } from "@/src/modules/rooms/actions/room-actions";
|
||||
import { Button } from "@/src/components/ui/button";
|
||||
import { toast } from "sonner";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
|
@ -41,6 +42,7 @@ const CourseListView = () => {
|
|||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
const [courseToDelete, setCourseToDelete] = useState<{ id: string; name: string } | null>(null);
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
const [roomsMap, setRoomsMap] = useState<Record<string, string>>({});
|
||||
|
||||
// Date range state for infinite scroll
|
||||
const [loadedDateFrom, setLoadedDateFrom] = useState<Date | null>(null);
|
||||
|
|
@ -50,6 +52,21 @@ const CourseListView = () => {
|
|||
const [hasOlderCourses, setHasOlderCourses] = useState(true);
|
||||
const [hasNewerCourses, setHasNewerCourses] = useState(true);
|
||||
|
||||
// Load rooms once on mount
|
||||
useEffect(() => {
|
||||
const loadRooms = async () => {
|
||||
const result = await getAllRooms();
|
||||
if (result.success) {
|
||||
const map: Record<string, string> = {};
|
||||
result.rooms.forEach((room) => {
|
||||
map[room.id] = room.name;
|
||||
});
|
||||
setRoomsMap(map);
|
||||
}
|
||||
};
|
||||
loadRooms();
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Load courses with optional date range
|
||||
* @param options - Optional date range parameters
|
||||
|
|
@ -442,7 +459,7 @@ const CourseListView = () => {
|
|||
<CourseListItem
|
||||
key={course.id}
|
||||
courseName={course.name}
|
||||
room={course.room}
|
||||
room={roomsMap[course.room] || course.room}
|
||||
time={course.time}
|
||||
currentParticipants={0} // TODO: Implement participant tracking
|
||||
maxParticipants={course.maxParticipants}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue