1 00:00:00,720 --> 00:00:05,490 OK we've had like five videos of buildup at this point where we've been saying that we're going to work 2 00:00:05,490 --> 00:00:09,360 on our action creator to take our form values and post them to our back and server. 3 00:00:09,360 --> 00:00:11,620 So it's now time to actually do it. 4 00:00:11,700 --> 00:00:15,510 We're going to make sure that we send those form values to our back in API. 5 00:00:15,600 --> 00:00:20,310 And then after we make sure that that request was successful we'll then redirect the user back over 6 00:00:20,310 --> 00:00:22,660 to the slash surveys route. 7 00:00:22,680 --> 00:00:24,400 So let's get to it. 8 00:00:24,480 --> 00:00:31,870 Back inside my code editor I'm going to pull open my action create or file inside the RC actions index 9 00:00:32,290 --> 00:00:33,250 file. 10 00:00:33,740 --> 00:00:34,230 OK. 11 00:00:34,440 --> 00:00:35,820 Inside if you're down at the bottom. 12 00:00:35,820 --> 00:00:38,340 We have our submit survey action creator. 13 00:00:38,640 --> 00:00:44,450 And at present we're just taking an action and returning it with a very plain type of Sumate serving 14 00:00:44,580 --> 00:00:46,680 nothing special so far. 15 00:00:46,980 --> 00:00:51,600 So the action clear that we want to create or the kind of the logic that we want to add to this thing 16 00:00:51,870 --> 00:00:58,110 will take the form values that are being passed in and make a post request to our back and API the action 17 00:00:58,110 --> 00:01:02,670 creator that we're going to make here is going to look nearly identical to the handled token action 18 00:01:02,670 --> 00:01:03,990 creator right above it. 19 00:01:03,990 --> 00:01:04,940 So let's get to it. 20 00:01:04,980 --> 00:01:07,410 I think we've got a good idea of what we need to do. 21 00:01:07,830 --> 00:01:16,630 We'll say Konst dress short for response awaits a post request being made to API slash surveys. 22 00:01:16,920 --> 00:01:21,860 And then as the second argument or as the body of the request the data that we want to send to the back 23 00:01:21,870 --> 00:01:26,850 end pass along the value object. 24 00:01:26,850 --> 00:01:31,890 Now after this request is completed we'll then want to make sure that we dispatch some type of action 25 00:01:31,890 --> 00:01:37,340 to say okay you know hey we think everything went okay here's some type of update now. 26 00:01:37,380 --> 00:01:43,560 Very long time ago when we put together this API slash service route right here on our back and server 27 00:01:43,630 --> 00:01:45,160 and let's pull up the code for that really quick. 28 00:01:45,210 --> 00:01:46,590 So we're looking at the same thing. 29 00:01:46,800 --> 00:01:50,850 So I find my routes survey routes start just file. 30 00:01:50,850 --> 00:01:57,720 Here's the API SLAs surveys route that accepts a post request and you'll recall that after we eventually 31 00:01:57,810 --> 00:02:04,650 sent the e-mail out saved the survey deducted the number of credits we then sent back the updated user 32 00:02:04,740 --> 00:02:10,780 model and the idea here was that we had just subtracted some number of credits from the user. 33 00:02:10,800 --> 00:02:16,170 And so if we instantly send back the updated user model the header could then update and reflect the 34 00:02:16,170 --> 00:02:17,760 new number of credits. 35 00:02:17,910 --> 00:02:20,730 And so that's exactly what we're going to do right now. 36 00:02:20,730 --> 00:02:26,460 Back inside of our index stock J.S. action Kreator file We're going to take that response and dispatch 37 00:02:26,460 --> 00:02:31,390 an action of type fecche user to update our local user model. 38 00:02:31,440 --> 00:02:40,540 So we'll say dispatch with a type of that user and a payload of Grez data. 39 00:02:41,130 --> 00:02:41,510 OK. 40 00:02:41,610 --> 00:02:43,730 So I think we're ready to test this out now. 41 00:02:43,740 --> 00:02:48,000 Do you recall that we don't have any logic in here right now for doing that redirect that I've said 42 00:02:48,000 --> 00:02:50,790 that we want to do so after we do that. 43 00:02:50,880 --> 00:02:55,890 POST request we eventually want to redirect the user over to slash service but we'll take care of that 44 00:02:55,890 --> 00:02:56,580 in just a minute. 45 00:02:56,580 --> 00:03:02,490 Once we know that this post request is being successfully issued so I'm going to change back to my re-act 46 00:03:02,490 --> 00:03:03,970 up here we are. 47 00:03:04,020 --> 00:03:07,470 You'll notice that I've got my test e-mail account still open right here. 48 00:03:07,470 --> 00:03:09,820 So my test e-mail that I created is dead. 49 00:03:09,830 --> 00:03:12,210 E-mail me at gmail dot com for you. 50 00:03:12,200 --> 00:03:17,250 You can of course just use your personal e-mail for ensuring that these surveys are being sent out. 51 00:03:17,310 --> 00:03:21,630 That was a campaign title this time around we're going to use a little bit more realistic inputs. 52 00:03:21,810 --> 00:03:26,680 So I'm going to say like a campaign number ten. 53 00:03:26,970 --> 00:03:33,300 I'll give it a subject line of please give feedback and e-mail body of. 54 00:03:33,300 --> 00:03:36,020 Did you like our service. 55 00:03:36,330 --> 00:03:40,160 And then I'm going to attempt to send this e-mail to Dev. 56 00:03:40,170 --> 00:03:43,600 Email me at gmail dot com. 57 00:03:43,830 --> 00:03:45,810 And just that address right there. 58 00:03:46,280 --> 00:03:46,550 OK. 59 00:03:46,560 --> 00:03:47,720 So now hit next. 60 00:03:47,760 --> 00:03:50,490 We will review our inputs. 61 00:03:50,490 --> 00:03:55,740 Everything looks good to me so I'm going to send out the survey now when I do you'll know that I have 62 00:03:55,740 --> 00:03:58,080 my request Lague open right here. 63 00:03:58,110 --> 00:04:02,570 Here's our request the post request that we just made it responded with a 200. 64 00:04:02,580 --> 00:04:04,540 So I think that means everything is OK. 65 00:04:04,860 --> 00:04:09,660 You'll notice I now have 6 credits whereas I had seven just a minute ago I should have pointed that 66 00:04:09,660 --> 00:04:13,020 out but it does look like our credit is being updated correctly. 67 00:04:13,020 --> 00:04:16,820 And then our e-mail has been successfully received by death. 68 00:04:16,830 --> 00:04:18,590 E-mail me at gmail dot com. 69 00:04:18,700 --> 00:04:21,020 And so I can now open this says. 70 00:04:21,030 --> 00:04:23,790 Did you like our service and we can click yes or no. 71 00:04:23,790 --> 00:04:24,390 Awesome. 72 00:04:24,390 --> 00:04:28,150 So looks like everything on the form is working out pretty well at this point. 73 00:04:28,170 --> 00:04:32,550 So the very last thing we have to do is make sure that after we successfully make that post request 74 00:04:32,880 --> 00:04:36,600 we redirect our user back over to slash service. 75 00:04:36,690 --> 00:04:39,040 So let's take care of that in the next section.