diff --git a/src/App.tsx b/src/App.tsx index 781153298c..5cd9e32e02 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -13,20 +13,20 @@ export const App = () => { const [hasTitleError, setHasTitleError] = useState(false); const [hasNameError, setHasNameError] = useState(false); - const handleSubmit: FormEventHandler = (event) => { + const handleSubmit: FormEventHandler = (event) => { event.preventDefault(); - if (!typedTitle) { + if (!typedTitle.trim()) { setHasTitleError(true); } - if (selectedUserId === 0) { + if (!selectedUserId) { setHasNameError(true); } const maxId = Math.max(...todosList.map(todo => todo.id)); - if (typedTitle !== '' && selectedUserId) { + if (!!typedTitle && selectedUserId) { const newTodo: Todo = { id: maxId + 1, title: typedTitle, @@ -59,7 +59,7 @@ export const App = () => {

Add todo form

-
+
{ title="User" defaultValue={0} > - - {usersFromServer.map(user => { - return ( - - ); - })} + {usersFromServer.map(user => ( + + ))} {hasNameError && Please choose a user}
-
diff --git a/src/api/users.ts b/src/api/users.ts index 101e16a84d..8438ad7a5f 100644 --- a/src/api/users.ts +++ b/src/api/users.ts @@ -59,4 +59,4 @@ export default [ username: 'Moriah.Stanton', email: 'Rey.Padberg@karina.biz', }, -]; \ No newline at end of file +]; diff --git a/src/components/TodoList/TodoList.tsx b/src/components/TodoList/TodoList.tsx index 1f666cebfa..bda7495932 100644 --- a/src/components/TodoList/TodoList.tsx +++ b/src/components/TodoList/TodoList.tsx @@ -5,7 +5,7 @@ type TodoListProps = { todos: Todo[]; }; -export const TodoList = ({ todos }: TodoListProps) => ( +export const TodoList: React.FC = ({ todos }) => (
{todos.map(todo => ( { - if (!user) { - return null; - } - return ( {user.name}