Skip to content

task#3574

Open
Natalia2408-forever wants to merge 3 commits intomate-academy:masterfrom
Natalia2408-forever:develop
Open

task#3574
Natalia2408-forever wants to merge 3 commits intomate-academy:masterfrom
Natalia2408-forever:develop

Conversation

@Natalia2408-forever
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Great job on implementing the core functionality for adding todos and setting up the form validation! The component structure is solid. However, a few critical issues need to be addressed before this can be approved.

Here are the main points to work on:

  1. Incomplete Todo Type: The Todo type in src/types/Todo.ts is missing the required user property. This is causing type errors in several components (App.tsx, TodoInfo.tsx, TodoList.tsx). Please update the type to include the user.
  2. Incorrect Data Flow: The TodoForm component currently imports usersFromServer directly. This violates the project's architectural guidelines [CHECKLIST ITEM #5]. Instead, you should pass the users data from the App component down to TodoForm as a prop.
  3. Missing data-id Attribute: The task requires each .TodoInfo element to have a data-id={todo.id} attribute. This is currently missing from the <article> tag in src/components/TodoInfo/TodoInfo.tsx.
  4. Type Mismatch in onSubmit: In TodoForm.tsx, the onSubmit prop is typed to receive userId as a string, but you're correctly converting it to a number before calling the function. Please update the type definition to match the data being passed.

Once these issues are resolved, your solution will be in great shape. Keep up the good work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +14 to +17
export const initialTodos: Todo[] = todosFromServer.map(todo => ({
...todo,
user: getUserById(todo.userId),
}));

Choose a reason for hiding this comment

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

The objects created here for initialTodos (and later for newTodo on line 34) include a user property. However, the imported Todo type does not define this property, which will cause a type error. The task requires a user object in each todo, so you should update the Todo type definition in src/types/Todo.ts to include it.

src/App.tsx Outdated
return (
<div className="App">
<h1 className="App__title">Static list of todos</h1>
<PostForm onSubmit={addTodo} />

Choose a reason for hiding this comment

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

This violates checklist item #5: 'Prepare data in one place (App component) and pass it to child components. Don't use import keyword in non-root components'. The PostForm component currently imports usersFromServer directly. Instead, you should pass usersFromServer from this App component to PostForm as a prop.

@@ -0,0 +1,101 @@
import React, { useState } from 'react';
import usersFromServer from '../../api/users';

Choose a reason for hiding this comment

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

This violates checklist item #5: 'Don't use import keyword in non-root components'. Data like usersFromServer should be imported in the root App component and passed down to child components as props.

};

type Props = {
onSubmit: (data: TodoForm) => void;

Choose a reason for hiding this comment

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

The type definition for the onSubmit prop is incorrect. It's defined to accept data of type TodoForm, which has userId as a string. However, you call it on line 55 with an object where userId has been converted to a number. This type should match the data shape that is actually passed, which is { title: string; userId: number; }.

return (
<form action="/api/todos" method="POST" onSubmit={handleSubmit}>
<div className="field">
<label htmlFor="titleInout">Title </label>

Choose a reason for hiding this comment

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

There's a typo in the htmlFor attribute. It should be "titleInput" to match the id of the <input> element on the next line. This is important for accessibility, as it allows users to focus the input field by clicking on its label.

import { Todo } from '../../types/Todo';

type Props = {
todo: Todo;

Choose a reason for hiding this comment

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

The imported Todo type from ../../types/Todo.ts doesn't include the user property, which you are accessing on line 15. You should update the Todo type definition to include the user property to match the data structure being created in App.tsx.

const className = `TodoInfo ${todo.completed ? 'TodoInfo--completed' : ''}`;

return (
<article className={className}>

Choose a reason for hiding this comment

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

The task description requires adding a data-id={todo.id} attribute to each .TodoInfo element. This attribute is missing from the <article> tag.

Comment on lines +9 to +11
if (!user) {
return null;
}

Choose a reason for hiding this comment

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

This violates checklist item #4: "Don't render the component if the property that you pass to the component has null or undefined value." The checklist's example shows that the check should happen in the parent component before rendering, not inside the child component. Since the parent component TodoInfo already checks if todo.user exists (todo.user && <UserInfo ... />), this check is redundant and can be removed.

Comment on lines +1 to +6
export type Todo = {
id: number;
title: string;
completed: boolean;
userId: number;
};

Choose a reason for hiding this comment

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

The task description requires each Todo item to include a user object. This type definition is missing that user property. You need to add it here to match the data structure used in App.tsx and TodoInfo.tsx. You will also need to import the User type.

import { Todo } from '../../types/Todo';

type Props = {
todos: Todo[];

Choose a reason for hiding this comment

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

The Todo type imported from ../../types/Todo.ts is incomplete. The todos array passed from the App component contains objects that each have a user property, but this type definition doesn't include it. This will cause a TypeScript error. You should update the Todo type in src/types/Todo.ts to reflect the actual data structure.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Excellent work on this task! I am approving your solution as you've successfully implemented all the core requirements and addressed all the feedback from the previous review. The data flow is clean, the form validation works perfectly, and the components are well-structured.

As a minor point for future improvement, the null check in UserInfo.tsx is redundant. The parent component, TodoInfo, already ensures the user prop is valid before rendering UserInfo, so you can safely remove the if (!user) block to simplify the component. This aligns with the principle of letting parent components handle rendering logic [CHECKLIST ITEM #4].

Overall, this is a very strong submission. Keep up the great work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment on lines +9 to +11
if (!user) {
return null;
}

Choose a reason for hiding this comment

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

This null check is a good example of the 'BAD EXAMPLE' pattern described in checklist item #4. The responsibility for checking if user exists lies with the parent component (TodoInfo), which already does this correctly with {todo.user && <UserInfo user={todo.user} />}.

Since the parent ensures user is never null or undefined when this component is rendered, you can remove this if block. This will simplify the component and align it with the provided guidelines.

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.

2 participants