import React, { Fragment } from 'react';
import moment from 'moment-with-locales-es6';
import './Days.css';
export const Days = ({choseDateEvent, choseDateStatus, dataTimes}) => {
const arrTimes = dataTimes.data;
const arrayDate = [];
for(let i=0; i<16; i++){
arrayDate.push(i)
}
let startDate = moment().add(1,'days');
let counter = 0;
const availableTime = [];
return <Fragment>
<div className='cardContent'>
<div>
<h2>Выберите дату:</h2>
<div className="row p-4">
{
choseDateStatus
? <Order />
: arrayDate.map((item) => {
return <div key={item} className="card col-3" onClick={() => choseDateEvent()}>
<div className="card-body">
<h5 className="card-title">{startDate.add(1, 'days').locale('ru').format('DD MMMM')}</h5>
<h5 className="card-title">{startDate.locale('ru').format('dddd')}</h5>
{
arrTimes?.map(item => {
const dateTime = item.attributes.datetime;
const date = startDate.locale('ru').format('YYYY-MM-DD');
if (dateTime.includes(date)) {
availableTime.push(dateTime);
return <div key={item.id}>Доступно записей: {++counter}</div>
}
})
}
</div>
</div>
})
}
</div>
</div>
</div>
</Fragment>
}
export const Days = ({ choseDateEvent, choseDateStatus, dataTimes }) => {
const [yourArray, setYourArray] = useState([])
useEffect(() => {
if (choseDateStatus) {
// code when condition true
setYourArray(...) // some array you need
} else {
// code when condition false
setYourArray(...) // some array you need
}
// do re-render when choseDateStatus changed
}, [choseDateStatus])
return (
...
<Order availibleTime={yourArray} />
...
)}