So let's get cracking.
And first, I want to navigate through the actions, want to grab all three.
Because remember, we essentially just want to add a different word in front of it.
So let me set up properly all my courses before I won't mess this up.
Then let's delete and we're just going to go here with Update.
Then we want to set up the imports.
So let's go to the app context and learn one by one.
We're looking for update user updates, success and update an error as well.
Let's say about one.
And before we do anything further in the app context, I also want to import them right away in my.
Just so that one is out of the way.
Then we want to do is go back to the Arab context, and again, the set up is going to be extremely,
extremely, extremely similar to set up user.
And before you ask, no, we cannot use the same function simply because, well, we're going to be
using off.
Correct.
And that is a good enough reason.
Now, can you somehow, someway make it as a one function?
Well, technically you can.
Again, the endpoint changes a little bit.
The user will be still the same, though, and as far as the alert text they are, technically you can
passing that data.
But this is going to be the case where I will set up new function, even though in the reducer.
Yes, a lot of the functionality is going to be exactly the same.
So first, I want to set up that loading.
Correct?
So we're going to go here with this patch.
We will set up a type and I want to go with update user and not error.
We'll go with Begin.
Let's start at one.
I know I'll get back my data and I'm not going to showcase this because we already have covered this
before, but I know that there is user location and token correct.
So let's go here with Konst user location and then token one is coming from the data.
Then I want to dispatch and pass those things to the reducer.
So what do we want to do?
What we want to go with this patch vinyl pressing type now in this case, type will be update user and
success, and let's pass in the payload and say payload.
Now that is an object.
And what do we want a passing user location and then token now?
We will add some code over here eventually, but for the time being, I simply want to dispatch the
error.
Actually, you're not for I forget, we also want to add that to the local storage, so add user to
the local storage and then let's pass in user location and the token as well.
So that's pretty much the same as the payload door here.
And then let's deal with that error where again, we wanted this patch something and that something
is going to be our error.
So type a mine, we want to go with update user and not success.
We actually want to go for the error one and not as far as the payload well.
Remember, we won't be sending back the error message, correct?
So this is the case where again, we can go with message.
No one is equal to error, then a response.
So that's the actual thing.
And then we have data and then message and at the very, very end since I'll set up the alerts.
I also want to clear them.
So let's go here with clear alert and let's hear it.
Now, once we have a list in place, let's navigate to the reducer and set up the functionality.
So we already have the actions.
Let's keep scrolling.
And again, this is going to be the case where we literally can copy and paste because I mean, most
of it is going to be exactly the same.
And yes, you can technically make this into a one function and then somehow in some way, combine it.
But I'm kind of very skeptical of that type of approach because in my opinion, that's just overcomplicating
something.
So let me take right now, the set up user begin essentially all the way to a set up user error.
Let's copy this one.
Let's keep scrolling and an almost copy and paste.
And essentially, again, same thing.
I just want to change this program.
That's all we have to do, because if we take a look at the read me effectively, the setup is going
to be exactly the same.
So instead of setup, we're going to go with update and then user, and that's it.
And once we say again, what happens over here?
Well before we send the request, we set loading to true.
Then once we're successful, we go update user success.
And in this case, what we can do, though, is just change the text where this is not going to be provided,
which show from the function.
In this case, I'll just add code.
I'll say alert type will be success and then also user profile and updated.
And when it comes to token user and user location geolocation, yes, we are setting them again from
scratch because we set up the new token and we possibly might have a new user data, correct?
And then when it comes to error, while the same deal update user error, and then I'm just looking
for the message that is in action, payload and message, and we're almost ready to take it out for
test drive.
Now one thing we need to remember, though, in the interceptors, more specifically in the request
one, we remove the authorization header.
Correct.
So we need to add that one back up otherwise well, we'll have unsuccessful requests.
So let's save this one.
And now let's navigate to the profile page.
And here I just want to change some values around where at the moment, notice this is my John user.
So why don't we change some things around where I want to go here with Susan, right?
And let's pass in the I don't know, Smith.
Maybe then I also probably want to change the email.
So in this case, I'm going to go with Susan now.
I might delete the user and then set it up from scratch in between the videos, then that is irrelevant.
And when it comes to location, let's go over here with Mexico, so let's save this.
And notice how we successfully updated the profile.
And then since we're updating the state, keep in mind that these are going to be our values correct?
Why?
Well, because if I go to the profile page, what is the value on here when there's a user email, last
name and location?
So that is correct.
And that also if I take a look at my database and effectively, I would just have to refresh in order
to see the latest changes.
What I also notice is right away the user, John, which right now has all of these values.
So now I can see that our functionality works.
We're successfully attaching the token when we're sending requests with our auth instance.
And if one of the values is missing, for example, the last name which you'll notice is the arrow that
is coming back from the server.
So this is not different than there because we did comment this one out temporarily.
This is coming back from the server and once we have.
All of this in place now, we can move on to the next step.