-
Notifications
You must be signed in to change notification settings - Fork 47
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-TASKS!!! #6
base: main
Are you sure you want to change the base?
Changes from 1 commit
48cda96
64c27f5
2768e26
a5282af
df86784
10ccf5a
11639b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
import axios from '../utils/axios'; | ||
import { useAuth } from '../context/auth' | ||
import {toast} from 'react-toastify' | ||
import 'react-toastify/dist/ReactToastify.css' | ||
import { useEffect } from 'react' | ||
|
||
toast.configure() | ||
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. | ||
* @todo 3. Set the token in the context (See context/auth.js) | ||
*/ | ||
} | ||
const { login,API_BASE_URL,setpagetype } = useAuth() | ||
useEffect(()=>{setpagetype("LOGIN");return;},[]) | ||
const loginnow = () => { | ||
const user_name = document.getElementById("inputUsername").value.trim(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use React Hooks like useState instead of Vanilla JS There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated login form. Please. review now. |
||
const user_pass = document.getElementById("inputPassword").value; | ||
if (user_name == "" || user_pass == "") { | ||
toast.error("Please fill the empty fields.",{position: toast.POSITION.BOTTOM_RIGHT}) | ||
return; | ||
} | ||
toast.info("Checking credentials...",{position: toast.POSITION.BOTTOM_RIGHT}) | ||
axios | ||
.post(API_BASE_URL + "auth/login/",{ | ||
username: user_name, | ||
password: user_pass | ||
}) | ||
.then(({ data, status }) => { | ||
toast.success("Successfully logged in!",{position: toast.POSITION.BOTTOM_RIGHT}) | ||
localStorage.setItem("token", data.token); | ||
login(data.token); | ||
}) | ||
.catch((err) => { | ||
toast.error("Cannot Login! :( Check credentials.",{position: toast.POSITION.BOTTOM_RIGHT}) | ||
}); | ||
} | ||
|
||
return ( | ||
<div className='bg-grey-lighter min-h-screen flex flex-col'> | ||
|
@@ -32,7 +55,7 @@ export default function RegisterForm() { | |
<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} | ||
onClick={loginnow} | ||
> | ||
Login | ||
</button> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,75 @@ | ||
/* eslint-disable @next/next/no-img-element */ | ||
import axios from '../utils/axios' | ||
import { useState } from 'react' | ||
import { useAuth } from '../context/auth' | ||
import {toast} from 'react-toastify' | ||
import 'react-toastify/dist/ReactToastify.css' | ||
|
||
export default function TodoListItem() { | ||
toast.configure() | ||
export default function TodoListItem(props) { | ||
const {config,API_BASE_URL } = useAuth() | ||
const [Newdata, setNewdata] = useState(props.todo.title); | ||
const [editnow, seteditnow] = useState(false); | ||
const editTask = (id) => { | ||
/** | ||
* @todo Complete this function. | ||
* @todo 1. Update the dom accordingly | ||
*/ | ||
seteditnow(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 | ||
.delete(API_BASE_URL + "todo/" + id + "/",config) | ||
.then(function ({ data, status }) { | ||
toast.success('Task deleted!',{position: toast.POSITION.BOTTOM_RIGHT}) | ||
props.onDelete(props.todo); | ||
}) | ||
.catch(function (err) { | ||
toast.error("An error occurred!"); | ||
}); | ||
} | ||
|
||
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. | ||
*/ | ||
if (!Newdata) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning toast missing! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added warning toast in update method. Please, review again. |
||
} | ||
axios | ||
.patch(API_BASE_URL + "todo/" + id + "/",{ title: Newdata },config) | ||
.then(function ({ data, status }) { | ||
toast.success('Task updated!',{position: toast.POSITION.BOTTOM_RIGHT}) | ||
seteditnow(false); | ||
}) | ||
.catch(function (err) { | ||
toast.error("An error occurred!"); | ||
}); | ||
|
||
} | ||
|
||
return ( | ||
<> | ||
<li className='border flex border-gray-500 rounded px-2 py-2 justify-between items-center mb-2'> | ||
<input | ||
id='input-button-1' | ||
id={"input-button-"+props.todo.id} | ||
type='text' | ||
className='hideme appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:ring todo-edit-task-input' | ||
value={Newdata} | ||
onChange={(e)=>{setNewdata(e.target.value)}} | ||
style ={{display: (editnow?"":"none")}} | ||
className='appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:ring todo-edit-task-input' | ||
placeholder='Edit The Task' | ||
/> | ||
<div id='done-button-1' className='hideme'> | ||
<div style ={{display: (editnow?"":"none")}} id={'done-button-'+props.todo.id}> | ||
<button | ||
className='bg-transparent hover:bg-gray-500 text-gray-700 text-sm hover:text-white py-2 px-3 border border-gray-500 hover:border-transparent rounded todo-update-task' | ||
type='button' | ||
onClick={updateTask(1)} | ||
onClick={()=>{updateTask(props.todo.id)}} | ||
> | ||
Done | ||
</button> | ||
</div> | ||
<div id='task-1' className='todo-task text-gray-600'> | ||
Sample Task 1 | ||
<div id={'task-'+props.todo.id} style ={{display: (editnow?"none":"")}} className='todo-task text-gray-600'> | ||
{Newdata} | ||
</div> | ||
<span id='task-actions-1' className=''> | ||
<span id={'task-actions-'+props.todo.id} style ={{display: (editnow?"none":"")}} className=''> | ||
<button | ||
style={{ marginRight: '5px' }} | ||
type='button' | ||
onClick={editTask(1)} | ||
onClick={()=>{editTask(props.todo.id)}} | ||
className='bg-transparent hover:bg-yellow-500 hover:text-white border border-yellow-500 hover:border-transparent rounded px-2 py-2' | ||
> | ||
<img | ||
|
@@ -62,7 +82,7 @@ export default function TodoListItem() { | |
<button | ||
type='button' | ||
className='bg-transparent hover:bg-red-500 hover:text-white border border-red-500 hover:border-transparent rounded px-2 py-2' | ||
onClick={deleteTask(1)} | ||
onClick={()=>{deleteTask(props.todo.id)}} | ||
> | ||
<img | ||
src='https://res.cloudinary.com/nishantwrp/image/upload/v1587486661/CSOC/delete.svg' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have added some Error or Warning Toast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added error message in add task. Please, review again.