From b3d36b3b61b29a165e2784581f9786bd728706b5 Mon Sep 17 00:00:00 2001
From: Archit Pattanaik <98776672+archit-2003@users.noreply.github.com>
Date: Sun, 26 Jun 2022 20:03:55 +0530
Subject: [PATCH 01/22] Update auth_required.js
---
middlewares/auth_required.js | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/middlewares/auth_required.js b/middlewares/auth_required.js
index 7f5e7bc..b657d32 100644
--- a/middlewares/auth_required.js
+++ b/middlewares/auth_required.js
@@ -1,3 +1,24 @@
/***
* @todo Redirect the user to login page if token is not present.
*/
+ import { useEffect} from 'react'
+
+ import { useAuth } from '../context/auth'
+ import { useRouter } from 'next/router'
+
+ export function authRequired(){
+
+ const { token } = useAuth()
+
+ const router = useRouter()
+
+ useEffect(()=>{
+ if(token===undefined){
+ router.push('/login');
+ }
+ },[token])
+
+
+ } ;
+
+
From 95773ddea70cae31f5365e125632471993d090e5 Mon Sep 17 00:00:00 2001
From: Archit Pattanaik <98776672+archit-2003@users.noreply.github.com>
Date: Sun, 26 Jun 2022 20:05:15 +0530
Subject: [PATCH 02/22] Update no_auth_required.js
---
middlewares/no_auth_required.js | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/middlewares/no_auth_required.js b/middlewares/no_auth_required.js
index 82558d4..fb02b20 100644
--- a/middlewares/no_auth_required.js
+++ b/middlewares/no_auth_required.js
@@ -1,3 +1,21 @@
/***
* @todo Redirect the user to main page if token is present.
- */
\ No newline at end of file
+ */
+ import { useEffect, useState } from 'react'
+ import { useAuth } from '../context/auth'
+ import { useRouter } from 'next/router'
+
+ export function noAuthRequired(){
+
+ const { token } = useAuth()
+
+ const router = useRouter()
+
+ useEffect(()=>{
+ if(token){
+ router.push('/');
+ }
+ },[token])
+
+
+ };
From 6ab611f7841581509b37e94d8625352e0da11799 Mon Sep 17 00:00:00 2001
From: Archit Pattanaik <98776672+archit-2003@users.noreply.github.com>
Date: Sun, 26 Jun 2022 20:06:02 +0530
Subject: [PATCH 03/22] Update .eslintrc
---
.eslintrc | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/.eslintrc b/.eslintrc
index a2ceebe..0b5b69d 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -1,3 +1,6 @@
{
- "extends": ["next/babel", "next/core-web-vitals"]
+ "extends": [
+ "next",
+ "next/core-web-vitals"
+ ]
}
From e464281412e5bd430e22720295a9dac38de0ebc0 Mon Sep 17 00:00:00 2001
From: Archit Pattanaik <98776672+archit-2003@users.noreply.github.com>
Date: Sun, 26 Jun 2022 20:23:51 +0530
Subject: [PATCH 04/22] Update AddTask.js
---
components/AddTask.js | 48 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 43 insertions(+), 5 deletions(-)
diff --git a/components/AddTask.js b/components/AddTask.js
index 9652adb..44e1561 100644
--- a/components/AddTask.js
+++ b/components/AddTask.js
@@ -1,10 +1,44 @@
+import React, { useState} from 'react'
+import axios from '../utils/axios'
+import { useAuth } from "../context/auth"
+import { toast, ToastContainer } from 'react-toastify';
+import 'react-toastify/dist/ReactToastify.css';
+
export default function AddTask() {
+ const [task, setTask] = useState("")
+ const {token} = useAuth()
+
const addTask = () => {
- /**
- * @todo Complete this function.
- * @todo 1. Send the request to add the task to the backend server.
- * @todo 2. Add the task in the dom.
- */
+
+ if(task==="") {
+ toast.warn("Don't leave task empty......")
+ return;
+ }
+
+ toast.info('Please wait...',{position: "top-center",autoClose: 1000})
+
+ const dataForApiRequest = {
+ title: task
+ }
+
+ const headersForApiRequest = {
+ headers: {Authorization: 'Token ' + token,}
+ }
+
+
+ axios.post(
+ '/todo/create/',dataForApiRequest,headersForApiRequest,
+ )
+ .then(function ({ data, status }) {
+ setTask("");
+ toast.success("Your Task has been added in the Todo Succesfully....",{position: "top-center"})
+ })
+ .catch(function (err) {
+ toast.error("Unable to add Task. Please try again ....",{position: "top-center"})
+ })
+ }
+
+
}
return (
@@ -12,6 +46,10 @@ export default function AddTask() {
type='text'
className='todo-add-task-input px-4 py-2 placeholder-blueGray-300 text-blueGray-600 bg-white rounded text-sm border border-blueGray-300 outline-none focus:outline-none focus:ring w-full'
placeholder='Enter Task'
+ name='task'
+ id='task'
+ value={task}
+ onChange={(e) => setTask(e.target.value)}
/>