How to Create a Drag-and-Drop Kanban Board Using React, Node.js and Socket.io (& SuprSend Notifications)?
Sanjeev Kumar
•
June 20, 2023
TABLE OF CONTENTS
In this article, we explore how to make an agile Kanban board in JIRA using the dynamic duo of React and Node.js, coupled with the flexible data storage capabilities of MongoDB. Leveraging the power of these technologies, we'll delve into the process of designing and building a highly interactive and responsive Kanban board, allowing teams to seamlessly manage and monitor their projects.
To augment the board's functionality, we'll integrate Suprsend, a centralised single notification API to power up its notification system. By incorporating Suprsend, developers can take advantage of real-time notifications, enabling teams to stay informed about critical updates and changes on the Kanban board. This added layer of communication enhances collaboration and ensures that everyone involved is promptly notified of relevant events, resulting in improved productivity and seamless project management.
Create the project folder containing two sub-folders named client and server
Copied ✔
mkdir kanban
cd kanban
mkdir client server
Setting up the Client part
Navigate into the client folder via your terminal and create a new React.js project.
Copied ✔
cd client
npx create-react-app ./
Installing dependencies
Install Socket.io client API and React Router. React Router is a popular routing library for React applications. It allows us to handle navigation and routing in a declarative manner within the React components.
Copied ✔
npm install socket.io-client react-router-dom
Cleaning up unnecessary data
Delete the redundant files such as the logo and the test files from the React app, and update the App.js file to display Hello World as below. Run npm start to verify the app is working fine.
Copied ✔
function App() {
return (
Hello World!
);
}
export default App;
Adding styles
Add the following code which contains css for the app into index.css file
Navigate into the server folder and create a package.json file.
Copied ✔
cd server
npm init -y
Installing dependencies
Install Express.js,Mongoose, dotenv, Mongodb Driver, CORS and Socket.io Server API.
Express.js is a fast, minimalist framework that provides several features for building web applications in Node.js. CORS is a Node.js package that allows communication between different domains.
Copied ✔
npm install express cors socket.io
Index.js
Create an index.js file – the entry point to the web server.
We can similarly create models for tasks,boards comments.
Adding Imports
Add Mongodb and Mongoose ODM and import models. Connect to the MongoDb Database. You can create a database for free on Mongodb. Make sure to keep the MONGODB_URI in .env instead of hardcoding it.
Next, add Socket.io to the project to create a real-time connection. Before the app.get()block, copy the code below.
Copied ✔
//New imports
.....
const socketIO = require('socket.io')(http, {
cors: {
origin: "http://localhost:3000"
}
});
// Add this before the app.get() block
socketIO.on('connection', (socket) => {
console.log(`${socket.id} User connected!`);
socket.on('disconnect', () => {
socket.disconnect()
console.log(' User disconnected');
});
});
From the code snippet above, the socket.io("connection") function establishes a connection with the React app, then creates a unique ID for each socket and logs the ID to the console whenever a user visits the web page.
When you refresh or close the web page, the socket fires the disconnect event showing that a user has disconnected from the socket.
OPTIONAL
Install Nodemon. Nodemon is a Node.js tool that automatically restarts the server after detecting file changes, and Socket.io allows us to configure a real-time connection on the server.
Configure Nodemon by adding the start command to the list of scripts in the package.json file. The code snippet below starts the server using Nodemon.
Copied ✔
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon index.js"
},
You can now run the server with Nodemon by using the command below.
Copied ✔
npm start
If you are not using nodemon, either run the server with the command "node index.js" or modify the script by adding the start command to the list of scripts in the package.json file as shown below:
Copied ✔
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
Developing UI/UX with Kanban Board Features
Let's create the UI for the application. It will have three pages: the Login page, Task page – the main part of the application, and The Comments page – where users can comment on each task.
Navigate into client/src and create a components folder containing the Login.js, Task.js, and Comments.js files.
Copied ✔
cd client/src
mkdir components
cd components
touch Login.js Task.js Comments.js
Modify the App.js file to setup the routes.
Copied ✔
import { BrowserRouter, Route, Routes } from "react-router-dom";
import Comments from "./components/Comments";
import Task from "./components/Task";
import Login from "./components/Login";
function App() {
return (
} />
} />
} />
);
}
export default App;
The Register Page
In this, User has to enter an email and a password. The details are stored in the database. After successful registration,an alert is displayed and user is redirected to login page:
Here, the application accepts the username and password, verifies the details from database and if credentials supplied are correct, alert is displayed.
React-beautiful-dnd (Drag and Drop) is a library developed by Atlassian that aims to provide a beautiful, accessible drag and drop experience for your React.js applications.
Drag and Drop functionality can greatly enhance the user experience by allowing users to physically move elements within your application, often for reordering lists or transferring items between lists.
Install React Beautiful DND and ensure you are not using React in strict mode. (Check src/index.js).
npm install react-beautiful-dnd
In server/index.js file,create an object containing all the dummy data for each task category.
Finally, add the listener for the same in server.js:
Copied ✔
socket.on("fetchComments", (data) => {
const { category, id } = data;
const taskItems = tasks[category].items;
for (let i = 0; i < taskItems.length; i++) {
if (taskItems[i].id === id) {
socket.emit("comments", taskItems[i].comments);
}
}
});
Implementing Suprsend Notifications:
SuprSend is a notification infrastructure as a service platform for easily creating, managing and delivering notifications to your end users. SuprSend has all the features set which enable you to send notifications in a reliable and scalable manner, as well as take care of end-user experience, thereby eliminating the need to build any notification service in-house.
Firstly create an account on Suprsend.
Install SuprSend Node.js SDK in the backend
Copied ✔
npm install @suprsend/node-sdk
# to upgrade to latest SDK version
npm install @suprsend/node-sdk@latest
Replace WORKSPACE KEY and WORKSPACE SECRET with your workspace values. You will get both the tokens from Suprsend dashboard (Settings page -> "API keys" section)
Create a New User. To create a new user or to update the profile of an existing user, you'll have to first instantiate the user object. Call supr_client.user.get_instance to instantiate user object.
Copied ✔
const distinct_id = "__uniq_user_id__" // Unique id of user in your application.
const user = supr_client.user.get_instance(distinct_id) // Instantiate User profile
Add the User Channels. Use user.add_* method(s) to add user channels in a profile
Copied ✔
user.add_email(`${distinct_id}`);
/* For adding slack using email of user and access token of slack app,do this: */
user.add_slack(
{
"email": `${distinct_id}`,
"Access_token": process.env.ACCESS_TOKEN
}
)
/* OR to add the incoming webhook for sending notification to slack channel, do this: */
user.add_slack(
{
"incoming_webhook": {
"url": process.env.INCOMING_WEBHOOK
}
})
// After setting the channel details on user-instance, call save()
const response1 = user.save() //save() returns promise
When you call user.save(), the SDK internally makes an HTTP call to SuprSend Platform to register this request, and you'll immediately receive a response indicating the acceptance / failure status.
Copied ✔
// Response structure
{
"success": true, // if true, request was accepted.
"status": "success",
"status_code": 202, // http status code
"message": "OK"
}
{
"success": false, // error will be present in message
"status": "fail",
"status_code": 500, // http status code
"message": "error message"
}
Create a workflow on SuprSend platform. For Event based workflow trigger, you'll have to create the workflow on SuprSend Platform.
Once the workflow is created, Add an import and then you can pass the Event name defined in workflow configuration with the help of supr_client.track_event method. Variables added in the template should be passed as event properties.
When you create an Event or a property, please ensure that the Event Name or Property Name does not start with $ or ss_, as we have reserved these symbols for our internal events and property names.
When you call supr_client.track_event, the SDK internally makes an HTTP call to SuprSend Platform to register this request, and you'll immediately receive a response indicating the acceptance status.
Copied ✔
{
"success": true, // if true, request was accepted.
"status": "success",
"status_code": 202, // http status code
"message": "Accepted",
}
{
"success": false, // error will be present in message
"status": "fail",
"status": 400, // http status code
"message": "error message",
}
The below image demonstrates a demo notification sent upon creating a task in Kanban Board to slack
Throughout the tutorial, we covered the essential steps of designing and building a highly interactive and responsive Kanban board. From setting up the development environment to implementing the board's core features, developers now have a solid foundation to create their own customized Kanban boards tailored to their specific project requirements.
Additionally, by integrating Suprsend's notification capabilities, teams can ensure that all stakeholders stay informed about important updates and changes happening on the Kanban board in real-time. This not only fosters seamless communication but also enables swift decision-making and rapid response to project developments.
Share this blog on:
Written by:
Sanjeev Kumar
Engineering, SuprSend
Get a powerful notification engine with SuprSend
Build smart notifications across channels in minutes with a single API and frontend components
By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View our Privacy Policy for more information.