From 7a42ff04d8175b7f15f048a6272942d1c2702cb5 Mon Sep 17 00:00:00 2001 From: Andrew P Maney Date: Tue, 31 Mar 2020 13:09:15 -0700 Subject: [PATCH] UI: pretty error messages Add Toast component for displaying error messages in a more prominent way --- src/components/EventEdit.tsx | 17 ++++++++++++++--- src/components/Tasks/TaskEdit.tsx | 16 +++++++++++++--- src/widgets/Toast.tsx | 25 +++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 src/widgets/Toast.tsx 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