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

add solution #2124

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

add solution #2124

wants to merge 3 commits into from

Conversation

VazilX
Copy link

@VazilX VazilX commented Jan 22, 2024

Copy link

@etojeDenys etojeDenys left a comment

Choose a reason for hiding this comment

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

i can create the movie only with spaces, let's fix that
image

Comment on lines 13 to 17
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [imgUrl, setImgUrl] = useState('');
const [imdbUrl, setImdbUrl] = useState('');
const [imdbId, setImdbId] = useState('');

Choose a reason for hiding this comment

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

we can combine it in one useState

const [newMovie, setNewMovie] = useState({
  title: '',
  ...
})

now we can also create only one handle function for all fields

const handleChange = (e: ...) => {
  const {name, value} = e.target;
  setMovie((prevMovie) => ({...prevMovie, [name]: value}))
}

don't forget to specify name attr to input in TextField

Choose a reason for hiding this comment

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

agree, looks good ⬆️

@VazilX VazilX requested a review from etojeDenys January 22, 2024 16:54
Copy link

@maxim2310 maxim2310 left a comment

Choose a reason for hiding this comment

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

Good work, just need to clear the form after adding a new movie and fix previous comments

@VazilX VazilX requested a review from maxim2310 January 22, 2024 17:12
@@ -48,6 +93,7 @@ export const NewMovie = () => {
type="submit"
data-cy="submit-button"
className="button is-link"
disabled={hasError}

Choose a reason for hiding this comment

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

please disable the button if some of required fields is not filled

Comment on lines 13 to 17
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [imgUrl, setImgUrl] = useState('');
const [imdbUrl, setImdbUrl] = useState('');
const [imdbId, setImdbId] = useState('');

Choose a reason for hiding this comment

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

agree, looks good ⬆️

@VazilX VazilX requested a review from andriy-shymkiv January 22, 2024 18:50
/>
</div>

{hasError && (
<p className="help is-danger">{`${label} is required`}</p>
{errorMaseg && (

Choose a reason for hiding this comment

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

Suggested change
{errorMaseg && (
{errorMessage && (

}) => {
// generage a unique id once on component load
const [id] = useState(() => `${name}-${getRandomDigits()}`);

// To show errors only if the field was touched (onBlur)
const [touched, setTouched] = useState(false);
const hasError = touched && required && !value;
const [errorMaseg, setErrorMaseg] = useState('');

Choose a reason for hiding this comment

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

Suggested change
const [errorMaseg, setErrorMaseg] = useState('');
const [errorMessage, setErrorMessege] = useState('');

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.

5 participants