OK we've had like five videos of buildup at this point where we've been saying that we're going to work
on our action creator to take our form values and post them to our back and server.
So it's now time to actually do it.
We're going to make sure that we send those form values to our back in API.
And then after we make sure that that request was successful we'll then redirect the user back over
to the slash surveys route.
So let's get to it.
Back inside my code editor I'm going to pull open my action create or file inside the RC actions index
file.
OK.
Inside if you're down at the bottom.
We have our submit survey action creator.
And at present we're just taking an action and returning it with a very plain type of Sumate serving
nothing special so far.
So the action clear that we want to create or the kind of the logic that we want to add to this thing
will take the form values that are being passed in and make a post request to our back and API the action
creator that we're going to make here is going to look nearly identical to the handled token action
creator right above it.
So let's get to it.
I think we've got a good idea of what we need to do.
We'll say Konst dress short for response awaits a post request being made to API slash surveys.
And then as the second argument or as the body of the request the data that we want to send to the back
end pass along the value object.
Now after this request is completed we'll then want to make sure that we dispatch some type of action
to say okay you know hey we think everything went okay here's some type of update now.
Very long time ago when we put together this API slash service route right here on our back and server
and let's pull up the code for that really quick.
So we're looking at the same thing.
So I find my routes survey routes start just file.
Here's the API SLAs surveys route that accepts a post request and you'll recall that after we eventually
sent the e-mail out saved the survey deducted the number of credits we then sent back the updated user
model and the idea here was that we had just subtracted some number of credits from the user.
And so if we instantly send back the updated user model the header could then update and reflect the
new number of credits.
And so that's exactly what we're going to do right now.
Back inside of our index stock J.S. action Kreator file We're going to take that response and dispatch
an action of type fecche user to update our local user model.
So we'll say dispatch with a type of that user and a payload of Grez data.
OK.
So I think we're ready to test this out now.
Do you recall that we don't have any logic in here right now for doing that redirect that I've said
that we want to do so after we do that.
POST request we eventually want to redirect the user over to slash service but we'll take care of that
in just a minute.
Once we know that this post request is being successfully issued so I'm going to change back to my re-act
up here we are.
You'll notice that I've got my test e-mail account still open right here.
So my test e-mail that I created is dead.
E-mail me at gmail dot com for you.
You can of course just use your personal e-mail for ensuring that these surveys are being sent out.
That was a campaign title this time around we're going to use a little bit more realistic inputs.
So I'm going to say like a campaign number ten.
I'll give it a subject line of please give feedback and e-mail body of.
Did you like our service.
And then I'm going to attempt to send this e-mail to Dev.
Email me at gmail dot com.
And just that address right there.
OK.
So now hit next.
We will review our inputs.
Everything looks good to me so I'm going to send out the survey now when I do you'll know that I have
my request Lague open right here.
Here's our request the post request that we just made it responded with a 200.
So I think that means everything is OK.
You'll notice I now have 6 credits whereas I had seven just a minute ago I should have pointed that
out but it does look like our credit is being updated correctly.
And then our e-mail has been successfully received by death.
E-mail me at gmail dot com.
And so I can now open this says.
Did you like our service and we can click yes or no.
Awesome.
So looks like everything on the form is working out pretty well at this point.
So the very last thing we have to do is make sure that after we successfully make that post request
we redirect our user back over to slash service.
So let's take care of that in the next section.