-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathAddTask.js
More file actions
53 lines (45 loc) · 1.31 KB
/
AddTask.js
File metadata and controls
53 lines (45 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { useState } from "react";
import axios from "../utils/axios";
import { useAuth } from "../context/auth";
export default function AddTask() {
const [task, setTask] = useState("")
const { token } = useAuth();
const addTask = async() => {
/**
* @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.
*/
console.log(token)
const options={
headers: {
'Authorization': 'Token ' + token,
'Content-Type': 'application/json',
}
}
try{
await axios.post("todo/create/",{title:task},options)
}
catch(err){
console.log(err)
}
};
return (
<div className="flex items-center max-w-sm mt-24">
<input
type="text"
name="task"
className="todo-add-task-input px-4 py-2 placeholder-blueGray-100 text-gray-500 bg-white rounded text-sm border border-blueGray-300 outline-none focus:outline-none focus:ring-1 focus:ring-my-white w-full"
placeholder="Enter Task"
value={task}
onChange={(e)=>setTask(e.target.value)}
/>
<button
type="button"
className="todo-add-task bg-transparent hover:bg-my-brown text-my-brown text-sm hover:text-white px-3 py-2 border border-my-brown hover:border-transparent rounded"
onClick={addTask}>
Add Task
</button>
</div>
);
}