mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-21 11:20:17 -04:00
improve event creation ux
This commit is contained in:
parent
7e9609fa79
commit
912244dcf6
|
@ -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
|
||||||
|
|
|
@ -7,13 +7,26 @@ 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(() => {
|
||||||
|
if (!creating) {
|
||||||
|
setCreating(true);
|
||||||
post('/events', {
|
post('/events', {
|
||||||
name,
|
name,
|
||||||
startTime,
|
startTime,
|
||||||
|
@ -23,9 +36,11 @@ export default function EventCreator({ group }: { group: IGroup }) {
|
||||||
})
|
})
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then(({ id }) => {
|
.then(({ id }) => {
|
||||||
window.location.href = `/groups/${id}`;
|
setCreatedEventId(id);
|
||||||
});
|
})
|
||||||
}, [name, startTime, endTime, group.id, placeId]);
|
.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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,10 @@ 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(() => {
|
||||||
|
if (!creating) {
|
||||||
|
setCreating(true);
|
||||||
post('/groups', {
|
post('/groups', {
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
|
@ -18,15 +21,26 @@ export default function GroupCreator() {
|
||||||
.then(({ id }) => {
|
.then(({ id }) => {
|
||||||
setCreationSuccessful(true);
|
setCreationSuccessful(true);
|
||||||
setCreatedGroupId(id);
|
setCreatedGroupId(id);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setCreating(false);
|
||||||
});
|
});
|
||||||
}, [name]);
|
}
|
||||||
|
}, [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>
|
||||||
|
|
|
@ -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} />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user