Skip to content

Commit

Permalink
wrapped chatbox in real form
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasFoydel committed Feb 19, 2023
1 parent 1119edf commit d4940c4
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions client/src/Pages/Messages/parts/ChatBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import React, { useState } from 'react'
const ChatBox = ({ props: { userId, userName, currentThread, update, isTrainer } }) => {
const [text, setText] = useState('')

const submit = () => {
const submit = (e) => {
e.preventDefault()
if (!text) return toast.error('Message must contain content')

const message = {
Expand All @@ -26,19 +27,11 @@ const ChatBox = ({ props: { userId, userName, currentThread, update, isTrainer }
.catch(({ response: { data } }) => toast.error(data.message))
}

const handleKeyPress = ({ charCode }) => charCode === 13 && submit()

return (
<>
<input
type="text"
value={text}
className="input"
onKeyPress={handleKeyPress}
onChange={(e) => setText(e.target.value)}
/>
<button onClick={submit}>send</button>
</>
<form onSubmit={submit}>
<input type="text" value={text} className="input" onChange={(e) => setText(e.target.value)} />
<button type="submit">send</button>
</form>
)
}

Expand Down

0 comments on commit d4940c4

Please sign in to comment.