diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 18968b1af..5bb5056b2 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -2094,5 +2094,9 @@ "notFriends": { "message": "not friends", "description": "Indicates that a conversation is not friends with us" + }, + "emptyGroupNameError": { + "message": "Group Name cannot be empty", + "description": "Error message displayed on empty group name" } } diff --git a/stylesheets/_mentions.scss b/stylesheets/_mentions.scss index d111a21ac..ceb0a91af 100644 --- a/stylesheets/_mentions.scss +++ b/stylesheets/_mentions.scss @@ -23,6 +23,22 @@ .hidden { display: none; } + + .error-message { + text-align: center; + color: red; + margin-bottom: 0.5em; + } + + .error-faded { + opacity: 0; + transition: all 100ms linear; + } + + .error-shown { + opacity: 1; + transition: all 250ms linear; + } } .friend-selection-list { diff --git a/ts/components/conversation/CreateGroupDialog.tsx b/ts/components/conversation/CreateGroupDialog.tsx index 632d1c281..43a34bf7c 100644 --- a/ts/components/conversation/CreateGroupDialog.tsx +++ b/ts/components/conversation/CreateGroupDialog.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import classNames from 'classnames'; import { Contact, MemberList } from './MemberList'; declare global { @@ -20,6 +21,7 @@ interface Props { interface State { friendList: Array; groupName: string; + errorDisplayed: boolean; } export class CreateGroupDialog extends React.Component { @@ -53,6 +55,7 @@ export class CreateGroupDialog extends React.Component { this.state = { friendList: friends, groupName: '', + errorDisplayed: false, }; window.addEventListener('keyup', this.onKeyUp); @@ -64,8 +67,8 @@ export class CreateGroupDialog extends React.Component { .map(d => d.id); if (!this.state.groupName.trim()) { - // TODO: show error message - // console.error('Group name cannot be empty!'); + this.onShowError(); + return; } @@ -79,9 +82,16 @@ export class CreateGroupDialog extends React.Component { const okText = this.props.okText; const cancelText = this.props.cancelText; + const errorMsg = this.props.i18n('emptyGroupNameError'); + const errorMessageClasses = classNames( + 'error-message', + this.state.errorDisplayed ? 'error-shown' : 'error-faded' + ); + return (

{titleText}

+

{errorMsg}

{ ); } + private onShowError() { + if (this.state.errorDisplayed) { + return; + } + + this.setState({ + errorDisplayed: true, + }); + + setTimeout(() => { + this.setState({ + errorDisplayed: false, + }); + }, 3000); + } + private onGroupNameChanged(event: any) { event.persist(); diff --git a/ts/components/conversation/UpdateGroupDialog.tsx b/ts/components/conversation/UpdateGroupDialog.tsx index df3158f42..ccc3ee441 100644 --- a/ts/components/conversation/UpdateGroupDialog.tsx +++ b/ts/components/conversation/UpdateGroupDialog.tsx @@ -16,6 +16,7 @@ interface Props { interface State { friendList: Array; groupName: string; + errorDisplayed: boolean; } export class UpdateGroupDialog extends React.Component { @@ -47,6 +48,7 @@ export class UpdateGroupDialog extends React.Component { this.state = { friendList: friends, groupName: this.props.groupName, + errorDisplayed: false, }; window.addEventListener('keyup', this.onKeyUp); @@ -58,8 +60,8 @@ export class UpdateGroupDialog extends React.Component { .map(d => d.id); if (!this.state.groupName.trim()) { - // TODO: show error message - // window.log.error('Group name cannot be empty!'); + this.onShowError(); + return; } @@ -78,9 +80,16 @@ export class UpdateGroupDialog extends React.Component { ? 'no-friends' : classNames('no-friends', 'hidden'); + const errorMsg = this.props.i18n('emptyGroupNameError'); + const errorMessageClasses = classNames( + 'error-message', + this.state.errorDisplayed ? 'error-shown' : 'error-faded' + ); + return (

{titleText}

+

{errorMsg}

{ ); } + private onShowError() { + if (this.state.errorDisplayed) { + return; + } + + this.setState({ + errorDisplayed: true, + }); + + setTimeout(() => { + this.setState({ + errorDisplayed: false, + }); + }, 3000); + } + private onKeyUp(event: any) { switch (event.key) { case 'Enter':