diff --git a/frontend/src/config/apiConfig.ts b/frontend/src/config/apiConfig.ts index 4a1d9310..6e8094d6 100644 --- a/frontend/src/config/apiConfig.ts +++ b/frontend/src/config/apiConfig.ts @@ -1,4 +1,4 @@ -const API_URL = process.env.REACT_APP_API_URL; +export const API_URL = process.env.REACT_APP_API_URL; export interface BoardReqDto { title: string; diff --git a/frontend/src/pages/SeminarRoom/Reservation.tsx b/frontend/src/pages/SeminarRoom/Reservation.tsx index 460a69d7..0055a3ec 100644 --- a/frontend/src/pages/SeminarRoom/Reservation.tsx +++ b/frontend/src/pages/SeminarRoom/Reservation.tsx @@ -1,6 +1,14 @@ -import { useState } from 'react'; +// 📁 src/pages/SeminarRoom/Reservation.tsx + +import React, { useEffect, useState } from 'react'; +import axios from 'axios'; +import moment, { MomentInput } from 'moment'; import { Container, + HeaderContainer, + Navigation, + NavButton, + NavButtonGroup, RoomContainer, RoomInfo, RoomName, @@ -11,42 +19,42 @@ import { StyledCalendar, } from './ReservationStyle'; import { Modal, useModal } from '../../components/Modal'; -import moment, { MomentInput } from 'moment'; -import styled from 'styled-components'; import { ReservationModal } from './ReservationModal'; import { ReservationData } from './types/reservation.types'; - -// 더미 데이터 -const dummyReservations: ReservationData[] = [ - { - id: 1, - roomId: '세미나실', - date: '2025-01-04', - startTime: '09:00', - endTime: '11:00', - userName: '김철수', - purpose: '세미나', - contact: '010-1234-5678', - department: '컴퓨터공학과', - }, - // ... other dummy data with updated roomId -]; +import {API_URL} from '../../config/apiConfig'; // API 베이스 URI 가져오기 function Reservation() { const { openModal, closeModal } = useModal(); - const [selectedDate, setSelectedDate] = useState( - moment(new Date()).format('YYYY-MM-DD'), - ); + const [selectedDate, setSelectedDate] = useState(moment(new Date()).format('YYYY-MM-DD')); + const [reservations, setReservations] = useState([]); + + // 🧩 GET 요청 함수: API를 통해 해당 월의 예약 데이터 가져오기 + const fetchReservations = async (yearMonth: string) => { + try { + const response = await axios.get(`${API_URL}/room/1/reservation/month`, { + params: { yearMonth }, + }); + setReservations(response.data); + } catch (error) { + console.error('예약 데이터를 가져오는 중 에러 발생:', error); + } + }; + + // 📆 달력 날짜 변경 시 예약 데이터 다시 가져오기 + useEffect(() => { + const yearMonth = moment(selectedDate).format('YYYY-MM'); + fetchReservations(yearMonth); + }, [selectedDate]); const handleReservationClick = () => { openModal( - , + , ); }; @@ -54,154 +62,66 @@ function Reservation() { setSelectedDate(moment(date).format('YYYY-MM-DD')); }; - const List = styled.p<{ className?: string }>` - margin: 0 0 8px 0; - padding: 8px 12px; - color: white; - border-radius: 4px; - - background-color: ${({ className }) => - className === '세미나' - ? '#1a73e8' - : className === '스터디' - ? '#34d399' - : className === '미팅' - ? '#f59e0b' - : '#9ca3af'}; - `; - const tileContent = ({ date }: { date: Date }) => { const formattedDate = moment(date).format('YYYY-MM-DD'); - const reservationsForDate = dummyReservations.filter( - (reservation) => reservation.date === formattedDate, + const reservationsForDate = reservations.filter( + (reservation) => reservation.date === formattedDate, ); if (reservationsForDate.length === 0) return null; - const visibleReservations = reservationsForDate.slice(0, 2); - const moreCount = reservationsForDate.length - visibleReservations.length; - - const showAllReservation = (formattedDate: string) => { - openModal( - <> - - {moment(formattedDate).format('YYYY년 MM월 DD일')} 예약 현황 - - -
- {reservationsForDate.map((reservation, index) => ( - - {reservation.startTime}~{reservation.endTime}{' '} - {reservation.purpose} ({reservation.userName}) - - ))} -
-
- - closeModal()}> - 닫기 - - - , - ); - }; - return ( -
- {visibleReservations.map((reservation, index) => ( -
- {reservation.startTime}~{reservation.endTime} -
- ))} - {moreCount > 0 && ( -
showAllReservation(formattedDate)} - > - {moreCount}개 더보기 -
- )} -
- ); - }; - - const getColorByPurpose = (purpose: string) => { - const colors = { - 세미나: '#1a73e8', - 스터디: '#34d399', - 미팅: '#f59e0b', - 기타: '#9ca3af', - }; - return colors[purpose as keyof typeof colors] || colors.기타; - }; - - const tileClassName = ({ date }: { date: Date }) => { - const formattedDate = moment(date).format('YYYY-MM-DD'); - const hasReservations = dummyReservations.some( - (reservation) => reservation.date === formattedDate, +
+ {reservationsForDate.map((reservation, index) => ( +
+ {reservation.startTime}~{reservation.endTime} +
+ ))} +
); - return hasReservations ? 'has-reservation' : ''; }; return ( - - - - 세미나실 -
-
- -
-
- 수용인원 - 30명 -
- 장소 - 충무관 501호 + + + + + 세미나실1 + + + + + + 세미나실1 +
+
+ +
+
+ 수용인원 + 30명 +
+ 장소 + 충무관 501호 +
-
- - -
- - 예약하기 - -
- moment(date).format('D')} - prev2Label={null} - next2Label={null} - minDetail="year" - onChange={handleDateChange} - tileContent={tileContent} - tileClassName={tileClassName} - minDate={new Date()} - /> - + + +
+ 예약하기 +
+ moment(date).format('D')} + prev2Label={null} + next2Label={null} + minDetail="year" + onChange={handleDateChange} + tileContent={tileContent} + minDate={new Date()} + /> + ); }