improve event creation ux

This commit is contained in:
Michael Fatemi 2021-06-24 11:45:08 -04:00
parent 7e9609fa79
commit 912244dcf6
4 changed files with 69 additions and 27 deletions

View File

@ -11,7 +11,7 @@ const lightgrey = '#e0e0e0';
export type IEvent = { export type IEvent = {
name: string; name: string;
group: string; group: string;
address: string; formattedAddress: string;
startTime: string; startTime: string;
endTime: string; endTime: string;
}; };
@ -47,7 +47,7 @@ function formatStartAndEndTime(
export default function Event({ export default function Event({
name, name,
group, group,
address, formattedAddress,
startTime, startTime,
endTime, endTime,
}: IEvent) { }: IEvent) {
@ -71,6 +71,7 @@ export default function Event({
<div <div
style={{ style={{
marginTop: '0.5rem', marginTop: '0.5rem',
textAlign: 'left',
}} }}
> >
<span <span
@ -82,13 +83,14 @@ export default function Event({
{formatStartAndEndTime(startTime, endTime)} {formatStartAndEndTime(startTime, endTime)}
</span> </span>
<br /> <br />
<br />
<span <span
style={{ style={{
color: '#303030', color: '#303030',
}} }}
> >
<b>Where: </b> <b>Where: </b>
{address} {formattedAddress}
</span> </span>
</div> </div>
<div <div

View File

@ -7,25 +7,40 @@ import UIPlacesAutocomplete from './UIPlacesAutocomplete';
import UISecondaryBox from './UISecondaryBox'; import UISecondaryBox from './UISecondaryBox';
import UITextInput from './UITextInput'; import UITextInput from './UITextInput';
const noop = () => {};
export default function EventCreator({ group }: { group: IGroup }) { export default function EventCreator({ group }: { group: IGroup }) {
const [name, setName] = useState(''); const [name, setName] = useState('');
const [startTime, setStartTime] = useState<Date | null>(null); const [startTime, setStartTime] = useState<Date | null>(null);
const [endTime, setEndTime] = useState<Date | null>(null); const [endTime, setEndTime] = useState<Date | null>(null);
const [placeId, setPlaceId] = useState<string | null>(null); const [placeId, setPlaceId] = useState<string | null>(null);
const [creating, setCreating] = useState(false);
const [createdEventId, setCreatedEventId] = useState(-1);
const buttonEnabled =
name.length > 0 &&
startTime != null &&
endTime != null &&
placeId != null &&
!creating;
const createEvent = useCallback(() => { const createEvent = useCallback(() => {
post('/events', { if (!creating) {
name, setCreating(true);
startTime, post('/events', {
endTime, name,
groupId: group.id, startTime,
placeId, endTime,
}) groupId: group.id,
.then((response) => response.json()) placeId,
.then(({ id }) => { })
window.location.href = `/groups/${id}`; .then((response) => response.json())
}); .then(({ id }) => {
}, [name, startTime, endTime, group.id, placeId]); setCreatedEventId(id);
})
.finally(() => setCreating(false));
}
}, [creating, name, startTime, endTime, group.id, placeId]);
return ( return (
<UISecondaryBox style={{ width: '100%', boxSizing: 'border-box' }}> <UISecondaryBox style={{ width: '100%', boxSizing: 'border-box' }}>
@ -48,7 +63,18 @@ export default function EventCreator({ group }: { group: IGroup }) {
setPlaceId(placeId); setPlaceId(placeId);
}} }}
/> />
<UIButton onClick={createEvent}>Create Event</UIButton> {createdEventId === -1 ? (
<UIButton
onClick={buttonEnabled ? createEvent : noop}
style={!buttonEnabled ? { color: 'grey' } : {}}
>
{creating ? 'Creating event' : 'Create event'}
</UIButton>
) : (
<span>
Created <b>{name}</b>.
</span>
)}
</UISecondaryBox> </UISecondaryBox>
); );
} }

View File

@ -10,23 +10,37 @@ export default function GroupCreator() {
const [creationSuccessful, setCreationSuccessful] = const [creationSuccessful, setCreationSuccessful] =
useState<boolean | null>(null); useState<boolean | null>(null);
const [createdGroupId, setCreatedGroupId] = useState(0); const [createdGroupId, setCreatedGroupId] = useState(0);
const [creating, setCreating] = useState(false);
const createGroup = useCallback(() => { const createGroup = useCallback(() => {
post('/groups', { if (!creating) {
name, setCreating(true);
}) post('/groups', {
.then((res) => res.json()) name,
.then(({ id }) => { })
setCreationSuccessful(true); .then((res) => res.json())
setCreatedGroupId(id); .then(({ id }) => {
}); setCreationSuccessful(true);
}, [name]); setCreatedGroupId(id);
})
.finally(() => {
setCreating(false);
});
}
}, [creating, name]);
const buttonEnabled = name.length > 0 && !creating;
return ( return (
<UISecondaryBox style={{ width: '100%', boxSizing: 'border-box' }}> <UISecondaryBox style={{ width: '100%', boxSizing: 'border-box' }}>
<h1 style={{ textAlign: 'center' }}>Create Group</h1> <h1 style={{ textAlign: 'center' }}>Create Group</h1>
Name Name
<UITextInput onChangeText={setName} value={name} /> <UITextInput onChangeText={setName} value={name} />
<UIButton onClick={createGroup}>Create group</UIButton> <UIButton
onClick={createGroup}
style={!buttonEnabled ? { color: 'grey' } : {}}
>
{creating ? 'Creating group' : 'Create group'}
</UIButton>
{creationSuccessful !== null && {creationSuccessful !== null &&
(creationSuccessful ? ( (creationSuccessful ? (
<span> <span>

View File

@ -20,7 +20,7 @@ function GroupJoiner() {
const buttonEnabled = code.length > 0 && !joining; const buttonEnabled = code.length > 0 && !joining;
return ( return (
<UISecondaryBox style={{ width: '100%' }}> <UISecondaryBox style={{ width: '100%', textAlign: 'center' }}>
<h1>Join Group</h1> <h1>Join Group</h1>
Code Code
<UITextInput value={code} onChangeText={setCode} /> <UITextInput value={code} onChangeText={setCode} />