diff --git a/.eslintrc b/.eslintrc index a2ceebe..f709325 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,3 @@ { - "extends": ["next/babel", "next/core-web-vitals"] -} + "extends": ["next", "next/core-web-vitals"] +} \ No newline at end of file diff --git a/components/AddTask.js b/components/AddTask.js index 9652adb..0d25a5f 100644 --- a/components/AddTask.js +++ b/components/AddTask.js @@ -1,17 +1,46 @@ -export default function AddTask() { +import axios from "axios" +import { useState } from "react" +import { useAuth } from "../context/auth" +import { API_URL } from "../utils/constants" + +export default function addTask() { + const [Task,settheTask]=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.length===0) + { + alert('Please Write some Task!') + } + else + { + axios({ + headers : {Authorization : "Token "+token}, + url : API_URL + 'todo/', + method : 'get', + + }).then((res)=>{ + const {data}=res + const apiData = {id : data.length, title : Task} + console.log(Task) + alert('Task added!') + axios({ + headers : {Authorization : "Token "+token}, + url : API_URL + 'todo/create/', + method: "post", + data : apiData + }) + }) + } + } return (
{settheTask(e.target.value)}} />
) -} +} \ No newline at end of file diff --git a/components/LoginForm.js b/components/LoginForm.js index fa28f9e..11b0409 100644 --- a/components/LoginForm.js +++ b/components/LoginForm.js @@ -1,11 +1,32 @@ +import axios from '../utils/axios' +import React, { useState } from 'react' +import { useAuth } from '../context/auth' +import { useRouter } from 'next/router' +import { API_URL } from '../utils/constants'; + export default function RegisterForm() { + // no_auth_required(); + const [ipusername,settheName]=useState("") + const [pwd,setpwd]=useState("") + const {setToken,token} = useAuth() + const router = useRouter() + 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(ipusername===''||pwd==='') + { + alert('The fields can`t be left empty!'); + } + else{ + axios({ + url:API_URL+"auth/login/", + method : "post", + data : {username:ipusername,password:pwd} + }).then((res)=>{ + const {data,status} = res; + setToken(data.token), + router.push('/') + }) + } } return ( @@ -19,6 +40,8 @@ export default function RegisterForm() { name='inputUsername' id='inputUsername' placeholder='Username' + value={ipusername} + onChange={(e)=>{settheName(e.target.value)}} /> {setpwd(e.target.value)}} /> -
- Sample Task 1 +
+ {props.title}
- +