-
Login
@@ -30,9 +31,11 @@ export default function Nav() {
Register
-
+
}
+
-
diff --git a/components/RegisterForm.js b/components/RegisterForm.js
index a6ef2e3..93daa63 100644
--- a/components/RegisterForm.js
+++ b/components/RegisterForm.js
@@ -2,8 +2,11 @@ import React, { useState } from 'react'
import axios from '../utils/axios'
import { useAuth } from '../context/auth'
import { useRouter } from 'next/router'
+import {toast} from 'react-toastify';
+import 'react-toastify/dist/ReactToastify.css';
export default function Register() {
+
const { setToken } = useAuth()
const router = useRouter()
@@ -27,11 +30,11 @@ export default function Register() {
username === '' ||
password === ''
) {
- console.log('Please fill all the fields correctly.')
+ toast.warning('Please fill all the fields correctly.',{position: toast.POSITION.TOP_CENTER})
return false
}
if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
- console.log('Please enter a valid email address.')
+ toast.error('Please enter a valid email address.',{position: toast.POSITION.TOP_CENTER})
return false
}
return true
@@ -43,7 +46,7 @@ export default function Register() {
if (
registerFieldsAreValid(firstName, lastName, email, username, password)
) {
- console.log('Please wait...')
+ toast.info('Please wait...',{position: toast.POSITION.TOP_CENTER})
const dataForApiRequest = {
name: firstName + ' ' + lastName,
@@ -58,12 +61,10 @@ export default function Register() {
)
.then(function ({ data, status }) {
setToken(data.token)
- router.push('/')
+ router.push("REGISTER","/")
})
.catch(function (err) {
- console.log(
- 'An account using same email or username is already created'
- )
+ toast.error('An account using same email or username is already created',{position: toast.POSITION.TOP_CENTER})
})
}
}
@@ -71,8 +72,8 @@ export default function Register() {
return (
-
-
Register
+
+
Register
+ onClick={register}>
Register
diff --git a/components/TodoListItem.js b/components/TodoListItem.js
index 7965f3b..cca8208 100644
--- a/components/TodoListItem.js
+++ b/components/TodoListItem.js
@@ -1,56 +1,80 @@
/* eslint-disable @next/next/no-img-element */
-export default function TodoListItem() {
- const editTask = (id) => {
- /**
- * @todo Complete this function.
- * @todo 1. Update the dom accordingly
- */
+import axios from '../utils/axios'
+import React, { useEffect, useState } from 'react'
+import { useAuth } from '../context/auth'
+import { API_URL } from '../utils/constants'
+import {toast} from 'react-toastify';
+import 'react-toastify/dist/ReactToastify.css';
+
+export default function TodoListItem(props) {
+
+ const { token } = useAuth()
+ const [edit, setEdit] = useState(false)
+ const [editText, setEditText] = useState('props.title')
+
+ const editTask = () => {
+ setEditText('')
+ setEdit(true)
}
const deleteTask = (id) => {
- /**
- * @todo Complete this function.
- * @todo 1. Send the request to delete the task to the backend server.
- * @todo 2. Remove the task from the dom.
- */
+
+ axios({
+ headers: {Authorization: 'Token ' + token},
+ url: API_URL + 'todo/' + id + '/',
+ method: 'delete'
+ }).then(function({data,status}){
+ toast.success('Task deleted successfully!',{position: toast.POSITION.TOP_CENTER})
+ }).catch((error)=>{
+ toast.error('Please try again!',{position: toast.POSITION.TOP_CENTER})
+ })
}
const updateTask = (id) => {
- /**
- * @todo Complete this function.
- * @todo 1. Send the request to update the task to the backend server.
- * @todo 2. Update the task in the dom.
- */
+
+ axios({
+ headers: {Authorization: 'Token ' + token},
+ url: API_URL + 'todo/' + id + '/',
+ method: 'patch',
+ data: {id: id, title: editText},
+ }).then(function({data,status}){
+ toast.success('Task updated successfully!',{position: toast.POSITION.TOP_CENTER})
+ }).catch((error)=>{
+ toast.error('Please try again!',{position: toast.POSITION.TOP_CENTER})
+ })
+ setEdit(false)
}
return (
<>
-
+
{setEditText(e.target.value)}}
/>
-