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..d136def 100644 --- a/components/AddTask.js +++ b/components/AddTask.js @@ -1,10 +1,34 @@ +import { useState } from "react" +import axios from "../utils/axios"; +import { useAuth } from "../context/auth" +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 + } + axios + .post( + 'todo/create/', + dataToPost, + { + headers:{ + Authorization: 'Token ' + token + } + }) + .then((res)=>{ + setNewTodo(''); + toast.success('Task added succesfully!!',{position:"bottom-right",theme:"colored"}); + }).catch((err)=>{ + toast.error('Some error Occured!',{position:"bottom-right",theme:"colored"}) + console.log(err); + }) + } return (
@@ -12,6 +36,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..4bce2aa 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 (
) } 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"