- Read Tutorial
- Watch Guide Video
Now we've got to check and see why this is happening. So let's go into first our actions let's go into user.js and let's try, let's do this, okay so the id might be wrong right, so let's console.log the id because it's clearly not setting the ID. Okay, so console.log(id) and set purchaseDetail. And you'll see it's one, and then now it is still one.
All right, that's weird. Interesting, let's check the DevTools, okay I just saw it. You'll see that, by default our purchases right, they all have a different id but when we click on an item for some reason it's setting them all to that id. So this is pretty common, we probably have a mistake in our if statement.
So let's go into vs code, let's go into userReducer.js and let's check our if statement in our SET_PURCHASE_DETAIL. Okay, you'll see that we're seeing purchase._id is equal to action.payload we're assigning the purchase ID of every single purchase and purchases to the one we first click. So we clearly don't want that, we want to check it using two equal signs okay.
case SET_PURCHASE_DETAIL: let purchaseDetail; state.purchases.map(purchase => { if(purchase._id) == action.payload) { purchaseDetail = purchase; } })
All right, it should be fixed. All right, sweet you'll see it's working now. We're getting all of our data properly. Okay cool so that's how you do that, let's go ahead and be done with this now, this part of the application. And let's move on to the account information, we have to build out the account information type, all right, so just another form it should be pretty simple.
And we're going to use form validation in redux form and then once we're done with that we will head on over to the shop where we will basically implement all of this here and then you know move from there. So in the next video we will handle the account information tab. Okay, we'll build this form pretty quickly.
So let's commit our code.
Terminal
git status git add . git commit -m "fixed bug setting user purchases Ids all the same"
Okay, I'll see you in the next video.