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"
+ ]
}
diff --git a/components/AddTask.js b/components/AddTask.js
index 9652adb..b3623b2 100644
--- a/components/AddTask.js
+++ b/components/AddTask.js
@@ -1,17 +1,53 @@
+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 (
+
setTask(e.target.value)}
/>
- )
-}
+ )
+
+ }
+
+
diff --git a/components/LoginForm.js b/components/LoginForm.js
index fa28f9e..fbd88ff 100644
--- a/components/LoginForm.js
+++ b/components/LoginForm.js
@@ -1,11 +1,49 @@
-export default function RegisterForm() {
+import React, { useState } from 'react'
+import { useAuth } from '../context/auth'
+import {noAuthRequired} from '../middlewares/no_auth_required'
+import { useRouter } from 'next/router'
+import axios from '../utils/axios'
+import 'react-toastify/dist/ReactToastify.css';
+import { ToastContainer, toast } from 'react-toastify';
+
+
+export default function LoginForm() {
+
+ const { setToken } = useAuth()
+ const router = useRouter()
+
+ noAuthRequired ();
+
+ const [password, setPassword] = useState('')
+ const [username, setUsername] = useState('')
+
+
const login = () => {
- /***
- * @todo Complete this function.
- * @todo 1. Write code for form validation.
- * @todo 2. Fetch the auth token from backend and login the user.
- * @todo 3. Set the token in the context (See context/auth.js)
- */
+ if (username === '' ||password === '') {
+
+ toast.warn("Please Don't leave any empty spaces....",{position: "top-center"});
+ return
+ }
+
+ const dataForApiRequest = {
+ username: username,
+ password: password
+ }
+
+ axios.post(
+ 'auth/login/',
+ dataForApiRequest,
+ )
+ .then(function ({ data, status }) {
+ setToken(data.token)
+ toast.success("You have been logged in succesfully....",{position: "top-center"})
+ router.reload()
+ })
+ .catch(function (err) {
+ toast.error('Unable to log in...Please try again.... ',{position: "top-center"})
+ })
+
+
}
return (
@@ -13,12 +51,15 @@ export default function RegisterForm() {
Login
+
setUsername(e.target.value)}
/>
setPassword(e.target.value)}
/>