Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Week 4 #6

Merged
merged 20 commits into from
Apr 10, 2019
Merged

Week 4 #6

merged 20 commits into from
Apr 10, 2019

Conversation

apedroferreira
Copy link
Contributor

No description provided.

Copy link
Contributor

@dannytce dannytce 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 guys! :)

I found only a couple of things.

One thing regarding API - could you please create api/customers folder? :)

@@ -25,5 +25,6 @@ module.exports = {
'prefer-named-capture-group': 0,
'react/no-did-mount-set-state': 1,
'react/prop-types': 1,
'no-shadow': [2, { allow: ['name'] }],
Copy link
Contributor

Choose a reason for hiding this comment

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

Kudos for not disabling the whole rule, but just allowing what needs to be allowed 💪

@@ -1,5 +1,6 @@
{
"extends": [
"@strv/stylelint-config-styled-components"
"@strv/stylelint-config-styled-components",
"stylelint-config-prettier"
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know about it 😅 Thanks for educating :D

display: flex;
flex-direction: column;
margin: 14px auto;
max-width: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't be this opossite? :) max-width: 420px; and width: 100%

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both work but yeah that makes more sense.

<Wrapper>
<Label htmlFor={name}>{label}</Label>
<StyledInput
hasError={!!error}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use Boolean operator instead of !!. It's much easier for our students to follow.

renderSuccess() {
return (
<Layout>
<H1 textAlign="center">{`You've signed up!`}</H1>
Copy link
Contributor

Choose a reason for hiding this comment

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

It could be just a string, no need to for template literals

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because there was an ESLint warning about the apostrophe. Would you prefer if I used &#8217? Or just disable the rule?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ESLint... ok than :)

values,
}) => (
<Form onSubmit={handleSubmit}>
{!!globalError && (
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, please use Boolean operator.

type="text"
label="First name"
value={values.firstName}
onChange={handleChange}
Copy link
Contributor

Choose a reason for hiding this comment

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

You are missing per Input onBlur event too. This leads to unexpected behavior with error messages (because when navigation accross input, touched wouldn't happen).

So either fix it by adding onBlur everywhere. Or go easily with Field from formik :) Btw, have you considered using it? Or why you actually didn't use it in the first place? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it but wanted to reduce complexity. Also thought the error messages aren't perfect. Will try to improve it and use Field ;)

export const fetchAPI = async (url, options) => {
const token = await getAccessToken()

const response = await fetch(`${config.apiUrl}/${url}`, {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is extra / in url, because other api calls have it in the beginning :) Pick one of them, but current solution. is not working

src/App.js Outdated
@@ -16,7 +18,8 @@ class App extends Component {
<GlobalStyles />
<Switch>
<Route path="/" exact component={ProductList} />
<Route path="/cart" component={Cart} />
<PrivateRoute path="/cart" component={Cart} />
Copy link
Contributor

Choose a reason for hiding this comment

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

For demonstration purposes let's rather create a new route. Let's say "My Profile". Don't need to implement it (add there a comment, that students can do that by them selfs if want to).

But anyway, "privatization" of Cart could lead into more discussions (aka it's possible to add product to cart without beiing logged in, but not seeing the cart... etc.). So let's use the simpliest version, which could be My Profile :P

@apedroferreira
Copy link
Contributor Author

@dannytce Added a commit with code review fixes and some other, let me know if it's all good!

@@ -7,7 +7,7 @@ export const fetchAPI = async (url, options) => {
const response = await fetch(`${config.apiUrl}/${url}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Content-Type': 'application/vnd.api+json',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@prichodko If we don't use this Content-Type while creating customer it breaks the API :) I think we can use it everywhere.

<Label htmlFor={name}>{label}</Label>
<Field
name={name}
render={({ field }) => (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to use render here or the hasError prop throws a console error.

Copy link
Contributor

@prichodko prichodko left a comment

Choose a reason for hiding this comment

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

Left a few inline comments, to simplify code even more :)


import { Wrapper, Label, StyledInput, StyledError } from './styled'

const Input = ({ error, isTouched, label, name, type = 'text' }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can tak error and touched from form props by the name and therefore you won't have to pass it in the actual form and leverage the Formik context.

return (
    <Field name={name}>
      {({ field, form }) => {
        const error = form.errors[name]
        const isTouched = form.touched[name]
        const isInvalid = isTouched && Boolean(error)
// ...
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, didn't know this :)

)}
<Input
name="firstName"
type="text"
Copy link
Contributor

Choose a reason for hiding this comment

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

You have declared type = 'text' as a default prop, so you don't have to pass it here.

name="firstName"
type="text"
label="First name"
isTouched={touched.firstName}
Copy link
Contributor

Choose a reason for hiding this comment

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

You can get rid of isTouched and error prop. :)

@dannytce dannytce merged commit ff97516 into master Apr 10, 2019
@dannytce dannytce deleted the week4 branch April 10, 2019 10:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants