mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-21 19:29:51 -04:00
add start time and end time client-side validation
This commit is contained in:
parent
305c738e50
commit
cf3a84d1c5
|
@ -108,12 +108,16 @@ export default function EventCreator({ group }: { group: IGroup }) {
|
||||||
const [daysOfWeek, setDaysOfWeek] = useState(0);
|
const [daysOfWeek, setDaysOfWeek] = useState(0);
|
||||||
const [endDate, setEndDate] = useState<Date | null>(null);
|
const [endDate, setEndDate] = useState<Date | null>(null);
|
||||||
|
|
||||||
|
const durationIsNegative =
|
||||||
|
endTime && startTime && endTime.getTime() < startTime.getTime();
|
||||||
|
|
||||||
const buttonEnabled =
|
const buttonEnabled =
|
||||||
name.length > 0 &&
|
name.length > 0 &&
|
||||||
startTime != null &&
|
startTime != null &&
|
||||||
endTime != null &&
|
endTime != null &&
|
||||||
placeId != null &&
|
placeId != null &&
|
||||||
(!recurring || daysOfWeek || endDate !== null) &&
|
(!recurring || daysOfWeek || endDate !== null) &&
|
||||||
|
!durationIsNegative &&
|
||||||
!creating;
|
!creating;
|
||||||
|
|
||||||
const createEvent = useCallback(() => {
|
const createEvent = useCallback(() => {
|
||||||
|
@ -200,6 +204,11 @@ export default function EventCreator({ group }: { group: IGroup }) {
|
||||||
<UIDateInput onChangedDate={setEndDate} disabled={creating} />
|
<UIDateInput onChangedDate={setEndDate} disabled={creating} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
{durationIsNegative && (
|
||||||
|
<span style={{ marginTop: '1rem' }}>
|
||||||
|
The start time can't be after the end time.
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
{createdEventId === -1 ? (
|
{createdEventId === -1 ? (
|
||||||
<UIButton
|
<UIButton
|
||||||
onClick={buttonEnabled ? createEvent : noop}
|
onClick={buttonEnabled ? createEvent : noop}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user