Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed all the tasks #9

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 60 additions & 25 deletions components/AddTask.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
export default function AddTask() {
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.
*/
}
return (
<div className='flex items-center max-w-sm mt-24'>
<input
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'
/>
<button
type='button'
className='todo-add-task bg-transparent hover:bg-green-500 text-green-700 text-sm hover:text-white px-3 py-2 border border-green-500 hover:border-transparent rounded'
onClick={addTask}
>
Add Task
</button>
</div>
)
}
import { useState } from "react";
import axios from "axios";
export default function AddTask(props) {
const API_BASE_URL = "https://todo-app-csoc.herokuapp.com/";
const [value, setValue] = useState("");
const addTask = () => {
const todoText = value.trim();

if (!todoText) {
alert("Enter something to add it")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make use of Toasts here

return;
}

axios({
headers: {
Authorization: "Token " + localStorage.getItem("token")
},
url: API_BASE_URL + "todo/create/",
method: "post",
data: { title: todoText }
})
.then(function (response) {
axios({
headers: {
Authorization: "Token " + localStorage.getItem("token")
},
url: API_BASE_URL + "todo/",
method: "get"
}).then(function ({ data, status }) {
const newTask = data[data.length - 1];
props.addNewTask(newTask);
});
})
.catch(function (err) {
console.log(error);
});
setValue("")

};
return (
<div>
<div className>
<input
id="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={value}
onChange={(e) => setValue(e.target.value)}
/>
<button
type="reset"
className="btn"
onClick={addTask}>
Add Task
</button>
</div>
</div>
);
}
108 changes: 70 additions & 38 deletions components/LoginForm.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,74 @@
export default function RegisterForm() {
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.
*/
}
import React, { useState, useEffect } from "react";
import axios from "axios";
import no_auth_required from "../middlewares/no_auth_required";
import Particles from 'react-particles-js';

return (
<div className='bg-grey-lighter min-h-screen flex flex-col'>
<div className='container max-w-sm mx-auto flex-1 flex flex-col items-center justify-center px-2'>
<div className='bg-white px-6 py-8 rounded shadow-md text-black w-full'>
<h1 className='mb-8 text-3xl text-center'>Login</h1>
<input
type='text'
className='block border border-grey-light w-full p-3 rounded mb-4'
name='inputUsername'
id='inputUsername'
placeholder='Username'
/>
export default function LoginForm() {
const [password, setPassword] = useState("");
const [username, setUsername] = useState("");

<input
type='password'
className='block border border-grey-light w-full p-3 rounded mb-4'
name='inputPassword'
id='inputPassword'
placeholder='Password'
/>
const API_BASE_URL = "https://todo-app-csoc.herokuapp.com/";

<button
type='submit'
className='w-full text-center py-3 rounded bg-transparent text-green-500 hover:text-white hover:bg-green-500 border border-green-500 hover:border-transparent focus:outline-none my-1'
onClick={login}
>
Login
</button>
useEffect(() => {
no_auth_required();
});

const login = (e) => {
e.preventDefault();

if (username == "" || password == "") {
alert("Fill all the details ")
} else {
const dataForApiRequest = {
username: username,
password: password
};

axios({
url: API_BASE_URL + "auth/login/",
method: "post",
data: dataForApiRequest
})
.then(function ({ data, status }) {
localStorage.setItem("token", data.token);
window.location.href = "/";
})
.catch(function (err) {
console.log(err)
});
}
};

return (
<div >
<div className="box">
<form>
<span className="textHeading">login</span>
<div className="input-container">
<input type="text" required=""
name="inputUsername"
id="inputUsername"
value={username}
onChange={(e) => setUsername(e.target.value)}/>
<label

>Username</label>
</div>
<div className="input-container">
<input type="password" required=""
name="inputPassword"
id="inputPassword"
value={password}
onChange={(e) => setPassword(e.target.value)}/>
<label

>Password</label>
</div>
<button type="button" className="btn"
onClick={login}>LOGIN</button>
</form>
</div>

</div>
</div>
</div>
)
}
);
}
131 changes: 70 additions & 61 deletions components/Nav.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,72 @@
/* eslint-disable jsx-a11y/alt-text */
/* eslint-disable @next/next/no-img-element */
import Link from 'next/link'
/**
*
* @todo Condtionally render login/register and Profile name in NavBar
*/
import Image from "next/image";
import Link from "next/link";
export default function Nav({ profileName = "Loading", avatarImage = "#", page = "" }) {
const logout = () => {
localStorage.removeItem("token");
window.location.href = "/login/";
};

export default function Nav({ profileName = 'Loading', avatarImage = '#' }) {
const logout = () => {
localStorage.removeItem('token')
window.location.href = '/login/'
}

return (
<nav className='bg-blue-600'>
<ul className='flex items-center justify-between p-5'>
<ul className='flex items-center justify-between space-x-4'>
<li>
<h1 className='text-white font-bold text-xl'>Todo</h1>
</li>
<li className='text-white font-semibold'>
<Link href='/'>Tasks</Link>
</li>
</ul>
<ul className='flex'>
<li className='text-white mr-2'>
<Link href='/login'>Login</Link>
</li>
<li className='text-white'>
<Link href='/register'>Register</Link>
</li>
</ul>
<div className='inline-block relative w-28'>
<div className='group inline-block relative'>
<button className='bg-gray-300 text-gray-700 font-semibold py-2 px-4 rounded inline-flex items-center'>
<img src={avatarImage} />
<span className='mr-1'>{profileName}</span>
<svg
className='fill-current h-4 w-4'
xmlns='http://www.w3.org/2000/svg'
viewBox='0 0 20 20'
>
<path d='M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z' />
</svg>
</button>
<ul className='absolute hidden text-gray-700 pt-1 group-hover:block'>
<li className=''>
<a
className='rounded-b bg-gray-200 hover:bg-gray-400 py-2 px-4 block whitespace-no-wrap'
href='#'
onClick={logout}
>
Logout
</a>
</li>
return (
<nav >
<ul className="flex items-center justify-between p-5">
<ul className="flex items-center justify-between space-x-4">
<li>
<h1 className="text-white font-bold text-xl">Todo</h1>
</li>
<li className="text-white font-semibold">
Tasks
</li>
</ul>
{page !== "index" ? (
<ul className="flex">
<li className="text-white mr-2">
<Link href="/login">Login</Link>
</li>
<li className="text-white">
<Link href="/register">Register</Link>
</li>
</ul>
) : (
<div className="inline-block relative">
<div className="group inline-block relative">
<div className="avatar">
<button className="btn Avatar">
{avatarImage ? (
<Image
className="img"
src={avatarImage}
height={33}
width={33}
alt="Profile image"
/>
) : (
""
)}
<br/>
<span className="mr-1 texHeading">{profileName.slice(0, 8)}</span>
<svg
className="fill-current h-4 w-4"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20">
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
</svg>
</button>
<ul className="absolute hidden text-gray-700 pt-1 group-hover:block">
<li className="logout">
<a
className="logout"
// className="rounded-b bg-gray-200 hover:bg-gray-400 py-2 px-4 block whitespace-no-wrap"
href="#"
onClick={logout}>
Logout
</a>
</li>
</ul>
</div>
</div>
</div>
)}
</ul>
</div>
</div>
</ul>
</nav>
)
}
</nav>
);
}
Loading