So now we want to be able to mark the order as delivered.
And of course only admins should be able to do this.
So the first step is on the back end.
If we go to our order controller, you should already have the method here, the function update order
to deliver.
We just need to finish it.
So let's get rid of that.
And first thing we want to do is get the order right.
So we're going to get it by the ID because we're getting it's going to be passed in right here and then
we're going to check for the order.
And if it's there, then we're going to set the is delivered to true.
We're going to set delivered at to the current date and time.
We're going to save it.
Put the result which is the the updated order into a variable and then respond with it.
So very simple.
And then we'll just have an else here where if there is no order, we have we throw an error with a
404 and that's it.
So let's save that.
And now we can go over to the front end and let's go into slices and order slices.
We'll go right under, get orders and we're going to call this one deliver order.
And that's going to be a mutation because we're changing something.
Our query is going to take in an order ID, The URL is going to be that.
Let's just double check, make sure that's yep, that looks correct.
And then the method will be put because we're changing something.
All right.
So we just need to export that, let's say use deliver order mutation, make sure you use mutation because
it's not a query, it's a mutation.
So now what we want to do is go into our order screen, not the list order screen, but the actual order
screen.
And we want to bring that mutation in.
So we're already bringing in a few things from that file.
Now we want to bring use deliver.
Order mutation.
And then we'll.
Go.
Let's see.
We'll just go like.
I guess, right here.
And we want to in brackets, we want to get deliver order and then we'll also get the loading.
R is loading, but we want to rename that because we're already using is loading.
Let's call it loading deliver.
Okay.
Now we do need a handler.
Actually, we'll do that after.
Let's create the button first.
So we should have a placeholder down here.
If you've been following along.
So right here, Mark is delivered placeholder and we first want to check if it's loading.
So we'll say if loading deliver, then show the loader.
And then underneath that, I don't know why it's doing these indents.
Underneath that, this is where we're going to use the user info.
So I'll just type this out.
So we'll say use if user info, right.
And we want to make sure the user is an admin.
So and user info dot.
Is admin.
So if that's true.
Then let's see.
Just trying to make sure that this is correct.
Yeah.
So then we also want to make sure the order is paid.
We're not going to deliver it without being paid and we want to make sure it's not already delivered.
So if all that's true, then we can proceed to add our list group item.
And in that list group item, we'll have a button.
It's going to have a type of button class name, BTN, BTN, Block, and then an onClick handler called
Deliver Deliver order handler.
And inside the button we'll just say Mark as delivered.
So if I save that, we're going to get an error because we don't have this handler yet, so let's go
ahead and create that.
And that should be the last thing we have to do and it should work.
So let's come up here.
Okay, we'll create our handler.
And what we're going to want to do in here is simply call deliver order.
And yeah, we can put it in a try catch.
So we're awaiting on deliver order, which is from our slice, which communicates with our back end,
our mutation and pass in the order ID then we're going to just re fetch because we want that read to
change to green and then a success.
And if there's an error, then we'll show the message.
So let's save that and let's see.
Oh, use info.
Is not to find deliver order.
Handler Yeah.
So this should be deliver order Handler And it looks like.
I put u's info instead of user info down here.
Okay.
So now.
This says, Oh, never mind.
I'm sorry.
The button is actually going to be over here.
I was thinking it was going to be over here, but yeah, so if if the order is not paid, then you're
going to see the pay buttons here.
If it is paid and you're logged in as admin and it's not delivered, you're going to see this button.
So let's try it out.
It shows the loading for a second, shows the order delivered and it changes to Green because it refreshes
and updates the page, updates the database and now we're all good.
If I reload, that should still be delivered.
And now if we go to the order list page, we should see instead of a red x, you should see the date
of order delivered.
All right, cool.
So everything is going really smooth.
So in the next video, what I want to do is move to products because obviously you need a way to add
products to your your application to your store.
So we're going to do that in the next video.