-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddTask.html
274 lines (252 loc) · 10.7 KB
/
addTask.html
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create Task Form</title>
<link rel="stylesheet" href="css/addTask.css">
<link rel="stylesheet" href="css/side.css">
<link rel="stylesheet" href="css/header.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
</head>
<body>
<div class="hamburger-menu">
<i class="fas fa-bars"></i>
</div>
<!-- Sidebar for large screens -->
<div class="sidebar">
<div class="logo">
<ul class="menu">
<li>
<a href="dashboard.html">
<i class="fas fa-tachometer-alt"></i>
<span>Dashboard</span>
</a>
</li>
<li>
<a href="profile.html">
<i class="fas fa-user"></i>
<span>Profile</span>
</a>
</li>
<li class="active">
<a href="addTask.html">
<i class="fas fa-plus"></i>
<span>Add Task</span>
</a>
</li>
<li>
<a href="all-tasks.html">
<i class="fas fa-tasks"></i>
<span>All Tasks</span>
</a>
</li>
<li>
<a href="completed-tasks.html">
<i class="fas fa-check"></i>
<span>Completed Tasks</span>
</a>
</li>
<li>
<a href="pending.html">
<i class="fas fa-clock"></i>
<span>Pending Tasks</span>
</a>
</li>
<li>
<a href="in-progress.html">
<i class="fas fa-spinner"></i>
<span>In-progress</span>
</a>
</li>
<li class="logout">
<a href="javascript:void(0);" id="logout-button">
<i class="fas fa-sign-out-alt"></i>
<span>Logout</span>
</a>
</li>
</ul>
</div>
</div>
<!-- Navbar for small screens -->
<div class="navbar">
<div class="navbar-header">
<span>Menu</span>
<i class="fas fa-times close-icon"></i>
</div>
<ul class="nav-menu">
<li><a href="dashboard.html">Dashboard</a></li>
<li><a href="profile.html">Profile</a></li>
<li><a href="addTask.html">Add Tasks</a></li>
<li><a href="all-tasks.html">All Tasks</a></li>
<li><a href="completed-tasks.html">Completed Tasks</a></li>
<li><a href="pending.html">Pending Tasks</a></li>
<li><a href="in-progress.html">In-Progress Tasks</a></li>
<li><a href="#">Logout</a></li>
</ul>
</div>
<!-- HEADER SECTION -->
<div class="main--content">
<div class="header--wrapper">
<div class="header--title">
<h2>TaskFlow</h2>
<span>Dashboard</span>
</div>
<div class="user--info">
<!-- <div class="search--box">
<i class="fa-solid fa-search"></i>
<input type="text" placeholder="Search"/>
</div> -->
<!-- <div class="welcome-message">
Welcome!
</div> -->
</div>
</div>
<!-- FORM CONTAINER -->
<div class="form-main-container">
<div class="form-container">
<form id="createTaskForm">
<h2>Create a New Task</h2>
<div class="form-group">
<label for="title">Title</label>
<input type="text" id="title" name="title" required>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea id="description" name="description" required></textarea>
</div>
<div class="form-group">
<label for="deadline">Deadline</label>
<input type="date" id="deadline" name="deadline" required>
</div>
<div class="form-group">
<label for="priority">Priority Level</label>
<select id="priority" name="priority" required>
<option value="LOW">Low</option>
<option value="MEDIUM">Medium</option>
<option value="HIGH">High</option>
</select>
</div>
<div class="form-group">
<label for="status">Status</label>
<select id="status" name="status" required disabled>
<option value="PENDING" selected>Pending</option>
<option value="IN_PROGRESS">In Progress</option>
<option value="COMPLETED">Completed</option>
</select>
</div>
<button type="submit" class="btn" id="createBtn">
<span id="createBtnText">Create Task</span>
<span id="createSpinner" class="spinner" style="display: none;">
<i class="fa fa-spinner fa-spin"></i>
</span>
</button>
</form>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Check if token exists in localStorage
if (!localStorage.getItem('Token')) {
// Redirect to login page if token is missing
window.location.href = '/auth/login.html';
return;
}
fetchUserProfile();
document.getElementById('logout-button').addEventListener('click', logout);
});
async function fetchUserProfile() {
try {
const response = await fetch('http://localhost:8080/api/user/profile', {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.getItem('Token')
}
});
if (!response.ok) {
throw new Error('Failed to fetch user profile');
}
const userProfile = await response.json();
console.log("user profile", userProfile);
updateWelcomeMessage(userProfile.userProfileResponseInfo.firstName);
} catch (error) {
console.error('Error fetching user profile:', error);
// Handle error if needed
}
}
function updateWelcomeMessage(firstName) {
const welcomeMessage = document.querySelector('.welcome-message');
if (welcomeMessage) {
welcomeMessage.textContent = `Welcome ${firstName}!`;
}
}
async function logout() {
try {
const response = await fetch('http://localhost:8080/api/auth/logout', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.getItem('Token')
}
});
if (!response.ok) {
throw new Error('Failed to logout');
}
// Clear local storage and redirect to login page
localStorage.removeItem('Token');
alert('Logged out successfully!');
window.location.href = '/auth/login.html';
} catch (error) {
console.error('Error logging out:', error);
alert('Error logging out. Please try again.');
}
}
document.getElementById('createTaskForm').addEventListener('submit', async function(event) {
event.preventDefault(); // Prevent the default form submission
const title = document.getElementById('title').value;
const description = document.getElementById('description').value;
const deadlineInput = document.getElementById('deadline').value;
const priority = document.getElementById('priority').value;
const status = document.getElementById('status').value;
// Format deadline to "yyyy-MM-ddT23:59:59"
const deadline = `${deadlineInput}T23:59:59`;
const taskData = {
title: title,
description: description,
deadline: deadline,
priorityLevel: priority,
status: status
};
try {
// Show spinner and hide text
document.getElementById('createBtnText').style.display = 'none';
document.getElementById('createSpinner').style.display = 'inline-block';
const response = await fetch('http://localhost:8080/api/tasks/new-task', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.getItem('Token') // assuming you are storing JWT in localStorage
},
body: JSON.stringify(taskData)
});
if (response.ok) {
console.log(response);
const result = await response.json();
alert('Task created successfully!');
window.location.href = 'dashboard.html'; // Redirect to the dashboard after successful task creation
} else {
alert('Failed to create task');
}
} catch (error) {
console.error('Error creating task:', error);
alert('An error occurred while creating the task');
} finally {
// Hide spinner and show text
document.getElementById('createBtnText').style.display = 'inline';
document.getElementById('createSpinner').style.display = 'none';
}
});
</script>
</body>
</html>