Create New Newsletters from the Client on the Backend
All right welcome back to the course. We've set this backend up let's test it out.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

Before we test it let's look at our parameters because it looks like we're passing in props._id, we don't want to pass in the id and we don't even have access to it, we don't want to tell the backend who's posting this newsletter because it doesn't matter, it's only going to be an admin clearly and it just doesn't matter.

Now the thing is in the future it might matter, like if the client you're developing this application for came back to you and was like hey we want to be able to tell who's posted these newsletters, there's multiple admins. Can you get that information for all of the past newsletters that have been posted?

Now if you set it up like that from the start you can be like yeah, and that might help them out because for whatever reason right. So it might be a good idea if you're developing an application like this just to develop that feature from the get go, just in case in the future for whatever reason they want to be able to keep track of who has posted these newsletters and they want that information since the start.

So in this case since we're not doing it you'd have to be like no sorry I can't get who's posted that in the past. But I can implement that feature and keep track of it from now on. So it might be a good idea just to do that because it's not going to hurt, it's only going to help you. Its not too much more code it's like one line on the backend and the front end, so yeah, but we're not going to do that because that will just distract us.

So create new newsletter, now let's go into newsletters.js and let's get rid of the user ID parameter and we should be good to go. Let's go ahead and test it out by going into Chrome logging in and going to newsletter. And basically what's happening is we don't have any newsletters on the backend, so keep that in mind. So when we create one we're going to get an error and I'll show you what that is.

Let's say new newsletter, "new newsletter item" and let's go into lipsum.com to get some dummy text. Now this is completely optional, the only reason I'm doing this is so I can have some dummy text. I'm going to keep the console open and I'm going to choose an image. I'm going to choose this big image and just see how it reacts on the backend, see if it takes forever to load just out of curiosity.

Now it shouldn't because it's all local, but anyway let's go ahead and hit submit and it says success save newsletters, scroll up and you'll see we have four errors or so but you'll see that it saved the newsletter and that's what's important.

large

Now the reason we're getting this error is because we're now fetching our newsletters back. So we've created a newsletter, we're being pushed back to the dashboard. So we create a newsletter, we get the response which was that success a true message saved newsletter, so that's all good and then we hit the success callback and we go back to newsletterNew.js, we go back here and it pushes us to dashboard.

large

Now the reason we're getting this error is because when we're getting pushed back to newsletterGrid it's fetching our newsletters, now what's happening is its getting our data and then it's trying to parse the state, it's going through our components like newsletterBox and archive and trying to display those dates. But we can't display those dates because they're not in date format it's a string.

So what we need to do in the next video is parse these dates into actual JavaScript date objects once we get it back from the server and have it display a date because it's just json and json can't contain an actual date object, it's a string, so we need to parse that into a date object. So really simple let's commit our code and do that in the next video.

Terminal

git status
git add .
git commit -m "finished create new newsletter action creator and tested it out"

Okay, I'll see you in the next guide.

Resources

Source code