Kimberly-Hart / East-Barley

1 stars 1 forks source link

Cart - routing and Add to cart #90

Open phillipsja97 opened 4 years ago

phillipsja97 commented 4 years ago

DevStory

UserStory

AC

WHEN a user clicks on the add cart button THEN the item will be added to the cart AND as a user WHEN I click on the cart page THEN I should be lead to the page where I can view items in my cart, and checkout options.

DevNotes

IN EAST & BARLEY API:

IN EAST & BARLEY.UI

const getLineItemsByInvoiceId = (invoiceId) => new Promise((resolve, reject) => { axios.get(https://localhost:44319/api/invoices/lineitems/${invoiceId}) .then((result) => resolve(result.data)) .catch((error) => reject(error)); });

export default { getLineItemsByInvoiceId };

- [x] In ```cartData.js```, create a function to create a new cart, or add to new cart:

const addToExistingOrNewCart = (product) => axios.post(axios.get('https://localhost:44319/api/invoices/newCart/${userId}), newOrder);

- [x] Also in ```cartData.js```, add a method to check for a cart:

const checkForCart = (userId) => new Promise((resolve, reject) => { axios.get(https://localhost:44319/api/invoice/openCart/${userId}) .then((result) => resolve(result.data)) .catch((error) => reject(error)); });

- [x] In ```Cart.js```, add these states:

state = { openCart: [ ], lineItems: [ ], }

- [x] In ```Cart.js```, in the componentDidMount(), use the checkForCart from ```cartData.js```

componentDidMount() { const checkForOpenCart = () => { const { user } = this.props; cartData.checkForCart(user.userId) .then((openCart) => { this.setState({ openCart }); }); }; }

- [x] Next, chain this function to follow the checkForOpenCart function in the componentDidMount():

.then((invoice) => cartData.getLineItemsByInvoiceId(openCart.invoiceId) .then((lineItems) => { this.setState({ lineItems: lineItems }); }) .catch((errorFromCart) => console.error(errorFromCart)); }


- [ ] Use whatever card/list you want form semantic UI to build out the render on in Cart.js.
- [ ] In ```ProductModal.js```, create an createNewOrder function that will use the addToExistingOrNewCart data function from above. The function will create an order with these data points: ProductId, Price, and Quantity. The new order will be passed along with the userId to the function.
- [ ] Create an onChange function that will take the value from the quantity input field to use for the data point in the createNewOrder function.
- [ ] On the button in the modal for adding to cart, create an onclick function and pass the createNewOrder function into the onClick.
- [ ] Test it and see if works in the database and shows up in Cart.js.
gseals commented 4 years ago