diff --git a/src/pages/TodayPage/Components/MenuToday.tsx b/src/pages/TodayPage/Components/MenuToday.tsx index f5afa16..fc70608 100644 --- a/src/pages/TodayPage/Components/MenuToday.tsx +++ b/src/pages/TodayPage/Components/MenuToday.tsx @@ -21,44 +21,26 @@ import SunIcon from "../../../icons/SunIcon"; import TodayIcon from "../../../icons/TodayIcon"; import UpsentIcon from "../../../icons/UpsentIcon"; +const DATE_OPTIONS = { + TODAY: "Today", + TOMORROW: "Tomorrow", + NEXT_WEEK: "Next weekend", + NO_DATE: "No date" +}; function MenuToday() { const date = new Date(Date.now()); - const [startDate, setStartDate] = useState(new Date()); + const [startDate, setStartDate] = useState(date); const weeksDate = new Date(Date.now() + 3600 * 1000 * 24); const nextWeeks = new Date(Date.now() + 3600 * 1000 * 24 * 7); - const formatNextWeekOptions: Intl.DateTimeFormatOptions = { + const formatOptions: Intl.DateTimeFormatOptions = { weekday: "short", day: "numeric", month: "short" }; - const formatTomorrowOptions: Intl.DateTimeFormatOptions = { - weekday: "short" - }; - const formatTodayOptions: Intl.DateTimeFormatOptions = { - month: "short", - day: "numeric" - }; - const today = date.toLocaleDateString("en-US", formatTodayOptions); - const tomorrow = weeksDate.toLocaleDateString("en-US", formatTomorrowOptions); - const nextWeek = nextWeeks.toLocaleDateString("en-US", formatNextWeekOptions); - - const menuItemsToday = [ - { - icon: , - text1: "Tomorrow", - text2: tomorrow - }, - { - icon: , - text1: "Next weekend", - text2: nextWeek - }, - { - icon: , - text1: "No date" - } - ]; - + const today = date.toLocaleDateString("en-US", formatOptions); + const tomorrow = weeksDate.toLocaleDateString("en-US", formatOptions); + const nextWeek = nextWeeks.toLocaleDateString("en-US", formatOptions); + const [checkedDate, setCheckedDate] = useState(today); return ( @@ -76,40 +58,104 @@ function MenuToday() { rightIcon={ { + e.stopPropagation(), setCheckedDate(""); + }} > } > - - Today + + {checkedDate === today + ? DATE_OPTIONS.TODAY + : checkedDate === tomorrow + ? DATE_OPTIONS.TOMORROW + : checkedDate + ? checkedDate.slice(4) + : DATE_OPTIONS.NO_DATE} - - + + + + {checkedDate.slice(4)} + - {menuItemsToday.map((item) => ( - - {item.icon} - {item.text1} - - - {item.text2} - - - ))} + setCheckedDate(today)} + display={checkedDate === today ? "none" : "flex"} + fontSize="13px" + fontWeight="500" + > + + {DATE_OPTIONS.TODAY} + + + {today.slice(0, 3)} + + + setCheckedDate(tomorrow)} + display={checkedDate === tomorrow ? "none" : "flex"} + fontSize="13px" + fontWeight="500" + > + + {DATE_OPTIONS.TOMORROW} + + + {tomorrow.slice(0, 3)} + + + setCheckedDate(nextWeek)} + fontSize="13px" + fontWeight="500" + > + + {DATE_OPTIONS.NEXT_WEEK} + + + {nextWeek} + + + setCheckedDate("")} + fontSize="13px" + fontWeight="500" + > + + {DATE_OPTIONS.NO_DATE} + - - setStartDate(date)} - /> + + + + { + setStartDate(date), + setCheckedDate( + date.toLocaleDateString("en-US", formatOptions) + ); + }} + showTimeSelect + dateFormat="d MMMM, yyyy h:mm aa" + minDate={new Date()} + /> +