-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathIntermediateTaskForm.jsx
More file actions
170 lines (154 loc) · 4.54 KB
/
IntermediateTaskForm.jsx
File metadata and controls
170 lines (154 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React, { useState, useEffect } from 'react';
import {
Button,
Form,
FormGroup,
Label,
Input,
Modal,
ModalHeader,
ModalBody,
ModalFooter,
} from 'reactstrap';
import styles from './IntermediateTaskList.module.css';
const IntermediateTaskForm = ({ task, onSubmit, onCancel }) => {
const [formData, setFormData] = useState({
title: '',
description: '',
expectedHours: '',
dueDate: '',
status: 'pending',
});
useEffect(() => {
if (task) {
setFormData({
title: task.title || '',
description: task.description || '',
expectedHours: task.expectedHours || task.expected_hours || '',
dueDate:
task.dueDate || task.due_date
? new Date(task.dueDate || task.due_date).toISOString().split('T')[0]
: '',
status: task.status || 'pending',
});
}
}, [task]);
const handleChange = e => {
const { name, value } = e.target;
setFormData(prev => ({
...prev,
[name]: value,
}));
};
const handleSubmit = e => {
e.preventDefault();
// Validation
if (!formData.title.trim()) {
alert('Title is required');
return;
}
if (formData.expectedHours && (isNaN(formData.expectedHours) || formData.expectedHours < 0)) {
alert('Expected hours must be a positive number');
return;
}
// Convert to backend format
const submitData = {
title: formData.title,
description: formData.description,
expectedHours: formData.expectedHours ? parseFloat(formData.expectedHours) : 0,
status: formData.status,
};
// Only set logged_hours to 0 when creating a new task (not editing)
if (!task) {
submitData.loggedHours = 0;
}
// Only include dueDate if it's set
if (formData.dueDate) {
submitData.dueDate = new Date(formData.dueDate).toISOString();
}
onSubmit(submitData);
};
return (
<Modal isOpen={true} toggle={onCancel} size="lg" className={styles.formModal}>
<ModalHeader toggle={onCancel}>
{task ? 'Edit Intermediate Task' : 'Add Intermediate Task'}
</ModalHeader>
<Form onSubmit={handleSubmit}>
<ModalBody>
<FormGroup>
<Label for="title">Title *</Label>
<Input
type="text"
name="title"
id="title"
value={formData.title}
onChange={handleChange}
required
placeholder="Enter task title"
/>
</FormGroup>
<FormGroup>
<Label for="description">Description</Label>
<Input
type="textarea"
name="description"
id="description"
rows="4"
value={formData.description}
onChange={handleChange}
placeholder="Enter task description"
/>
</FormGroup>
<div className={styles.formRow}>
<FormGroup className={styles.formGroupHalf}>
<Label for="expectedHours">Expected Hours</Label>
<Input
type="number"
name="expectedHours"
id="expectedHours"
min="0"
step="0.5"
value={formData.expectedHours}
onChange={handleChange}
placeholder="0"
/>
</FormGroup>
<FormGroup className={styles.formGroupHalf}>
<Label for="dueDate">Due Date</Label>
<Input
type="date"
name="dueDate"
id="dueDate"
value={formData.dueDate}
onChange={handleChange}
/>
</FormGroup>
</div>
<FormGroup>
<Label for="status">Status</Label>
<Input
type="select"
name="status"
id="status"
value={formData.status}
onChange={handleChange}
>
<option value="pending">Pending</option>
<option value="in_progress">In Progress</option>
{task && <option value="completed">Completed</option>}
</Input>
</FormGroup>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={onCancel}>
Cancel
</Button>
<Button color="primary" type="submit">
{task ? 'Update' : 'Create'} Task
</Button>
</ModalFooter>
</Form>
</Modal>
);
};
export default IntermediateTaskForm;