Skip to content

Commit

Permalink
feat: error messages for NewMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Mar 12, 2022
1 parent 5747048 commit 9942e79
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/Messaging/Inbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ const Inbox = ({ threads, selected, handleListItemClick }) => {
return thread;
}
})
.map((thread) => (
.map((thread, i) => (
<ListItem
key={thread.userName}
key={`${thread.userName}-${i}`}
alignItems="flex-start"
className={listItem}
selected={thread.userName === selected}
Expand Down
23 changes: 23 additions & 0 deletions src/components/Messaging/NewMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const NewMessage = ({ openModal, handleClose }) => {
const [messageContent, setMessageContent] = useState('');
const [recipient, setRecipient] = useState('');
const [inputValue, setInputValue] = useState('');
const [error, setError] = useState(false);

useEffect(() => {
if (openModal === false) {
Expand All @@ -81,6 +82,7 @@ const NewMessage = ({ openModal, handleClose }) => {
}, [openModal]);

const handleChange = (e) => {
setError(false);
const { name, value } = e.target;
name === 'body'
? setMessageContent(value)
Expand All @@ -97,6 +99,16 @@ const NewMessage = ({ openModal, handleClose }) => {
body: messageContent,
};

if (
!recipient ||
recipient === '' ||
!messageContent ||
messageContent === ''
) {
setError(true);
return;
}

if (
messagePayload.body !== '' &&
user.userName &&
Expand Down Expand Up @@ -159,6 +171,17 @@ const NewMessage = ({ openModal, handleClose }) => {
<Box className={header} my={1}>
<Typography variant="h3">Send New Message</Typography>
</Box>
{error ? (
<Typography
style={{
color: 'red',
fontWeight: 'bold',
margin: '20px 10px 0px',
}}
>
Please select a recipient and enter a message!
</Typography>
) : null}
<FormControl>
<GSInputLabel text="Choose the Message Recipient" />
<Autocomplete
Expand Down

0 comments on commit 9942e79

Please sign in to comment.