From 3231131e7e4c5afa35dedcc723766830efa47cb4 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 13 Dec 2017 15:31:04 +0000 Subject: [PATCH] Add basic validation for events. --- src/EventEdit.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/EventEdit.tsx b/src/EventEdit.tsx index 4bd8ec9..43d9e33 100644 --- a/src/EventEdit.tsx +++ b/src/EventEdit.tsx @@ -24,6 +24,8 @@ class EventEdit extends React.Component { location: string; description: string; journalUid: string; + + error?: string; }; props: { @@ -41,9 +43,10 @@ class EventEdit extends React.Component { allDay: false, location: '', description: '', - journalUid: '', start: '', - end: '' + end: '', + + journalUid: '', }; if (this.props.event !== undefined) { const event = this.props.event; @@ -110,12 +113,14 @@ class EventEdit extends React.Component { e.preventDefault(); if ((this.state.start === '') || (this.state.end === '')) { + this.setState({error: 'Both start and end time must be set!'}); return; } const startDate = ICAL.Time.fromString(this.state.start); let endDate = ICAL.Time.fromString(this.state.end); if (startDate.compare(endDate) >= 0) { + this.setState({error: 'End time must be later than start time!'}); return; } @@ -159,6 +164,9 @@ class EventEdit extends React.Component {

{this.props.event ? 'Edit Event' : 'New Event'}

+ {this.state.error && ( +
ERROR! {this.state.error}
+ )}