|
| 1 | +import { Card, Radio } from 'antd'; |
| 2 | +import { useState, useEffect } from 'react'; |
| 3 | +import { parentDummyData } from '../../../parentDummyData'; |
| 4 | +import { LeftOutlined, RightOutlined } from '@ant-design/icons'; |
| 5 | + |
| 6 | +// const defaultValues = { |
| 7 | +// program: '', |
| 8 | +// course: '', |
| 9 | +// date: '', |
| 10 | +// }; |
| 11 | +const BookingProgram = ({ handleRadioClick, disabled }) => { |
| 12 | + const [index, setIndex] = useState(0); |
| 13 | + // const [userChoice, setUserChoice] = useState(defaultValues); |
| 14 | + // const [disabled, setDisabled] = useState(false); |
| 15 | + // const toggleDisabled = () => { |
| 16 | + // setDisabled(!disabled); |
| 17 | + // }; |
| 18 | + |
| 19 | + const subjectsArray = [ |
| 20 | + ...new Set( |
| 21 | + parentDummyData.availableCourses.map(course => { |
| 22 | + return course.subject; |
| 23 | + }) |
| 24 | + ), |
| 25 | + ]; |
| 26 | + |
| 27 | + let selectProgramArray = subjectsArray.slice(index, index + 3); |
| 28 | + |
| 29 | + useEffect(() => { |
| 30 | + const lastIndex = subjectsArray.length - 1; |
| 31 | + if (index < 0) { |
| 32 | + setIndex(lastIndex); |
| 33 | + } |
| 34 | + if (index > lastIndex) { |
| 35 | + setIndex(0); |
| 36 | + } |
| 37 | + }, [index, subjectsArray]); |
| 38 | + |
| 39 | + // const handleRadioClick = e => { |
| 40 | + // setUserChoice({ program: e.target.value }); |
| 41 | + // console.log(userChoice); |
| 42 | + // }; |
| 43 | + // const handleCalendarClick = e => { |
| 44 | + // setUserChoice({ date: e.target.value }); |
| 45 | + // console.log(userChoice); |
| 46 | + // }; |
| 47 | + |
| 48 | + // const handleTime = e => { |
| 49 | + // setUserChoice({ time: e.target.value }); |
| 50 | + // console.log(userChoice); |
| 51 | + // }; |
| 52 | + |
| 53 | + return ( |
| 54 | + <> |
| 55 | + <div style={{ display: 'flex' }}> |
| 56 | + <button |
| 57 | + style={{ background: 'none' }} |
| 58 | + onClick={() => { |
| 59 | + if (index > 0) { |
| 60 | + setIndex(index - 1); |
| 61 | + } else if (index === 0) { |
| 62 | + setIndex(subjectsArray.length - 3); |
| 63 | + } |
| 64 | + }} |
| 65 | + > |
| 66 | + <LeftOutlined style={{ color: '#4a1e3c' }} /> |
| 67 | + </button> |
| 68 | + |
| 69 | + <Radio.Group |
| 70 | + style={{ |
| 71 | + width: '60vw', |
| 72 | + backgroundColor: '#eeedd9', |
| 73 | + }} |
| 74 | + > |
| 75 | + <div style={{ display: 'flex', overflow: 'hidden' }}> |
| 76 | + {selectProgramArray.map((subject, index) => { |
| 77 | + return ( |
| 78 | + <Card |
| 79 | + style={{ |
| 80 | + padding: '5px 0 5px 5px', |
| 81 | + background: '#f35f24', |
| 82 | + alignItems: 'center', |
| 83 | + minWidth: '250px', |
| 84 | + flex: '1 ', |
| 85 | + margin: '0 10px', |
| 86 | + }} |
| 87 | + > |
| 88 | + <Radio |
| 89 | + onChange={handleRadioClick} |
| 90 | + disabled={disabled} |
| 91 | + value={subject} |
| 92 | + key={index} |
| 93 | + name="program" |
| 94 | + style={{ fontSize: '20px' }} |
| 95 | + > |
| 96 | + {subject} |
| 97 | + </Radio> |
| 98 | + </Card> |
| 99 | + ); |
| 100 | + })} |
| 101 | + </div> |
| 102 | + </Radio.Group> |
| 103 | + |
| 104 | + <button |
| 105 | + style={{ background: 'none' }} |
| 106 | + onClick={() => { |
| 107 | + if (index !== subjectsArray.length - 3) { |
| 108 | + setIndex(index + 1); |
| 109 | + } else if (index === subjectsArray.length - 3) { |
| 110 | + setIndex(0); |
| 111 | + } |
| 112 | + }} |
| 113 | + > |
| 114 | + <RightOutlined style={{ color: '#4a1e3c', fontWeight: 'bold' }} /> |
| 115 | + </button> |
| 116 | + </div> |
| 117 | + </> |
| 118 | + ); |
| 119 | +}; |
| 120 | + |
| 121 | +export default BookingProgram; |
| 122 | + |
| 123 | +// const startTimes = parentDummyData.availableCourses.map( |
| 124 | +// time => time.start_time |
| 125 | +// ); |
| 126 | + |
| 127 | +// const endTimes = parentDummyData.availableCourses.map(time => time.end_time); |
| 128 | +// let durationArr = []; |
| 129 | +// let duration = ''; |
| 130 | +// const [durations, setDurations] = useState([]); |
| 131 | +// const generateDurationArr = () => { |
| 132 | +// for (let i = 0; i < endTimes.length; i++) { |
| 133 | +// let difference = |
| 134 | +// parseInt(endTimes[i][0] + endTimes[i][1]) - |
| 135 | +// parseInt(startTimes[i][0] + startTimes[i][1]); |
| 136 | +// duration += difference; |
| 137 | +// if (endTimes[i][3] !== '0' || startTimes[i][3] !== '0') { |
| 138 | +// duration += ' - ' + (difference + 1); |
| 139 | +// } |
| 140 | +// duration += ' hour(s)'; |
| 141 | +// durationArr.push(duration); |
| 142 | +// duration = ''; |
| 143 | +// } |
| 144 | +// setDurations(durationArr); |
| 145 | +// }; |
| 146 | +// useEffect(() => { |
| 147 | +// generateDurationArr(); |
| 148 | +// }, [durationArr, endTimes, startTimes]); |
0 commit comments