diff --git a/src/components/EventEdit.tsx b/src/components/EventEdit.tsx index b8d1f2d..397dbc5 100644 --- a/src/components/EventEdit.tsx +++ b/src/components/EventEdit.tsx @@ -24,6 +24,7 @@ import DateTimePicker from '../widgets/DateTimePicker'; import ConfirmationDialog from '../widgets/ConfirmationDialog'; import TimezonePicker from '../widgets/TimezonePicker'; +import Toast from '../widgets/Toast'; import { Location } from 'history'; import { withRouter } from 'react-router'; @@ -138,6 +139,7 @@ class EventEdit extends React.PureComponent { this.onDeleteRequest = this.onDeleteRequest.bind(this); this.toggleRecurring = this.toggleRecurring.bind(this); this.handleRRuleChange = this.handleRRuleChange.bind(this); + this.handleCloseToast = this.handleCloseToast.bind(this); } public UNSAFE_componentWillReceiveProps(nextProps: any) { @@ -180,6 +182,15 @@ class EventEdit extends React.PureComponent { public handleRRuleChange(rrule: RRuleOptions): void { this.setState({ rrule: rrule }); } + + public handleCloseToast(_event?: React.SyntheticEvent, reason?: string) { + if (reason === 'clickaway') { + return; + } + + this.setState({ error: '' }); + } + public onSubmit(e: React.FormEvent) { e.preventDefault(); @@ -279,9 +290,9 @@ class EventEdit extends React.PureComponent { (by editing the first instance) is supported. )} - {this.state.error && ( -
ERROR! {this.state.error}
- )} + + ERROR! {this.state.error} +
{ this.handleInputChange = this.handleInputChange.bind(this); this.toggleTime = this.toggleTime.bind(this); this.onDeleteRequest = this.onDeleteRequest.bind(this); + this.handleCloseToast = this.handleCloseToast.bind(this); } public UNSAFE_componentWillReceiveProps(nextProps: any) { @@ -161,6 +163,14 @@ class TaskEdit extends React.PureComponent { this.setState({ includeTime: !this.state.includeTime }); } + public handleCloseToast(_event?: React.SyntheticEvent, reason?: string) { + if (reason === 'clickaway') { + return; + } + + this.setState({ error: '' }); + } + public onSubmit(e: React.FormEvent) { e.preventDefault(); @@ -265,9 +275,9 @@ class TaskEdit extends React.PureComponent { (by editing the first instance) is supported. )} - {this.state.error && ( -
ERROR! {this.state.error}
- )} + + ERROR! {this.state.error} + void; +} + +export default function Toast(props: PropsType) { + const { open, children, onClose } = props; + + return ( + + + {children} + + + ); +} \ No newline at end of file