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

Es pja add new item #28

Merged
merged 19 commits into from
Apr 20, 2020
Merged

Es pja add new item #28

merged 19 commits into from
Apr 20, 2020

Conversation

erostribe
Copy link
Contributor

For an example of how to fill this template out, see this Pull Request.

Description

Related Issue

Closes #6

Acceptance Criteria

  • User is presented with a form that allows them to enter the name of the item and select how soon they anticipate needing to buy it again (Soon, Kind of soon, Not soon)
  • When the user submits the form, the item is saved to the database, associated with the user’s token
  • Along with the item name, an integer corresponding to the estimated number of days until next purchase is saved: 7 for “Soon”, 14 for “Kind of soon”, and 30 for “Not soon”
  • The last purchased date should be set to null initially (i.e. you can create an item without purchasing it)

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
💯 Add tests
🔗 Update dependencies
📜 Docs

Updates

Before

Image 4-17-20 at 4 37 PM (1)

After

Image 4-17-20 at 4 29 PM

Testing Steps / QA Criteria

  1. Git pull the branch using git pull origin es-pja-add-new-item and git checkout es-pja-add-new-item to switch to the branch.
  2. Run npm install to add dependencies, then npm start to run the app.
  3. When the app runs in the browser, you will be presented with a page titled "Shopping List" with two buttons "Shopping" and "Add Item."
  4. Clicking "Add Item" should present a form with a "Name" input, a Schedule option with a dropdown menu and 3 choices, and a Submit button.

@@ -0,0 +1,71 @@
import React from 'react';
import { format } from 'prettier';
Copy link
Contributor

@skillitzimberg skillitzimberg Apr 18, 2020

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'

super(props);
this.state = {
name: '',
next_purchase: null,
Copy link
Contributor

@skillitzimberg skillitzimberg Apr 18, 2020

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.

Copy link
Contributor

@SaraSweetie SaraSweetie Apr 18, 2020

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>

Copy link
Collaborator

Choose a reason for hiding this comment

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

The select element expects to have some value passed to it. null throws an error:

I would make the default 14 (kinda soon).

//To reset the input field after the user hits submit
this.setState({
name: '',
ext_purchase: null,
Copy link
Contributor

@skillitzimberg skillitzimberg Apr 18, 2020

Choose a reason for hiding this comment

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

Tyypo . . . : ) next_purchase: null,

Copy link
Collaborator

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);
  }
}

<br />
<label class="schedule">
Schedule:
<select value={this.state.schedule}>
Copy link
Contributor

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

value={this.state.name}
onChange={this.handleChange}
/>
<input type="submit" value="Submit" />
Copy link
Contributor

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.

Copy link
Collaborator

@stevelikesmusic stevelikesmusic left a 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:

  1. Set a default for the select element that is not null
  2. Use className instead of class on the form
  3. 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 />
Copy link
Collaborator

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;
}

render() {
return (
<form onSubmit={this.handleSubmit}>
<label class="name">
Copy link
Collaborator

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.

</select>
</label>
<br />
<label class="lastpurchase">Last Purchased Date:</label>
Copy link
Collaborator

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);
Copy link
Collaborator

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.

//To reset the input field after the user hits submit
this.setState({
name: '',
ext_purchase: null,
Copy link
Collaborator

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';
Copy link
Collaborator

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
Copy link
Collaborator

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';
Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Member

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 });
Copy link
Collaborator

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?

@stevelikesmusic
Copy link
Collaborator

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 👏👏👏

Copy link
Member

@segdeha segdeha left a 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 💪

}

handleSubmit(event) {
const { name, next_purchase, last_purchase } = this.state;
Copy link
Member

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?

const { name, next_purchase, last_purchase } = this.state;
this.props.firestore
.collection('itemform')
.add({ name, next_purchase, last_purchase })
Copy link
Member

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

Copy link
Member

@segdeha segdeha left a 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
Copy link
Member

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

@espain16 espain16 merged commit 0a7102d into master Apr 20, 2020
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. As a user, I want to add a new item to my shopping list
6 participants