-
Notifications
You must be signed in to change notification settings - Fork 0
Task 2 react forms #2
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- При попытке выбрать Gender: male, отоброжается сообщение "gender should be fill", при этом флажок на Male установлен. Установить Male можно только после того, как выбрал Female,а потом Male. Не очищается после сабмита формы
- Хотелось бы увидеть валидацию не только на обязательность заполнения, но и валидацию введенных данных. Например запретить вводить цыфры и специальные символы в поле Name.
- Если ввести в поле Name или Surname слишком длинную строку - ломается верстка карточки.
- Необходимо добалять node_module в gitignore. Добавить коментарии к коду в данной ситуации не представляется возможным.
| <div className="card"> | ||
| <div> | ||
| <span>Name: </span> | ||
| <span className="field">{Item.firstName}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше использовать деструктуризацию const { firstName, lastName, country ...} = Item Названия props обычно называются с маленькой буквы
| import { useState, useEffect } from 'react'; | ||
|
|
||
| export interface State { | ||
| firstName: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
State не лучшее название для интерфейса
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Переименовала
src/components/form.tsx
Outdated
|
|
||
| useEffect(() => { | ||
| const validate = () => { | ||
| setErrors({}); // сбрасываем ошибки |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Комментарии на русском - плохая практика
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
исправила
| } | ||
| if ( | ||
| birthDate === '' || | ||
| birthDate > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно заменить birthDate === '' -> !birthDate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправлено
| setErrors((state) => ({ ...state, birthDate })); | ||
| } | ||
| if (gender === '') { | ||
| setErrors((state) => ({ ...state, gender })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно заменить gender === '' -> !gender
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправлено
src/components/form.tsx
Outdated
|
|
||
| const handleSubmit = (event) => { | ||
| event.preventDefault(); | ||
| if (Object.keys(errors).length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не обязателельно сравнивать с 0: !Object.keys(errors).length
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправлено
| gender, | ||
| }, | ||
| ]); | ||
| alert('data saved succesfully'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше не использовать allert, предупреждение eslint
| <option value="poland">Poland</option> | ||
| <option value="turkey">Turkey</option> | ||
| <option value="germany">Germany</option> | ||
| </select> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше спользовать массив для генерации options
| <p> | ||
| I agree... | ||
| {errors?.agree !== undefined && ( | ||
| <span className="errors"> * agree should be check</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сравнивать что либо с undefined - плохая идея

4 пункты выполнены по форме