From c0a00945ef60acf3ac193a29eb6770f4abdb58de Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Wed, 30 Jun 2021 20:52:24 -0400 Subject: [PATCH] event creator includes recurring events! --- src/components/NewUI/EventCreator.tsx | 11 ++++++- src/components/NewUI/UIDateInput.tsx | 44 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/components/NewUI/UIDateInput.tsx diff --git a/src/components/NewUI/EventCreator.tsx b/src/components/NewUI/EventCreator.tsx index 080c6eb..6b8d0c3 100644 --- a/src/components/NewUI/EventCreator.tsx +++ b/src/components/NewUI/EventCreator.tsx @@ -4,6 +4,7 @@ import { toggleBit } from './bits'; import { green, lightgrey } from './colors'; import { IGroup } from './Group'; import UIButton from './UIButton'; +import UIDateInput from './UIDateInput'; import UIDatetimeInput from './UIDatetimeInput'; import UIPlacesAutocomplete from './UIPlacesAutocomplete'; import UISecondaryBox from './UISecondaryBox'; @@ -86,12 +87,14 @@ export default function EventCreator({ group }: { group: IGroup }) { const [recurring, toggleRecurring] = useToggle(false); const [daysOfWeek, setDaysOfWeek] = useState(0); + const [endDate, setEndDate] = useState(null); const buttonEnabled = name.length > 0 && startTime != null && endTime != null && placeId != null && + (!recurring || daysOfWeek || endDate !== null) && !creating; const createEvent = useCallback(() => { @@ -139,12 +142,18 @@ export default function EventCreator({ group }: { group: IGroup }) { backgroundColor: recurring ? green : lightgrey, color: recurring ? 'white' : 'black', transition: 'color 0.2s, background-color 0.2s', + marginBottom: '1.5rem', }} > Recurring event {recurring && ( - + <> + Days of week + + Date of last occurence + + )} {createdEventId === -1 ? ( void; + disabled?: boolean; +}) { + const onChange = useCallback( + (e) => { + // YYYY-MM-DD or "" (empty string) + const dateAsString = e.target.value as string; + if (typeof dateAsString !== 'string' || dateAsString.length === 0) { + onChangedDate(null); + } + const year = dateAsString.slice(0, 4); + const month = dateAsString.slice(5, 7); + const day = dateAsString.slice(8, 10); + + // Midnight in the timezone of the user + const date = new Date(`${year}-${month}-${day}T00:00:00`); + onChangedDate(date); + }, + [onChangedDate] + ); + return ( + + ); +}