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

solution react_movies_list_add_form task #1909

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

Conversation

ivaZaiets
Copy link

Copy link

@HardCodWorker HardCodWorker left a comment

Choose a reason for hiding this comment

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

AWESOME!

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.

Almost perfect!

Comment on lines 20 to 38
const handleTitleUpdate = (newValue: string) => {
setTitle(newValue);
};

const handleDescriptionUpdate = (newValue: string) => {
setDescription(newValue);
};

const handleimgUrlUpdate = (newValue: string) => {
setimgUrl(newValue);
};

const handleImdbUrlUpdate = (newValue: string) => {
setimdbUrl(newValue);
};

const handleImdbIdUpdate = (newValue: string) => {
setImdbId(newValue);
};

Choose a reason for hiding this comment

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

These functions are actually redundant

value=""
onChange={() => {}}
value={title}
onChange={handleTitleUpdate}

Choose a reason for hiding this comment

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

Suggested change
onChange={handleTitleUpdate}
onChange={setTitle}

Can be simplified just like this

>
Add
</button>
{!title || !imgUrl || !imdbUrl || !imdbId ? (

Choose a reason for hiding this comment

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

Create a variable for this condition

type="submit"
data-cy="submit-button"
className="button is-link"
disabled

Choose a reason for hiding this comment

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

Suggested change
disabled
disabled={condition}

And just use it here. No need to render two different buttons

@ivaZaiets ivaZaiets requested a review from polosanya October 23, 2023 15:36
Copy link

@StasSokolov1 StasSokolov1 left a comment

Choose a reason for hiding this comment

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

Great job, let's improve your code a bit more!


/* eslint-disable max-len */

const pattern = /^((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@,.\w_]*)#?(?:[,.!/\\\w]*))?)$/;

Choose a reason for hiding this comment

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

will be better move this into separated file like patterns

Comment on lines 140 to 141
incorrectimgUrl=""
incorrectimdbUrl=""

Choose a reason for hiding this comment

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

let's remove these props with empty string

Comment on lines +28 to +29
incorrectimgUrl,
incorrectimdbUrl,

Choose a reason for hiding this comment

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

Suggested change
incorrectimgUrl,
incorrectimdbUrl,
incorrectimgUrl = '',
incorrectimdbUrl = '',

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

// To show errors only if the field was touched (onBlur)
// const pattern = /^((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@,.\w_]*)#?(?:[,.!/\\\w]*))?)$/;

Choose a reason for hiding this comment

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

remove this comment

Comment on lines 61 to 65
{hasError ? (
<p className="help is-danger">{`${label} is required`}</p>
) : (
null
)}

Choose a reason for hiding this comment

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

Suggested change
{hasError ? (
<p className="help is-danger">{`${label} is required`}</p>
) : (
null
)}
{hasError && (
<p className="help is-danger">{`${label} is required`}</p>
)}

can be simplify

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.

Well done! 🔥

Comment on lines +84 to +86
onChange={(newValue) => {
setTitle(newValue);
}}

Choose a reason for hiding this comment

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

Suggested change
onChange={(newValue) => {
setTitle(newValue);
}}
onChange={setTitle}

Can be simplified

Comment on lines +41 to +42
setIncorrectimgUrl('Error');
setIncorrectimdbUrl('Error');

Choose a reason for hiding this comment

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

The name of the state is a bit confusing. Also, you could set the full error's text here and use it to show the user instead of the "Label is not valid"

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.

4 participants