Learn how to implement beautiful toast notifications using Shadcn Sonner in a Next.js 15 + MySQL job portal application! In this tutorial, we'll add toast notifications for user feedback like successful registration, password validation errors, and more. ---------------------------------------------------------------------------------- 📂 Source Code 👉 GitHub Repo: https://github.com/thapatechnical/job-portal-nextjs
⌛TIMELINE⏳ 0:00 - Introduction to Notifications 0:15 - Problem We Are Facing 0:30 - Shadcn Notification - Sonner 1:05 - Get Source Code 1:40 - How to Add Shadcn Sonner 3:20 - Add Shadcn Sonner in Job Portal App 4:30 - Adding Toaster to layout.tsx 6:10 - Return Success/Error from Server Action 7:01 - Show Toast Function in UI 8:30 - Add Toast for Password Matching 9:20 - Changing Toast Position and Rich Colors
Hello what's up guys, welcome to the next full stack project
present job portal application. Today is our day number 16
and today we are going to see that how yesterday
in such a lovely way, in such a good way
we validated the password in the registration form
and we also stored the data by hashing, you can see here.
But the problem is that if I click on it, whether it is submitted or not
whether the registration was successful or not
I don't know, I don't know anything. So today we will see that
how we can tackle this problem.
So for that guys, you will get a lot of applications.
You will get a library, but we are using Satsen here.
So there is an awesome of Satsen which we call Sonar.
So with the help of Sonar, it is basically a toastie and nothing else.
But if you click like this, you will see something like this.
You will get a lot of variety of this.
Different from success, different from warning,
different from default, different from errors.
So today in this video, I will tell you that
how you can include this kind of toast in your full stack project.
So guys, let's start the video without any delay, but before that
if you haven't checked out the previous video yet, then please do it.
Link is in the description below and you will get it in the comment section with source code.
It is a source code of github, you can copy and paste it.
And if you haven't subscribed to the channel yet, then please do it.
Our next target is 8 lakh subscribers.
And do press the bell icon so that you don't miss such awesome videos.
Alright, so see, to use every part,
by default, they tell you everything from the beginning.
Where to do what and how to do it.
So I want toast, right? If I want this toast,
then they said, first of all, on your application,
you will have to add this toast.
Because we already installed Satsen, so you don't need to install it again and again.
But if you have installed Satsen,
then there are a lot of components in it,
which are going to be used. If you want that, then we need to add.
You will have to tell your project,
that now I have this component in this Satsen,
which I need, so I have to add it.
So from this, you know that I have to do this.
After that, if you see, in your main application,
layout.tsx, because we are using TypeScript in our next project,
then it says,
that your layout.tsx file,
first of all, your toaster component,
you have to import it from our, obviously, like Sonar only,
you have to import it from there,
and you have to include your main layout there,
so that, this toaster, globally,
in any of your files or components,
you can use it without any worries.
You understand, including it here, means,
like a context API, if you remember, like a global store,
so this is your second step.
And once this much is done, and wherever you want to use your toaster,
there again, you need to use this toast function,
this is your function, which you have to use,
and then, I mean, before use, we have to import it,
and then in this way, what you have to do,
you have to make a simple call, like registration successful,
so whatever I write in this toast, I will get that notification there.
So, these three steps, which we have to follow,
to get the notification in our job portal application.
So, how will it be, first of all, what we need to do,
obviously, we need to add Sonar in our project.
So, what will we do, see, we don't have to do anything,
go here, like I said, in yesterday's video, to hash,
Argon2, today, what you have to do, you have to hit enter.
When you hit enter, then you have to see carefully,
whenever, if you remember, whenever you will work with Sidescreen,
then by default, it will make a components folder for you,
you can see clearly here, in that folder,
I know, you can't see, but now you will see, don't worry, see this,
in that, if you see, so we already have this Sonar installed,
I mean, this is not from before,
obviously, before making the video, I will practice,
so that I can give you the best education.
So, I had already installed it, so you can see,
Sonar.tsx from our components,
you can get it from the UI, something like this,
and there is variety, I mean, you can do a lot of things and changes here.
So, I mean, my first step is done,
that I have added it, after that, I have to include the toaster
in my layout.tsx,
okay, good, I will go here, so what we need to do,
like, go to layout.tsx,
and here also, if you see, so my toaster,
first of all, I need to import,
you can see a lot of things here, we have already imported the toaster,
and remember one thing, components,
right, after that we have UI,
and then we have this Sonar, so do you remember,
why did I show you Sonar in components and UI,
because from there, my toaster,
what we have to do, we have to import, never forget this,
because if you go to write toaster like this,
if I show you,
see this toaster, can you see,
from where your toaster comes, see Sonar, Sonar, Sonar,
and this comes, so make sure,
this Sonar, I mean, this toaster,
from this particular place, this destination,
you have to get from there, never forget this,
okay, once this is done, come to bottom,
and the toaster you got, right here, like this,
okay, now this is global, and once this much work is done,
now I will go to my registration form,
here, what is happening,
whenever the user is submitting the form,
this is the server action, where I am adding the data to the database,
now here I will do one thing,
if the data is successfully stored on my database,
then I have to show the success message,
if not, then I have to show the error message,
right, so what we will do,
if you see my data carefully, it is something like this,
let's go with try and then catch, if you remember, we have a try and then catch,
right, so I will remove this and keep it at the end,
so, in case, if there is any error,
any wrong word, it will catch it, right,
if everything is correct, it will come here, so what we will do,
we just have to return,
so after simple return,
paste it with curly braces,
means, in return, my status will be success, message will be
registration completed successfully,
in the same way, if there is any error, I will return there also,
but this time, this is not,
like success, then what will happen,
error will be there, and unknown error occurred, please try again later,
so now what we are doing, it is feeling better,
that if it is successful, then I am returning this message,
basically object, and if there is any error,
then I am returning this object, and where are we returning,
where this function is being called,
inside our handle submit function,
so once this part comes here,
obviously, it is getting some result,
this function returned data,
so it went to the result,
now, if my result is correct,
then my toast function,
I have to show here,
and not only this,
if you want to show in a better way, then toast.success,
to show success message,
now what message I have to show here,
if you remember, if everything is correct,
I am returning a message along with status,
by default, it is written here,
that registration completed successfully,
so I have to show that only,
so what I have to do here,
this is an object,
result.message,
this is the beauty of auto completion of TypeScript,
and here you can make it better,
not only result, status of result,
if your result is triple equal to success,
then only you have to show this,
else,
if this doesn't happen,
then copy and paste this,
but here you have to show error,
and then toast.error,
and by the way guys,
I just realized, why to show in else,
you are understanding,
this way you can show notification,
and one more thing,
instead of alert,
toast.error,
this is it,
you can't write toast as it is,
you have to import this also,
and yeah, perfect,
toast is imported,
you can see here,
that's it,
you have to pass message in object form,
check status,
let's check it out,
let me refresh it,
yeah, see,
unknown error occurred,
and by the way,
I can change its placement,
if I want to change its placement,
you can do something here,
and by the way,
I have already uploaded video on this,
link is in description,
you have to go to layout,
we have a toaster,
here you get some attributes,
like position,
you can write like this,
rich color means colorful,
error means dark red,
success means green,
you can write like this,
and if I click here,
and boom guys,
this is so awesome,
you are getting notification,
username must be unique,
these are unique,
and boom guys,
registration completed successfully,
this is so awesome,
and if I refresh it,
so yeah guys,
this is it for today's video,
I hope you liked it,
we are moving forward slowly,
password has been hashed,
notification has come,
we have seen toaster,
position has been changed,
if you have any doubt,
please comment,
I am here to help you,
and if you want to learn full stack,
you can comment,
link is in description,
and if you haven't subscribed,
please do it,
see you in tomorrow's video,
till then thank you so much,
take care.