Skip to content

Commit

Permalink
Bug/294 can't edit task due to earliest date addition (#295)
Browse files Browse the repository at this point in the history
* Fixed bug: can't add task on  a selected date #232

* Delete package-lock.json

* Bug Issue 294 Fixed edit task

* Fix Edit Bug

* Added form validation and fixed earliestDate

* fixed taskID problem due to async
  • Loading branch information
nikotj1 authored Apr 29, 2020
1 parent 1a68063 commit cf2e232
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 7 deletions.
4 changes: 4 additions & 0 deletions doto-backend/src/models/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const taskSchema = mongoose.Schema({
type: Number,
required: false,
},
earliestDate: {
type: Date,
required: true,
},
category: {
type: Number,
},
Expand Down
1 change: 1 addition & 0 deletions doto-backend/src/routes/task-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ router.post("/post", authenticateToken, function (req, res) {
task.travelTime = req.body.travelTime;
task.reminderType = req.body.reminderType;
task.dueDate = req.body.dueDate;
task.earliestDate = req.body.earliestDate;
task.category = req.body.category;

task.save(function (err) {
Expand Down
4 changes: 4 additions & 0 deletions doto-backend/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@
"reminderType": {
"type": "integer",
"uniqueItems": false
},
"earliestDate": {
"type": "date",
"uniqueItems": false
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions doto-backend/test/task.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const validTask = new TaskModel({
isComplete: false,
travelTime: 10,
dueDate: "2020-08-14T07:50:00+12:00",
earliestDate: "2020-08-14T07:50:00+12:00",
});

process.env.TEST_SUITE = "task-test";
Expand Down Expand Up @@ -221,6 +222,7 @@ describe("Task Model Tests", function () {
isComplete: false,
travelTime: 20,
dueDate: "2020-08-14T07:50:00+12:00",
earliestDate: "2020-08-14T07:50:00+12:00",
});
await testTask.save();
const [retrievedTask] = await TaskModel.find({
Expand All @@ -247,6 +249,7 @@ describe("Task Model Tests", function () {
isComplete: false,
travelTime: 20,
dueDate: "2020-08-14T07:50:00+12:00",
earliestDate: "2020-08-14T07:50:00+12:00",
});
await testTask.save();
const retrievedTasks = await TaskModel.find({
Expand Down Expand Up @@ -274,6 +277,7 @@ describe("Task Model Tests", function () {
isComplete: false,
travelTime: 20,
dueDate: "2020-08-14T07:50:00+12:00",
earliestDate: "2020-08-14T07:50:00+12:00",
});
await testTask.save();
const retrievedTasks = await TaskModel.find({
Expand Down Expand Up @@ -301,6 +305,7 @@ describe("Task Model Tests", function () {
isComplete: true,
travelTime: 20,
dueDate: "2020-08-14T07:50:00+12:00",
earliestDate: "2020-08-14T07:50:00+12:00",
});
await testTask.save();
const retrievedTasks = await TaskModel.find({
Expand Down
19 changes: 17 additions & 2 deletions doto-frontend/src/components/ModalContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const ModalContent = props => {
const [selectedLocation, setSelectedLocation] = useState("");
const [selectedPriority, setSelectedPriority] = useState("");
const [selectedReminder, setSelectedReminder] = useState("");
const [dueDateValid, setDueDateValid] = useState(false);
const [earliestDateValid, setEarliestDateValid] = useState(true);
const [selectedCategory, setSelectedCategory] = useState("");

// ----- HANDLERS FOR INPUT FIELDS -----
Expand All @@ -69,18 +71,23 @@ const ModalContent = props => {
const handleDateChange = date => {
if (date > new Date()) {
setSelectedDueDate(date);
setDueDateValid(true);
} else {
setSelectedDueDate("invalid date");
setDueDateValid(false);
}
};

const handleEarliestChange = date => {
if (date > new Date()) {
if (date >= new Date()) {
setEarliestDate(date);
setEarliestDateValid(true);
} else {
setEarliestDate("invalid date");
setEarliestDateValid(false);
}
};

const handleLocationChange = event => {
setSelectedLocation(event.target.value);
};
Expand Down Expand Up @@ -168,6 +175,7 @@ const ModalContent = props => {
KeyboardButtonProps={{
"aria-label": "Change date/time",
}}
error={!dueDateValid}
/>
</MuiPickersUtilsProvider>
</div>
Expand All @@ -190,6 +198,7 @@ const ModalContent = props => {
KeyboardButtonProps={{
"aria-label": "Change date/time",
}}
error={!earliestDateValid}
/>
</MuiPickersUtilsProvider>
</div>
Expand Down Expand Up @@ -269,7 +278,13 @@ const ModalContent = props => {
<MenuItem value={5}>5 Minutes Before</MenuItem>
</Select>
</FormControl>
<Button id="add-button" variant="contained" color="default" onClick={handleAdd}>
<Button
id="add-button"
variant="contained"
color="default"
onClick={handleAdd}
disabled={!(dueDateValid && earliestDateValid)}
>
ADD
</Button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion doto-frontend/src/components/pages/Calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const Calendar = () => {
const taskList = [...tasks];
const index = taskList.findIndex(currentTask => currentTask.taskId === task.taskId);
taskList.splice(index, 1);
const { newTaskOrder, updatedTask } = addTaskToSchedule(task, taskList, new Date());
const { newTaskOrder, updatedTask } = addTaskToSchedule(task, taskList);
setTasks(newTaskOrder);
await DotoService.deleteTask(task.taskId);
await DotoService.setNewTask(updatedTask);
Expand Down
52 changes: 49 additions & 3 deletions doto-frontend/src/components/updateModal/UpdateModalContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const UpdateModalContent = props => {

const [selectedName, setSelectedName] = useState(props.taskToUpdate.title);
const [selectedDescription, setSelectedDescription] = useState(props.taskToUpdate.description);
const [selectedDueDate, setSelectedDueDate] = useState(new Date());
const [selectedDueDate, setSelectedDueDate] = useState(props.taskToUpdate.dueDate);
const [selectedEarliestDate, setSelectedEarliestDate] = useState(props.taskToUpdate.earliestDate);

// default duration is 1 hour
var initialDuration = new Date();
Expand All @@ -54,6 +55,8 @@ const UpdateModalContent = props => {
const [selectedLocation, setSelectedLocation] = useState(props.taskToUpdate.location);
const [selectedPriority, setSelectedPriority] = useState("");
const [selectedReminder, setSelectedReminder] = useState("");
const [dueDateValid, setDueDateValid] = useState(props.taskToUpdate.dueDate > new Date());
const [earliestDateValid, setEarliestDateValid] = useState(props.taskToUpdate.earliestDate >= new Date());
const [selectedCategory, setSelectedCategory] = useState("");

useEffect(() => {
Expand All @@ -66,6 +69,7 @@ const UpdateModalContent = props => {
setSelectedCategory(props.taskToUpdate.category || "");
setSelectedPriority(props.taskToUpdate.priority || "");
setSelectedReminder(props.taskToUpdate.reminderType || "");
setSelectedEarliestDate(props.taskToUpdate.earliestDate || "");
}, [props.taskToUpdate]);

// ----- HANDLERS FOR INPUT FIELDS -----
Expand All @@ -80,8 +84,20 @@ const UpdateModalContent = props => {
const handleDateChange = date => {
if (date > new Date()) {
setSelectedDueDate(date);
setDueDateValid(true);
} else {
setSelectedDueDate("invalid beans");
setSelectedDueDate("invalid date");
setDueDateValid(false);
}
};

const handleEarliestChange = date => {
if (date >= new Date()) {
setSelectedEarliestDate(date);
setEarliestDateValid(true);
} else {
setSelectedEarliestDate("invalid date");
setEarliestDateValid(false);
}
};

Expand Down Expand Up @@ -117,6 +133,7 @@ const UpdateModalContent = props => {
title: selectedName,
description: selectedDescription,
dueDate: selectedDueDate,
earliestDate: selectedEarliestDate,
duration: selectedDuration.getHours() * 60 + selectedDuration.getMinutes(),
travelTime: selectedTravelTime.getHours() * 60 + selectedTravelTime.getMinutes(),
location: selectedLocation,
Expand Down Expand Up @@ -181,6 +198,30 @@ const UpdateModalContent = props => {
KeyboardButtonProps={{
"aria-label": "Change date/time",
}}
error={!dueDateValid}
/>
</MuiPickersUtilsProvider>
</div>
<div>
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<KeyboardDateTimePicker
disableToolbar
autoOk={true}
minDate={new Date()}
minDateMessage="Date must be after now"
invalidDateMessage="Date must be after now"
variant="inline"
format="MM/dd/yyyy HH:mm"
ampm={false}
margin="normal"
id="date-picker-inline"
label="Earliest Start"
value={selectedEarliestDate}
onChange={handleEarliestChange}
KeyboardButtonProps={{
"aria-label": "Change date/time",
}}
error={!earliestDateValid}
/>
</MuiPickersUtilsProvider>
</div>
Expand Down Expand Up @@ -265,7 +306,12 @@ const UpdateModalContent = props => {
</form>
</div>
<div id="add-button">
<Button variant="contained" color="default" onClick={handleUpdate}>
<Button
variant="contained"
color="default"
onClick={handleUpdate}
disabled={!(dueDateValid && earliestDateValid)}
>
Update
</Button>
</div>
Expand Down
4 changes: 3 additions & 1 deletion doto-frontend/src/helpers/DotoService.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const taskMapper = data => {
...(data.category && { category: data.category }),
...(data.location && { location: data.location }),
isComplete: data.isComplete,
earliestDate: new Date(data.earliestDate),
};
};

Expand Down Expand Up @@ -73,6 +74,7 @@ const DotoService = {
...(task.category && { category: task.category }),
...(task.location && { location: task.location }),
isComplete: false,
earliestDate: task.earliestDate.toString(),
};

axios({
Expand All @@ -85,7 +87,7 @@ const DotoService = {
// TODO: catch for errors depending if it didn't post properly or maybe retry mechanism
},
deleteTask: async taskId => {
axios({
await axios({
method: "delete",
url: baseUrl + `/task/${taskId}`,
headers: { Authorization: "Bearer " + CookieManager.get("jwt") },
Expand Down

0 comments on commit cf2e232

Please sign in to comment.