From 893ac6fb62aaa263343a23a0c99c19b9d0c08730 Mon Sep 17 00:00:00 2001 From: yash6318 Date: Fri, 15 Jul 2022 02:25:52 +0530 Subject: [PATCH 1/2] initial commit --- .eslintrc | 2 +- components/AddTask.js | 29 ++++++++++++ components/LoginForm.js | 46 +++++++++++++++---- components/Nav.js | 15 ++++--- components/RegisterForm.js | 2 + components/TodoListItem.js | 80 ++++++++++++++++++++++----------- context/auth.js | 15 +++++-- middlewares/auth_required.js | 16 +++++++ middlewares/no_auth_required.js | 15 ++++++- pages/index.js | 31 ++++++++++++- 10 files changed, 204 insertions(+), 47 deletions(-) diff --git a/.eslintrc b/.eslintrc index a2ceebe..97a2bb8 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,3 @@ { - "extends": ["next/babel", "next/core-web-vitals"] + "extends": ["next", "next/core-web-vitals"] } diff --git a/components/AddTask.js b/components/AddTask.js index 9652adb..522f3ae 100644 --- a/components/AddTask.js +++ b/components/AddTask.js @@ -1,10 +1,37 @@ +import { useState } from "react" +import axios from "../utils/axios"; +import { useAuth } from "../context/auth" +import { position } from "tailwindcss/lib/plugins"; + export default function AddTask() { + const [newtodo,setNewTodo]=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. */ + const dataToPost={ + "title": newtodo + } + axios + .post( + 'todo/create/', + dataToPost, + { + headers:{ + Authorization: 'Token ' + token + } + }) + .then((res)=>{ + setNewTodo(''); + alert("Task added succesfully!!"); + }).catch((err)=>{ + // alert("Some error Occured!") + console.log(err); + }) + } return (
@@ -12,6 +39,8 @@ 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' + value={newtodo} + onChange={(e)=>{setNewTodo(e.target.value)}} /> diff --git a/components/Nav.js b/components/Nav.js index e03cb0f..85563e7 100644 --- a/components/Nav.js +++ b/components/Nav.js @@ -2,13 +2,14 @@ /* eslint-disable @next/next/no-img-element */ import Link from 'next/link' import { useAuth } from '../context/auth' -/** - * - * @todo Condtionally render login/register and Profile name in NavBar - */ +import { useState ,useEffect } from 'react' + export default function Nav() { - const { logout, profileName, avatarImage } = useAuth() + const { logout, profileName, avatarImage ,token } = useAuth() + const [tokPresent,settokPresent] = useState(true) + + useEffect(()=>{(token)?settokPresent(true):settokPresent(false)},[token]) return (
From 599a357148913145099ea3f121034e5e93f8d254 Mon Sep 17 00:00:00 2001 From: yash6318 Date: Fri, 15 Jul 2022 13:33:32 +0530 Subject: [PATCH 2/2] csoc task done --- components/AddTask.js | 13 +++++-------- components/LoginForm.js | 8 ++++---- components/Nav.js | 10 +++++----- components/RegisterForm.js | 14 +++++++++----- components/TodoListItem.js | 27 ++++++++++++++++++++------- context/auth.js | 7 ++++--- package.json | 1 + pages/index.js | 3 +++ pages/login.js | 3 +++ pages/register.js | 3 +++ yarn.lock | 12 ++++++++++++ 11 files changed, 69 insertions(+), 32 deletions(-) diff --git a/components/AddTask.js b/components/AddTask.js index 522f3ae..d136def 100644 --- a/components/AddTask.js +++ b/components/AddTask.js @@ -1,17 +1,14 @@ import { useState } from "react" import axios from "../utils/axios"; import { useAuth } from "../context/auth" -import { position } from "tailwindcss/lib/plugins"; +import {toast} from 'react-toastify' +import 'react-toastify/dist/ReactToastify.css' export default function AddTask() { const [newtodo,setNewTodo]=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. - */ + const dataToPost={ "title": newtodo } @@ -26,9 +23,9 @@ export default function AddTask() { }) .then((res)=>{ setNewTodo(''); - alert("Task added succesfully!!"); + toast.success('Task added succesfully!!',{position:"bottom-right",theme:"colored"}); }).catch((err)=>{ - // alert("Some error Occured!") + toast.error('Some error Occured!',{position:"bottom-right",theme:"colored"}) console.log(err); }) diff --git a/components/LoginForm.js b/components/LoginForm.js index 32ffa28..98cdd38 100644 --- a/components/LoginForm.js +++ b/components/LoginForm.js @@ -3,7 +3,7 @@ import {No_Auth_req} from "../middlewares/no_auth_required" import { useState } from "react"; import { useAuth } from "../context/auth"; import axios from '../utils/axios' -import {API_URL} from "../utils/constants" +import { toast } from "react-toastify"; export default function RegisterForm() { No_Auth_req(); @@ -13,7 +13,7 @@ export default function RegisterForm() { const Login = () => { if (username === '' || password === '') { - alert("Do not use empty fields!"); + toast.warn('Do not use empty fields!',{position:"top-center",theme:"colored"}); return; } const dataForApiRequest = { @@ -26,10 +26,10 @@ export default function RegisterForm() { dataForApiRequest, ).then(function({data, status}) { setToken(data.token); + toast.success('Login was successful!!',{position:"top-center",theme:"colored"}) router.reload(); - alert('Login was successful!!') }).catch(function(err) { - alert('Invalid credentials! :('); + toast.error('Invalid credentials! :(',{position:"top-center",theme:"colored"}); console.log(err); }) } diff --git a/components/Nav.js b/components/Nav.js index 85563e7..4bce2aa 100644 --- a/components/Nav.js +++ b/components/Nav.js @@ -24,18 +24,18 @@ export default function Nav() { -
+
) } diff --git a/pages/login.js b/pages/login.js index 5f2bbe0..63e99f6 100644 --- a/pages/login.js +++ b/pages/login.js @@ -1,9 +1,12 @@ import LoginForm from '../components/LoginForm' +import { ToastContainer } from 'react-toastify'; +import 'react-toastify/dist/ReactToastify.css'; export default function Login() { return (
+
) } diff --git a/pages/register.js b/pages/register.js index 456003a..00a0c3e 100644 --- a/pages/register.js +++ b/pages/register.js @@ -1,9 +1,12 @@ import RegisterForm from '../components/RegisterForm' +import { ToastContainer } from 'react-toastify'; +import 'react-toastify/dist/ReactToastify.css'; export default function Register() { return (
+
) } diff --git a/yarn.lock b/yarn.lock index 11dbcb7..cd8ba45 100644 --- a/yarn.lock +++ b/yarn.lock @@ -720,6 +720,11 @@ classnames@2.2.6: resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.6.tgz#43935bffdd291f326dad0a205309b38d00f650ce" integrity sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q== +clsx@^1.1.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12" + integrity sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg== + color-convert@^1.9.0, color-convert@^1.9.1: version "1.9.3" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" @@ -2803,6 +2808,13 @@ react-refresh@0.8.3: resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.8.3.tgz#721d4657672d400c5e3c75d063c4a85fb2d5d68f" integrity sha512-X8jZHc7nCMjaCqoU+V2I0cOhNW+QMBwSUkeXnTi8IPe6zaRWfn60ZzvFDZqWPfmSJfjub7dDW1SP0jaHWLu/hg== +react-toastify@^9.0.5: + version "9.0.5" + resolved "https://registry.yarnpkg.com/react-toastify/-/react-toastify-9.0.5.tgz#310d7bcfcf3887c0e8461ac6068fe1abb8d720e1" + integrity sha512-dszPCeQINY+Nm6HmsiAXT/7wsazPqv0S/RuhIYLAW+fTKcd3T1iRjZG0XqrN9nvAzqaE5J6uxMaiBrOevxjY8g== + dependencies: + clsx "^1.1.1" + react@17.0.2: version "17.0.2" resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"