Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first solution #2127

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

first solution #2127

wants to merge 3 commits into from

Conversation

Clover247
Copy link

Copy link

@BetterSol BetterSol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Made a few suggestions about your code.

Comment on lines +11 to +13
const findUserById = (id: number) => {
return usersFromServer.find(user => user.id === id) || null;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to relocate this function to a separate file.

Comment on lines +82 to 117
<form
action="/api/todos"
method="POST"
onSubmit={handleSubmit}
>
<div className="field">
<input type="text" data-cy="titleInput" />
<span className="error">Please enter a title</span>
<input
type="text"
data-cy="titleInput"
placeholder="Enter a Title"
value={title}
onChange={handleTitleInput}
/>

{hasTitleError && <span className="error">Please enter a title</span>}
</div>

<div className="field">
<select data-cy="userSelect">
<select
data-cy="userSelect"
value={userId}
onChange={handleUserSelect}
>
<option value="0" disabled>Choose a user</option>
{usersFromServer.map(user => (
<option value={user.id} key={user.id}>{user.name}</option>
))}
</select>

<span className="error">Please choose a user</span>
{hasUserError && <span className="error">Please choose a user</span>}
</div>

<button type="submit" data-cy="submitButton">
Add
</button>
</form>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating a separate file for a ToDoForm and it's hooks, it will keep your App file more readable

Comment on lines +54 to +64
if (!title) {
setHasTitleError(!hasTitleError);

return;
}

if (!userId) {
setHasUserError(!hasUserError);

return;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you actually don't need these

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need this to prevent changes and raise individual errors if there are any

const handleSubmit = ((e: React.ChangeEvent<HTMLFormElement>) => {
e.preventDefault();

if (!title && !userId) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use || operator, then you won't need separate conditions below

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I will always have both mistakes

Comment on lines 14 to 15
className={cn('TodoInfo', {
'TodoInfo--completed': todo.completed,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess it's better to move this part to a new variable

Copy link

@polosanya polosanya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants