-
Notifications
You must be signed in to change notification settings - Fork 8
Week 4 #6
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.
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'] }], |
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.
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" |
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.
I didn't know about it 😅 Thanks for educating :D
src/components/Form/index.js
Outdated
display: flex; | ||
flex-direction: column; | ||
margin: 14px auto; | ||
max-width: 100%; |
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.
Shouldn't be this opossite? :) max-width: 420px;
and width: 100%
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.
Both work but yeah that makes more sense.
src/components/Input/index.js
Outdated
<Wrapper> | ||
<Label htmlFor={name}>{label}</Label> | ||
<StyledInput | ||
hasError={!!error} |
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.
Please use Boolean
operator instead of !!
. It's much easier for our students to follow.
src/pages/SignUp/index.js
Outdated
renderSuccess() { | ||
return ( | ||
<Layout> | ||
<H1 textAlign="center">{`You've signed up!`}</H1> |
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.
It could be just a string, no need to for template literals
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.
This is because there was an ESLint warning about the apostrophe. Would you prefer if I used ’
? Or just disable the rule?
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.
Ah, ESLint... ok than :)
src/pages/SignUp/index.js
Outdated
values, | ||
}) => ( | ||
<Form onSubmit={handleSubmit}> | ||
{!!globalError && ( |
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.
Same here, please use Boolean operator.
src/pages/SignUp/index.js
Outdated
type="text" | ||
label="First name" | ||
value={values.firstName} | ||
onChange={handleChange} |
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.
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? :)
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.
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
;)
src/api/fetch-api.js
Outdated
export const fetchAPI = async (url, options) => { | ||
const token = await getAccessToken() | ||
|
||
const response = await fetch(`${config.apiUrl}/${url}`, { |
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 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} /> |
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.
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
5839d56
to
5748815
Compare
@dannytce Added a commit with code review fixes and some other, let me know if it's all good! |
src/api/fetch-api.js
Outdated
@@ -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', |
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.
@prichodko If we don't use this Content-Type while creating customer it breaks the API :) I think we can use it everywhere.
src/components/Input/index.js
Outdated
<Label htmlFor={name}>{label}</Label> | ||
<Field | ||
name={name} | ||
render={({ field }) => ( |
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.
Had to use render
here or the hasError
prop throws a console error.
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.
Left a few inline comments, to simplify code even more :)
src/components/Input/index.js
Outdated
|
||
import { Wrapper, Label, StyledInput, StyledError } from './styled' | ||
|
||
const Input = ({ error, isTouched, label, name, type = 'text' }) => { |
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.
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)
// ...
...
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.
Thanks, didn't know this :)
src/pages/SignUp/index.js
Outdated
)} | ||
<Input | ||
name="firstName" | ||
type="text" |
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.
You have declared type = 'text'
as a default prop, so you don't have to pass it here.
src/pages/SignUp/index.js
Outdated
name="firstName" | ||
type="text" | ||
label="First name" | ||
isTouched={touched.firstName} |
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.
You can get rid of isTouched
and error
prop. :)
* Add create-customer API call * Implement sign up form with styles and libraries * General layout improvement * ESLint and stylelint configuration fixes
* Code review fixes * Integration fixes * Use rem and themes in styles
* Formik Input refactoring * Omit default props
No description provided.