-
Notifications
You must be signed in to change notification settings - Fork 1
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
Es pja add new item #28
Conversation
src/components/AddItemForm.js
Outdated
@@ -0,0 +1,71 @@ | |||
import React from 'react'; | |||
import { format } from '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 think this prettier
import might be what's causing the checks to fail. I'm not sure. I did run npm install
and I still get these messages in the terminal. Commenting out this import fixed it.
./src/components/AddItemForm.js
Line 2:10: 'format' is defined but never used no-unused-vars
./node_modules/prettier/parser-typescript.js
Module not found: Can't resolve '@microsoft/typescript-etw' in '/Users/ForeignFood/Development/collab_lab/tcl-6-smart-shopping-list/node_modules/prettier'
src/components/AddItemForm.js
Outdated
super(props); | ||
this.state = { | ||
name: '', | ||
next_purchase: null, |
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 couldn't find a record of it the ticket or AC, but is there supposed to be a default value for next_purchase
?
For AC next_purchase
should have an integer saved with the item. You might need an onChange={this.handleNextPurchaseChange}
similar to the one you have for the item 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.
The next_purchase
state is not updating and saving properly to the firestore database. Your item name is updating properly. To have the select drop-down update the proper numerical value to the database, there are a couple of things you need to do.
this.handleSchdeule = this.handleSchdeule.bind(this);
handleSchdeule(event) {
this.setState({
next_purchase: event.target.value,
});
}
// in the form
<select value={this.state.value}
onChange={this.handleSchdeule}> // add this like you have on the text field
<option value="7">Soon</option>
<option value="14">Kind Of Soon</option>
<option value="30">Not Soon</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.
src/components/AddItemForm.js
Outdated
//To reset the input field after the user hits submit | ||
this.setState({ | ||
name: '', | ||
ext_purchase: null, |
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.
Tyypo . . . : ) next_purchase: null,
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 could make the state reset more consistent by defining an initialState
variable.
const initialState = {
name: 'some default or blank'
}
class Form extends Component {
state = initialState
handleSubmit = event => {
...submitLogic
this.setState(initialState);
}
}
src/components/AddItemForm.js
Outdated
<br /> | ||
<label class="schedule"> | ||
Schedule: | ||
<select value={this.state.schedule}> |
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.state.schedule
should be this.state.next_purchase
src/components/AddItemForm.js
Outdated
value={this.state.name} | ||
onChange={this.handleChange} | ||
/> | ||
<input type="submit" value="Submit" /> |
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.
The submit button should be at the end of the form. You have a text field then the submit button, followed by two more form inputs. That is not good for accessibility.
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 some great work @espain16 @erostribe 👏
There are only a couple things I would add/change before merging:
- Set a default for the
select
element that is notnull
- Use
className
instead ofclass
on the form - Use
useToken
now that we have it, so we save the item with the list token the user created.
The other comments are suggestions or 🎉 Lot's of good stuff here!!
onChange={this.handleChange} | ||
/> | ||
</label> | ||
<br /> |
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 semantic and accessible form 😍
Alternatively, you could remove the <br />
tags and use css:
#addItemForm label {
display: block;
}
src/components/AddItemForm.js
Outdated
render() { | ||
return ( | ||
<form onSubmit={this.handleSubmit}> | ||
<label class="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.
🚨 React wants className
rather than class
. class
is a keyword in JS so we can't use it in jsx
.
src/components/AddItemForm.js
Outdated
</select> | ||
</label> | ||
<br /> | ||
<label class="lastpurchase">Last Purchased Date:</label> |
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.
We can probably omit this value. We'll set this value in a later story when we mark that the item has been purchased.
user_token: 'shpongle', | ||
}; | ||
|
||
this.handleChange = this.handleChange.bind(this); |
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.
Not a blocker, just FYI in case you didn't know. With create-react-apps (CRA), we have a babel feature that will let you define method without explicitly binding this
in the constructor.
handleChange = event => {
this.setState({ name: event.target.value });
}
Like the docs mention, it's an experimental feature so your mileage may vary. But it's definitely a common pattern.
src/components/AddItemForm.js
Outdated
//To reset the input field after the user hits submit | ||
this.setState({ | ||
name: '', | ||
ext_purchase: null, |
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 could make the state reset more consistent by defining an initialState
variable.
const initialState = {
name: 'some default or blank'
}
class Form extends Component {
state = initialState
handleSubmit = event => {
...submitLogic
this.setState(initialState);
}
}
@@ -0,0 +1,3 @@ | |||
import { createBrowserHistory as history } from 'history'; |
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.
What is this component for? Could it be deleted?
} | ||
|
||
handleSubmit(event) { | ||
this.props.firestore |
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.
Not at all a requirement for this ticket—just a question: How might you redirect the user back to their list after they successfully add an item?
@@ -0,0 +1,80 @@ | |||
import React from 'react'; | |||
import { withFirestore } from 'react-firestore'; | |||
import '../CSS/AddItemForm.css'; |
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.
Now that #5 is merged, you could add useToken
to this component and utilize the same token that the user has created and saved to localStorage
.
@@ -0,0 +1,3 @@ | |||
{ | |||
"liveServer.settings.port": 5502 |
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 we don't want to save this file to the repo, you can add it to .gitignore
.
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.
Like Steve said, we should exclude this file as it's a code editor configuration
} | ||
|
||
handleSchedule(event) { | ||
this.setState({ next_purchase: event.target.value }); |
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.
We will expect to use this value as a number later on to calculate the next purchase date. What data type is event.target.value
here? Is it a number? If not, how could we make it one?
One other comment: I like the before/after in the PR details—I might add an additional step in the testing steps talking about what to expect once we submit the form. Let's get in the habit of writing a thorough description (especially about what you did and why you made the choices you did). You should be able to use these PRs as a resource showing how you communicate with a remote team. Again, lot's of great work 👏👏👏 |
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.
Approving so that once you add the token as the other data point you're free to merge 💪
src/components/AddItemForm.js
Outdated
} | ||
|
||
handleSubmit(event) { | ||
const { name, next_purchase, last_purchase } = this.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.
Sorry I didn't mention this in our Slack thread, but I believe you want to store the user's token along with the other data points, correct?
src/components/AddItemForm.js
Outdated
const { name, next_purchase, last_purchase } = this.state; | ||
this.props.firestore | ||
.collection('itemform') | ||
.add({ name, next_purchase, last_purchase }) |
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.
Connected to line 32 above, store the token along with the other data
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 looks good 👍
@@ -0,0 +1,3 @@ | |||
{ | |||
"liveServer.settings.port": 5502 |
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.
Like Steve said, we should exclude this file as it's a code editor configuration
For an example of how to fill this template out, see this Pull Request.
Description
Related Issue
Closes #6
Acceptance Criteria
Type of Changes
Updates
Before
After
Testing Steps / QA Criteria
git pull origin es-pja-add-new-item
andgit checkout es-pja-add-new-item
to switch to the branch.npm install
to add dependencies, thennpm start
to run the app.