Skip to content

Commit

Permalink
Merge pull request #155 from PLADI-ALM/feat/PDW-76-car-booking
Browse files Browse the repository at this point in the history
[PDW-76/feat] 차량 예약
  • Loading branch information
psyeon1120 authored Dec 1, 2023
2 parents 1671da7 + 82574c2 commit a1dde94
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 66 deletions.
33 changes: 29 additions & 4 deletions src/components/resourceBooking/TimeSelector.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from "styled-components"
import React, {useEffect, useState} from "react";
import {ResourceTimeList} from "../../constants/ToggleList";
import {ResourcesAxios} from "../../api/AxiosApi";
import {CarsAxios, ResourcesAxios} from "../../api/AxiosApi";
import {getToken} from "../../utils/IsLoginUtil";
import {basicError} from "../../utils/ErrorHandlerUtil";

Expand Down Expand Up @@ -35,7 +35,7 @@ export const TimeCard = styled.li`
background: #BDBDBD;
cursor: default;
}
&.disabled:hover {
background: #BDBDBD;
color: #4c4c4c;
Expand All @@ -57,7 +57,10 @@ export function TimeSelector(props) {
const [bookedTimes, setBookedTimes] = useState([]);

useEffect(() => {
getResourceBookedDates(currentDate, props.resourceId)
if (props.resourceId)
getResourceBookedDates(currentDate, props.resourceId)
else if (props.carId)
getCarBookedDates(currentDate, props.carId)
}, [currentDate]);

const clickHandler = (time) => {
Expand Down Expand Up @@ -93,6 +96,27 @@ export function TimeSelector(props) {
});
}

const getCarBookedDates = (date, carId) => {
const params = {date: date};
CarsAxios.get(`/${carId}/booking-time`, {
params, headers: {
Authorization: getToken()
}
})
.then((Response) => {
var temp = [];
Response.data.data.map(function (time) {
temp.push(time)
})
setBookedTimes(temp)
})
.catch((Error) => {
basicError(Error)
window.alert("예약 정보를 불러올 수 없습니댜.")
window.history.back()
});
}

return (
<TimeContainer>
{
Expand All @@ -102,7 +126,8 @@ export function TimeSelector(props) {
onMouseOver={() => props.onMouseOver(time, currentDate)}
className={'disabled'}>{time}</TimeCard>)
else
return (<TimeCard onClick={() => clickHandler(time)}>{time}</TimeCard>)
return (<TimeCard onClick={() => clickHandler(time)}
onMouseOver={() => props.onMouseOver(time, null)}>{time}</TimeCard>)
})
}
</TimeContainer>
Expand Down
Loading

0 comments on commit a1dde94

Please sign in to comment.