Files
hsp-gdh-front/src/components/dashboard/patient/appointment/create/time.jsx

38 lines
1.2 KiB
JavaScript

import { timeStringToFloat, floatToTimeString } from "../../../../../modules/timeManager";
function Time({service,setTime}) {
if(!service) return null;
const openTime = timeStringToFloat(service.open_time);
const closeTime = timeStringToFloat(service.close_time);
const duration = timeStringToFloat(service.duration);
const workTime = closeTime - openTime;
const timeSlots = Math.floor(workTime / duration);
let time = [];
for(let i = 0; i < timeSlots; i++) {
time[i] = openTime + duration * i;
}
const onChange = (e) => {
setTime(e.target.value);
};
return(
<div className="text-xl flex flex-row justify-between items-center">
<label htmlFor="time">Choisissez un horaire :</label>
<select name="time" id="time" className="w-44" onChange={onChange}>
<option value="">Choisir un horaire</option>
{time.map((time,key) => {
const timeStr = floatToTimeString(time);
return <option value={timeStr} key={key}>{timeStr}</option>
})}
</select>
</div>
);
}
export default Time;