From b7244c91e589f15c7fab76f69705f827bc5e9fa8 Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Tue, 22 Jun 2021 21:19:08 -0400 Subject: [PATCH] add event creation ui --- src/components/NewUI/App.tsx | 2 + src/components/NewUI/Event.tsx | 46 +++++--------------- src/components/NewUI/EventCreator.tsx | 53 ++++++++++++++++++++++++ src/components/NewUI/Group.tsx | 4 +- src/components/NewUI/UIButton.tsx | 33 +++++++++++++++ src/components/NewUI/UIDatetimeInput.tsx | 22 ++++++++++ src/components/NewUI/UISecondaryBox.tsx | 26 ++++++++++++ src/components/NewUI/UITextInput.tsx | 24 +++++++++++ 8 files changed, 172 insertions(+), 38 deletions(-) create mode 100644 src/components/NewUI/EventCreator.tsx create mode 100644 src/components/NewUI/UIButton.tsx create mode 100644 src/components/NewUI/UIDatetimeInput.tsx create mode 100644 src/components/NewUI/UISecondaryBox.tsx create mode 100644 src/components/NewUI/UITextInput.tsx diff --git a/src/components/NewUI/App.tsx b/src/components/NewUI/App.tsx index 136a741..cf857c1 100644 --- a/src/components/NewUI/App.tsx +++ b/src/components/NewUI/App.tsx @@ -1,3 +1,4 @@ +import EventCreator from './EventCreator'; import Group from './Group'; import UIPrimaryTitle from './UIPrimaryTitle'; @@ -15,6 +16,7 @@ export default function App() { }} > WheelShare + + {title} -
{ setNeedRideThere((needRideThere) => !needRideThere); }} > I need a ride there -
-
+ { setNeedRideBack((needRideBack) => !needRideBack); }} > I need a ride back -
+ {needRideThere && ( <> @@ -161,25 +142,18 @@ export default function Event({ title, group, location, time }: IEvent) { )} {(needRideThere || needRideBack) && (rideTherePickupPlaceID || rideBackDropoffPlaceID) && ( -
{ setConfirmed((confirmed) => !confirmed); }} > {confirmed ? 'Confirmed' : 'Confirm'} -
+ )} - +
); } diff --git a/src/components/NewUI/EventCreator.tsx b/src/components/NewUI/EventCreator.tsx new file mode 100644 index 0000000..96c2cb0 --- /dev/null +++ b/src/components/NewUI/EventCreator.tsx @@ -0,0 +1,53 @@ +import { useCallback, useState } from 'react'; +import UIButton from './UIButton'; +import UIDatetimeInput from './UIDatetimeInput'; +import UIPlacesAutocomplete from './UIPlacesAutocomplete'; +import UISecondaryBox from './UISecondaryBox'; +import UITextInput from './UITextInput'; + +export default function EventCreator() { + const [name, setName] = useState(''); + const [startTime, setStartTime] = useState(null); + const [endTime, setEndTime] = useState(null); + const [placeId, setPlaceId] = useState(null); + const [groupId, setGroupId] = useState(''); + + const createEvent = useCallback(() => { + fetch('http://localhost:5000/api/events', { + method: 'post', + body: JSON.stringify({ + name, + startTime, + endTime, + groupId, + }), + headers: { + 'Content-Type': 'application/json', + }, + }); + }, [name, startTime, endTime, groupId]); + + return ( + + Name + +
+ Group + +
+ Start time + +
+ End time + +
+ Location + { + setPlaceId(placeId); + }} + /> + Create Event +
+ ); +} diff --git a/src/components/NewUI/Group.tsx b/src/components/NewUI/Group.tsx index 073ac3c..a508b19 100644 --- a/src/components/NewUI/Group.tsx +++ b/src/components/NewUI/Group.tsx @@ -7,9 +7,9 @@ export type IGroup = { export default function Group({ events, name }: IGroup) { return ( -
+

{name}

-
+
{events.map((event) => ( ))} diff --git a/src/components/NewUI/UIButton.tsx b/src/components/NewUI/UIButton.tsx new file mode 100644 index 0000000..483813f --- /dev/null +++ b/src/components/NewUI/UIButton.tsx @@ -0,0 +1,33 @@ +import { useMemo, CSSProperties, MouseEventHandler, ReactNode } from 'react'; + +const baseStyle: CSSProperties = { + padding: '1rem', + borderRadius: '0.5em', + textTransform: 'uppercase', + fontWeight: 500, + marginTop: '0.5em', + cursor: 'pointer', + userSelect: 'none', +}; + +export default function UIButton({ + style, + children, + onClick, +}: { + style?: CSSProperties; + children: ReactNode; + onClick: MouseEventHandler; +}) { + const computedStyle = useMemo(() => { + if (!style) { + return baseStyle; + } + return { ...baseStyle, ...style }; + }, [style]); + return ( +
+ {children} +
+ ); +} diff --git a/src/components/NewUI/UIDatetimeInput.tsx b/src/components/NewUI/UIDatetimeInput.tsx new file mode 100644 index 0000000..156a6d3 --- /dev/null +++ b/src/components/NewUI/UIDatetimeInput.tsx @@ -0,0 +1,22 @@ +const baseStyle = { + marginTop: '0.5em', + padding: '0.5em', + fontFamily: 'Inter', + fontSize: '1.25rem', + borderRadius: '0.5em', + border: '0px', +}; + +export default function UIDatetimeInput({ + onChangedDate, +}: { + onChangedDate: (date: Date | null) => void; +}) { + return ( + onChangedDate(e.target.valueAsDate)} + /> + ); +} diff --git a/src/components/NewUI/UISecondaryBox.tsx b/src/components/NewUI/UISecondaryBox.tsx new file mode 100644 index 0000000..d38c94b --- /dev/null +++ b/src/components/NewUI/UISecondaryBox.tsx @@ -0,0 +1,26 @@ +import { CSSProperties, ReactNode, useMemo } from 'react'; + +const baseStyle: CSSProperties = { + display: 'flex', + flexDirection: 'column', + backgroundColor: '#f9f9f9', + borderRadius: '0.5rem', + padding: '1rem', + marginBottom: '1em', +}; + +export default function UISecondaryBox({ + children, + style, +}: { + children: ReactNode; + style?: CSSProperties; +}) { + const computedStyle = useMemo(() => { + if (!style) { + return baseStyle; + } + return { ...baseStyle, ...style }; + }, [style]); + return
{children}
; +} diff --git a/src/components/NewUI/UITextInput.tsx b/src/components/NewUI/UITextInput.tsx new file mode 100644 index 0000000..50339f6 --- /dev/null +++ b/src/components/NewUI/UITextInput.tsx @@ -0,0 +1,24 @@ +const baseStyle = { + marginTop: '0.5em', + padding: '0.5em', + fontFamily: 'Inter', + fontSize: '1.25rem', + borderRadius: '0.5em', + border: '0px', +}; + +export default function UITextInput({ + value, + onChangeText, +}: { + value: string; + onChangeText: (text: string) => void; +}) { + return ( + onChangeText(e.target.value)} + /> + ); +}