-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
120 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
|
||
type Props = { | ||
id: number; | ||
name: string; | ||
email: string; | ||
body: string; | ||
handleDelete: (id: number) => void; | ||
}; | ||
|
||
export const Comment: React.FC<Props> = ({ | ||
id, | ||
name, | ||
email, | ||
body, | ||
handleDelete, | ||
}) => { | ||
return ( | ||
<article className="message is-small" data-cy="Comment" key={id}> | ||
<div className="message-header"> | ||
<a href={`mailto:${email}`} data-cy="CommentAuthor"> | ||
{name} | ||
</a> | ||
<button | ||
data-cy="CommentDelete" | ||
type="button" | ||
className="delete is-small" | ||
aria-label="delete" | ||
onClick={() => handleDelete(id)} | ||
> | ||
delete button | ||
</button> | ||
</div> | ||
|
||
<div className="message-body" data-cy="CommentBody"> | ||
{body} | ||
</div> | ||
</article> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { Comment } from './Comment'; | ||
|
||
type Props = { | ||
comments: Array<{ | ||
id: number; | ||
name: string; | ||
email: string; | ||
body: string; | ||
}>; | ||
handleDelete: (id: number) => void; | ||
}; | ||
|
||
export const CommentList: React.FC<Props> = ({ comments, handleDelete }) => { | ||
return ( | ||
<> | ||
{comments.map(({ id, email, name, body }) => ( | ||
<Comment | ||
key={id} | ||
id={id} | ||
name={name} | ||
email={email} | ||
body={body} | ||
handleDelete={handleDelete} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,9 @@ export const NewCommentForm: React.FC<Props> = ({ | |
}); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
const { name: commentName, email: commentEmail, body: commentBody } = addComment; | ||
const { name: nameError, email: emailError, body: bodyError } = commentError; | ||
|
||
const handleOnChange = ( | ||
event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, | ||
) => { | ||
|
@@ -137,17 +140,17 @@ export const NewCommentForm: React.FC<Props> = ({ | |
id="comment-author-name" | ||
placeholder="Name Surname" | ||
className={classNames('input', { | ||
'is-danger': commentError.name, | ||
'is-danger': nameError, | ||
})} | ||
value={addComment.name} | ||
value={commentName} | ||
onChange={handleOnChange} | ||
/> | ||
|
||
<span className="icon is-small is-left"> | ||
<i className="fas fa-user" /> | ||
</span> | ||
|
||
{commentError.name && ( | ||
{nameError && ( | ||
<span | ||
className="icon is-small is-right has-text-danger" | ||
data-cy="ErrorIcon" | ||
|
@@ -157,7 +160,7 @@ export const NewCommentForm: React.FC<Props> = ({ | |
)} | ||
</div> | ||
|
||
{commentError.name && ( | ||
{nameError && ( | ||
<p className="help is-danger" data-cy="ErrorMessage"> | ||
Name is required | ||
</p> | ||
|
@@ -176,17 +179,17 @@ export const NewCommentForm: React.FC<Props> = ({ | |
id="comment-author-email" | ||
placeholder="[email protected]" | ||
className={classNames('input', { | ||
'is-danger': commentError.email, | ||
'is-danger': emailError, | ||
})} | ||
value={addComment.email} | ||
value={commentEmail} | ||
onChange={handleOnChange} | ||
/> | ||
|
||
<span className="icon is-small is-left"> | ||
<i className="fas fa-envelope" /> | ||
</span> | ||
|
||
{commentError.email && ( | ||
{emailError && ( | ||
<span | ||
className="icon is-small is-right has-text-danger" | ||
data-cy="ErrorIcon" | ||
|
@@ -196,7 +199,7 @@ export const NewCommentForm: React.FC<Props> = ({ | |
)} | ||
</div> | ||
|
||
{commentError.email && ( | ||
{emailError && ( | ||
<p className="help is-danger" data-cy="ErrorMessage"> | ||
Email is required | ||
</p> | ||
|
@@ -214,14 +217,14 @@ export const NewCommentForm: React.FC<Props> = ({ | |
name="body" | ||
placeholder="Type comment here" | ||
className={classNames('textarea', { | ||
'is-danger': commentError.body, | ||
'is-danger': bodyError, | ||
})} | ||
value={addComment.body} | ||
value={commentBody} | ||
onChange={handleOnChange} | ||
/> | ||
</div> | ||
|
||
{commentError.body && ( | ||
{bodyError && ( | ||
<p className="help is-danger" data-cy="ErrorMessage"> | ||
Enter some text | ||
</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters