Skip to content

Commit bdfda61

Browse files
committed
fix(tasks): resolve issue preventing new tasks from being added
Ask your favorite LLM to do this: "Rewrite this in a brutally honest, sarcastic tone: The codebase has significant potential, but its current state is highly problematic and requires substantial improvement."
1 parent 2994e70 commit bdfda61

2 files changed

Lines changed: 13 additions & 76 deletions

File tree

src/components/Projects/WBS/AddWBS/AddWBS.jsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,18 @@ import { connect } from 'react-redux';
88
import { addNewWBS } from './../../../../actions/wbs';
99
import hasPermission from 'utils/permissions';
1010

11-
const AddWBS = props => {
11+
const AddWBS = (props) => {
1212
const darkMode = props.state.theme.darkMode;
13-
const [newName, setNewName] = useState('');
14-
const [showAddButton, setShowAddButton] = useState(false);
13+
const [taskTitle, setTaskTitle] = useState('');
1514
const canPostWBS = props.hasPermission('postWbs');
1615

17-
const changeNewName = value => {
18-
setNewName(value);
19-
setShowAddButton(value.length >= 3);
20-
};
16+
const handleSubmit = () => {
17+
if (!taskTitle.trim()) return;
2118

22-
const handleAddWBS = () => {
23-
if (newName.length >= 3) {
24-
props.addNewWBS(props.projectId, newName);
25-
setNewName('');
26-
setShowAddButton(false);
19+
const confirmed = window.confirm(`Add task "${taskTitle}" to the database?`);
20+
if (confirmed) {
21+
props.addNewWBS(taskTitle, props.projectId);
22+
setTaskTitle('');
2723
}
2824
};
2925

@@ -41,14 +37,15 @@ const AddWBS = props => {
4137
className={`form-control ${darkMode ? 'bg-darkmode-liblack border-0 text-light' : ''}`}
4238
aria-label="WBS WBS"
4339
placeholder="WBS Name"
44-
onChange={e => changeNewName(e.target.value)}
40+
value={taskTitle}
41+
onChange={(e) => setTaskTitle(e.target.value)}
4542
/>
4643
<div className="input-group-append">
47-
{showAddButton ? (
44+
{taskTitle.length >= 3 ? (
4845
<button
4946
className="btn btn-outline-primary"
5047
type="button"
51-
onClick={handleAddWBS}
48+
onClick={handleSubmit}
5249
data-testid="add-wbs-button"
5350
>
5451
<i className="fa fa-plus" aria-hidden="true"></i>

src/components/Projects/WBS/WBSDetail/WBSTasks.jsx

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
2-
/*********************************************************************************
3-
* Component: TASK
4-
* Author: Henry Ng - 21/03/20 ≢
5-
********************************************************************************/
61
import React, { useState, useEffect, useRef } from 'react';
72
import { connect, useSelector } from 'react-redux';
83
import { Link } from 'react-router-dom';
@@ -24,10 +19,6 @@ import { boxStyle, boxStyleDark } from 'styles';
2419
import { getProjectDetail } from 'actions/project';
2520

2621
function WBSTasks(props) {
27-
/*
28-
* -------------------------------- variable declarations --------------------------------
29-
*/
30-
// props from store
3122
const { tasks, fetched, darkMode } = props;
3223

3324
const { wbsId } = props.match.params;
@@ -69,7 +60,6 @@ function WBSTasks(props) {
6960
case 'inactive': return tasks.filter(task => ['Not Started', 'Paused'].includes(task.status))
7061
case 'complete': return tasks.filter(task => task.status === 'Complete')
7162
case 'paused': return tasks.filter(task => task.status === 'Paused');
72-
7363
}
7464
}
7565

@@ -87,56 +77,6 @@ function WBSTasks(props) {
8777
setIsDeleted(true);
8878
};
8979

90-
/**
91-
* Drag and drop is not being used anywhere, and it seems to be replaced by the copy and paste functionality,
92-
* so here comments it out for future reference if such functionality is desired again.
93-
*/
94-
95-
// let drag = '';
96-
// let dragParent = '';
97-
// const dragTask = (taskIdFrom, parentId) => {
98-
// drag = taskIdFrom;
99-
// dragParent = parentId;
100-
// };
101-
102-
// const dropTask = (taskIdTo, parentId) => {
103-
// const tasksClass = document.getElementsByClassName('taskDrop');
104-
// for (let i = 0; i < tasks.length; i++) {
105-
// tasksClass[i].style.display = 'none';
106-
// }
107-
108-
// const list = [];
109-
// const target = tasks.find(task => task._id === taskIdTo);
110-
// const siblings = tasks.filter(task => task.parentId === dragParent);
111-
112-
// let modifiedList = false;
113-
// if (dragParent === target._id) {
114-
// list.push({
115-
// id: drag,
116-
// num: siblings[0].num,
117-
// });
118-
// modifiedList = true;
119-
// }
120-
// for (let i = 0; i < siblings.length - 1; i++) {
121-
// if (siblings[i]._id === drag) {
122-
// modifiedList = false;
123-
// }
124-
// if (modifiedList) {
125-
// list.push({
126-
// id: siblings[i]._id,
127-
// num: siblings[i + 1].num,
128-
// });
129-
// }
130-
// if (siblings[i]._id === target._id) {
131-
// list.push({
132-
// id: drag,
133-
// num: siblings[i + 1].num,
134-
// });
135-
// modifiedList = true;
136-
// }
137-
// }
138-
// };
139-
14080
/*
14181
* -------------------------------- useEffects --------------------------------
14282
*/
@@ -369,7 +309,7 @@ function WBSTasks(props) {
369309
{/* <tr className="taskDrop"> // Drag and drop functionality is deserted for now
370310
<td colSpan={14} />
371311
</tr> */}
372-
{fetched && levelOneTasks.map((task, i) => (
312+
{levelOneTasks.map((task, i) => (
373313
<Task
374314
key={`${task._id}${i}`}
375315
taskId={task._id}

0 commit comments

Comments
 (0)