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

[Sprint 2] Added "edit" feature as well as "priority" and "due date" features #14

Merged
merged 2 commits into from
Apr 20, 2023
Merged
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
62 changes: 62 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"bootstrap": "^5.2.3",
"react": "^18.2.0",
"react-bootstrap": "^2.7.2",
"react-datepicker": "^4.11.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.1",
"react-scripts": "5.0.1",
Expand Down
60 changes: 55 additions & 5 deletions frontend/src/components/AddTodo.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import { unwatchFile } from 'fs'
import React, { useState } from 'react'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";

type Props = {
type Props = TodoProps & {
saveTodo: (e: React.FormEvent, formData: ITodo | any) => void
}

const AddTodo: React.FC<Props> = ({ saveTodo }) => {
const AddTodo: React.FC<Props> = ({todo, saveTodo }) => {
const [formData, setFormData] = useState<ITodo | {}>()
const [name, setName] = useState("")
const [description, setDescription] = useState("")
const [name, setName] = useState(todo.name)
const [description, setDescription] = useState(todo.description)
const [label, setLabel] = useState(todo.label)
const [priority, setPriority] = useState(todo.priority)
const [dueDate, setDueDate] = useState(todo.dueDate)
const [show, setShow] = useState(false)

let priorities = [
{ label: "Low", value: "Low" },
{ label: "Medium", value: "Medium" },
{ label: "High", value: "High" }
]

// const handleForm = (e: React.FormEvent<HTMLInputElement>): void => {
// setFormData({
// ...formData,
Expand All @@ -20,10 +31,15 @@ const AddTodo: React.FC<Props> = ({ saveTodo }) => {

const handleSubmit = (e: React.FormEvent<HTMLFormElement>): void => {

e.preventDefault();

const todo: ITodo = {
_id: "",
name: name,
description: description,
label: label,
priority: priority,
dueDate: dueDate,
status: false,
}

Expand All @@ -32,19 +48,53 @@ const AddTodo: React.FC<Props> = ({ saveTodo }) => {
saveTodo(e, todo);
setName("");
setDescription("");
setLabel("");
setPriority("");
setDueDate(null);
}

return ( show && (
<div>
<form className='Form' onSubmit={handleSubmit}>

<div className="form-group mt-3">
<input onChange={(e) => setName(e.currentTarget.value)} type='text' id='name' value={name} placeholder="Name"/>
</div>
<div className="form-group mt-3">
<input onChange={(e) => setDescription(e.currentTarget.value)} type='text' id='description' value={description} placeholder="Description"/>
</div>
<div className="form-group mt-3">
<input onChange={(e) => setLabel(e.currentTarget.value)} type='text' id='label' value={label} placeholder="Label"/>
</div>

<div className="form-group mt-3">
<input
onChange={(e) => setPriority(e.currentTarget.value)}
type='text'
id='priority'
value={priority}
placeholder="Priority"/>

<select onChange={(e) => setPriority(e.currentTarget.value)} >
{/* <option value={priority}> Priority </option> */}
<option value={priority}> -- Select a priority -- </option>
{priorities.map((fruit) => <option value={fruit.value}>{fruit.label}</option>)}
</select>

</div>
<div className="form-group mt-3">
<DatePicker
selected={dueDate}
onChange={date => setDueDate(date)}
showTimeSelect
dateFormat="MMMM d, yyyy h:mmaa"
placeholderText="Due Date"
isClearable
filterDate={d => {
return new Date() <= d;
}}
/>
</div>
<div className="form-group mt-3" >
<button disabled={name == "" || description == "" ? true: false} >Add Todo</button>
</div>
<div className="form-group mt-3">
Expand Down
103 changes: 103 additions & 0 deletions frontend/src/components/EditTodo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { unwatchFile } from 'fs'
import React, { useState } from 'react'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";

type Props = TodoProps & {
saveTodo: (e: React.FormEvent, formData: ITodo | any) => void
clearForm: React.Dispatch<React.SetStateAction<boolean>>
}

const EditTodo: React.FC<Props> = ({todo, saveTodo, clearForm}) => {
const [id, setId] = useState(todo._id)
const [name, setName] = useState(todo.name)
const [description, setDescription] = useState(todo.description)
const [label, setLabel] = useState(todo.label)
const [priority, setPriority] = useState(todo.priority)
const [dueDate, setDueDate] = useState(todo.dueDate)
const [show, setShow] = useState(false)

let priorities = [
{ label: "Low", value: "Low" },
{ label: "Medium", value: "Medium" },
{ label: "High", value: "High" }
]

// const handleForm = (e: React.FormEvent<HTMLInputElement>): void => {
// setFormData({
// ...formData,
// [e.currentTarget.id]: e.currentTarget.value,
// })
// }

const handleSubmit = (e: React.FormEvent<HTMLFormElement>): void => {

e.preventDefault();

const todo: ITodo = {
_id: id,
name: name,
description: description,
label: label,
priority: priority,
dueDate: dueDate,
status: false,
}

console.log("EDITED TODO: ", todo)

saveTodo(e, todo);

clearForm(false);
}

return (
<div>
<form className='Form' onSubmit={handleSubmit}>
<div className="form-group mt-3">
<input onChange={(e) => setName(e.currentTarget.value)} type='text' id='name' value={name} placeholder="Name"/>
</div>
<div className="form-group mt-3">
<input onChange={(e) => setDescription(e.currentTarget.value)} type='text' id='description' value={description} placeholder="Description"/>
</div>
<div className="form-group mt-3">
<input onChange={(e) => setLabel(e.currentTarget.value)} type='text' id='label' value={label} placeholder="Label"/>
</div>

<div className="form-group mt-3">
<input
onChange={(e) => setPriority(e.currentTarget.value)}
type='text'
id='priority'
value={priority}
placeholder="Priority"/>

<select onChange={(e) => setPriority(e.currentTarget.value)} >
{/* <option value={priority}> Priority </option> */}
<option value={priority}> -- Select a priority -- </option>
{priorities.map((fruit) => <option value={fruit.value}>{fruit.label}</option>)}
</select>

</div>
<div className="form-group mt-3">
<DatePicker
selected={dueDate}
onChange={date => setDueDate(date)}
showTimeSelect
dateFormat="MMMM d, yyyy h:mmaa"
placeholderText="Due Date"
isClearable
filterDate={d => {
return new Date() <= d;
}}
/>
</div>
<div className="form-group mt-3" >
<button disabled={name == "" || description == "" ? true: false} >Save Todo</button>
</div>
</form>
</div>
)
}

export default EditTodo
Loading