All right.
And I guess let's just start by setting up the loader.
So effectively, what do we want to do once we navigate to this page?
Well, we want to make a request and get the info on that specific job.
Correct.
So we're going to set up, try and catch I know I'm going to be getting back the data, basically an
object with the data property and that job is going to be there.
Then we're going to go with Await, then custom fetch Dot.
Then we're going to go with get.
But this is the case where we want to go with template strings and we're going to go to jobs and then
specific job ID and in order to access it, since I have a template string, I'm going to go here with
dollar sign, then curlies and then remember it's located in the params and I named my params the id.
And if I'm successful, I simply want to return the data.
And the job, of course, is going to be located over there.
Now, what about the error?
If let's say the ID is wrong, what do we want to do?
Well, for starters, we want to go here with toast, with an error.
And let's provide again that error.
Question mark, dot.
And we're looking for response question mark.
That and then data.
And then we're again looking for the message over here.
And also, I want to navigate back to the all jobs, because there's really no need to stay on this
page if there's something wrong with the request.
So if I cannot get the data on that specific job, there's really no point to hang out on this page.
And therefore I'm going to go with return redirect.
And here let's pass in the path.
So I want to go back to Dashboard, then forward slash and then all jobs.
Let's save it.
And if everything is correct, then of course in the edit job, I want to access that job.
Like I said, this was just for demonstration purposes, so I'm going to remove this.
And since the job is going to be located in that data, I'm going to go with job and then use loader
data.
Let's set up the log for now and if everything is correct, we should see info on that specific job.
So let me refresh again.
Let me inspect.
And in the console.
I should see the object with all of the info.
Now, of course, if I'm going to go back to all jobs and if I'm going to take a look at the other one.
So this one over here, I believe, then of course, I'll have the info on this specific job.
Now, if I'm going to mess with the ID, for example, I'll pass something that doesn't make sense.
Notice I'll nicely display the post for the error, but again, we're going to navigate back to all
jobs.
There's really no point to hang out on the edit job page, and with this in place we're done with the
loader functionality.
In edit Job page.