diff --git a/apps/comments-ui/src/components/modals/AddNameDialog.js b/apps/comments-ui/src/components/modals/AddNameDialog.js index 3af4eed9c3..e88c749ffb 100644 --- a/apps/comments-ui/src/components/modals/AddNameDialog.js +++ b/apps/comments-ui/src/components/modals/AddNameDialog.js @@ -1,7 +1,9 @@ -import React, {useContext, useState} from 'react'; +import React, {useContext, useState, useRef} from 'react'; +import {Transition} from '@headlessui/react'; import AppContext from '../../AppContext'; const AddNameDialog = (props) => { + const inputRef = useRef(null); const {dispatchAction} = useContext(AppContext); const close = () => { @@ -9,33 +11,52 @@ const AddNameDialog = (props) => { }; const submit = async () => { - await dispatchAction('updateMemberName', { - name - }); - props.callback(); - close(); + if (name.trim() !== '') { + await dispatchAction('updateMemberName', { + name + }); + props.callback(); + close(); + } else { + setError('Enter your name'); + setName(''); + inputRef.current.focus(); + } }; const [name, setName] = useState(''); + const [error, setError] = useState(''); return ( <>

Add context to your comment

For a healthy discussion, let other members know who you are when commenting.

- +
+ + +
{error}
+
+
{ setName(e.target.value); }} - // onKeyDown={e => onKeyDown(e, name)} - // onBlur={e => onBlur(e, name)} maxLength="64" />