-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from PLADI-ALM/feat/PDW-75-resource-booking
[PDW-75/feat] 자원 예약
- Loading branch information
Showing
9 changed files
with
324 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import styled from "styled-components" | ||
import React, {useEffect, useState} from "react"; | ||
import {ResourceTimeList} from "../../constants/ToggleList"; | ||
import {ResourcesAxios} from "../../api/AxiosApi"; | ||
import {getToken} from "../../utils/IsLoginUtil"; | ||
import {basicError} from "../../utils/ErrorHandlerUtil"; | ||
|
||
export const TimeContainer = styled.ul` | ||
margin-top: 10px; | ||
overflow-y: scroll; | ||
&::-webkit-scrollbar { | ||
display: flex; | ||
width: 8px; | ||
} | ||
&::-webkit-scrollbar-thumb { | ||
background-color: #BDBDBD; | ||
border-radius: 10px; | ||
} | ||
` | ||
|
||
export const TimeCard = styled.li` | ||
border: 1px solid #BDBDBD; | ||
height: 30px; | ||
width: 100px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
cursor: pointer; | ||
margin-bottom: 5px; | ||
margin-right: 3px; | ||
&.disabled { | ||
background: #BDBDBD; | ||
cursor: default; | ||
} | ||
&.disabled:hover { | ||
background: #BDBDBD; | ||
color: #4c4c4c; | ||
} | ||
&:hover { | ||
background: #8741CB; | ||
color: white; | ||
} | ||
` | ||
|
||
let currentDate = ""; | ||
|
||
export function setDate(date) { | ||
currentDate = date | ||
} | ||
|
||
export function TimeSelector(props) { | ||
const [bookedTimes, setBookedTimes] = useState([]); | ||
|
||
useEffect(() => { | ||
getResourceBookedDates(currentDate, props.resourceId) | ||
}, [currentDate]); | ||
|
||
const clickHandler = (time) => { | ||
props.click(time) | ||
} | ||
|
||
function isTimeMatch(time) { | ||
for (let i = 0; i < bookedTimes.length; i++) { | ||
if (bookedTimes[i] === time) | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
const getResourceBookedDates = (date, resourceId) => { | ||
const params = {date: date}; | ||
ResourcesAxios.get(`/${resourceId}/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> | ||
{ | ||
ResourceTimeList.map(function (time) { | ||
if (isTimeMatch(time)) | ||
return (<TimeCard className={'disabled'}>{time}</TimeCard>) | ||
else | ||
return (<TimeCard onClick={() => clickHandler(time)}>{time}</TimeCard>) | ||
}) | ||
} | ||
</TimeContainer> | ||
) | ||
; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.