@@ -18,7 +18,7 @@ export default function RequestList() {
18
18
}
19
19
const router = useRouter ( ) ;
20
20
// const TABLE_HEAD_REQ = ["ID", "Title", "Describe", "Last Update", "Status"];
21
- const TABLE_HEAD_REQ = [ "Project Name" , "Describe" , "Status PM" , "Status Ops" ] ;
21
+ const TABLE_HEAD_REQ = [ "Project Name" , "Describe" , "Type" , " Status PM", "Status Ops" ] ;
22
22
const [ TABLE_ROWS_REQ , setTableRowsReq ] = useState ( [ ] ) ;
23
23
const [ sortAsc , setSortAsc ] = useState ( true ) ;
24
24
@@ -33,13 +33,27 @@ export default function RequestList() {
33
33
} ,
34
34
} ) ;
35
35
36
+ const resRequesttype = await fetch ( "/api/requesttype" , {
37
+ method : "GET" ,
38
+ headers : {
39
+ "Content-Type" : "application/json" ,
40
+ } ,
41
+ } ) ;
42
+
36
43
if ( resProjects . ok ) {
37
- const data = await resProjects . json ( ) ;
38
- console . log ( "data" , data )
39
- const rows = data . map ( ( element ) => ( {
44
+ const ProjectData = await resProjects . json ( ) ;
45
+ const RequesttypeData = await resRequesttype . json ( ) ;
46
+
47
+ const projectStatusMap = { } ;
48
+ RequesttypeData . forEach ( requesttype => {
49
+ projectStatusMap [ requesttype . projectid ] = requesttype . status ;
50
+ } ) ;
51
+
52
+ const rows = ProjectData . map ( ( element ) => ( {
40
53
projectid : element . _id ,
41
54
projectname : element . projectName ,
42
55
describe : element . projectDescription ,
56
+ type : projectStatusMap [ element . _id ] ,
43
57
statuspm : element . statuspm ,
44
58
statusops : element . statusops ,
45
59
} ) ) ;
@@ -53,63 +67,6 @@ export default function RequestList() {
53
67
fetchRequests ( ) ;
54
68
} , [ ] ) ;
55
69
56
- // useEffect(() => {
57
- // // Fetch request data from the API
58
- // const fetchRequests = async () => {
59
- // try {
60
- // // First, fetch all requests
61
- // const resRequests = await fetch("/api/request", {
62
- // method: "GET",
63
- // headers: {
64
- // "Content-Type": "application/json",
65
- // },
66
- // });
67
-
68
- // if (!resRequests.ok) {
69
- // throw new Error("Failed to fetch requests");
70
- // }
71
-
72
- // const requestsData = await resRequests.json();
73
-
74
- // // Then, fetch all projects
75
- // const resProjects = await fetch("/api/project", {
76
- // method: "GET",
77
- // headers: {
78
- // "Content-Type": "application/json",
79
- // },
80
- // });
81
-
82
- // if (!resProjects.ok) {
83
- // throw new Error("Failed to fetch projects");
84
- // }
85
-
86
- // const projectsData = await resProjects.json();
87
-
88
- // // Create a map of project IDs to project names for quick lookup
89
- // const projectMap = {};
90
- // projectsData.forEach(project => {
91
- // projectMap[project._id] = project.projectName;
92
- // });
93
-
94
- // // Now map request data and include project names
95
- // const rows = requestsData.map((element) => ({
96
- // id: element.requestid,
97
- // projectid: element.projectid,
98
- // projectname: projectMap[element.projectid] || "Unknown Project", // Add project name
99
- // requestname: element.name,
100
- // type: element.type,
101
- // statuspm: element.statuspm,
102
- // statusops: element.statusops,
103
- // }));
104
-
105
- // console.log("Requests with project names:", rows);
106
- // setTableRowsReq(rows);
107
- // } catch (error) {
108
- // console.error("Failed to fetch data:", error.message);
109
- // }
110
- // };
111
- // fetchRequests();
112
- // }, []);
113
70
114
71
115
72
const sortOrder = [ "Request" , "Under Review" , "Rejected" , "Approved" ] ;
@@ -132,7 +89,7 @@ export default function RequestList() {
132
89
133
90
return (
134
91
< div >
135
- < p className = "text-5xl font-bold mx-16 my-5" > Create Requests</ p >
92
+ < p className = "text-5xl font-bold mx-16 my-5" > Requests</ p >
136
93
137
94
{ /* Details box */ }
138
95
< div className = "overflow-hidden bg-white mx-16 my-8 text-black text-x1 font-normal rounded-lg" >
@@ -168,7 +125,7 @@ export default function RequestList() {
168
125
< tbody >
169
126
170
127
{ userRole === 'pm' &&
171
- sortedRows . map ( ( { projectid, projectname, describe, statuspm, statusops } , index ) => {
128
+ sortedRows . map ( ( { projectid, projectname, describe, type , statuspm, statusops } , index ) => {
172
129
const isOdd = index % 2 === 1 ;
173
130
const rowBgColor = isOdd ? "bg-gray-50" : "bg-white" ;
174
131
@@ -198,75 +155,17 @@ export default function RequestList() {
198
155
</ td >
199
156
< td className = "p-4 border-b border-blue-gray-50" >
200
157
< Link href = { { pathname : "/projectpm" , query : { projectid } } } >
201
- < Typography
202
- variant = "small"
203
- className = { `font-normal px-2 py-1 rounded-md
204
- ${ statuspm === "Approved"
205
- ? "text-green-600 bg-green-100 px-2"
206
- : statuspm === "Under Review"
207
- ? "text-amber-600 bg-amber-100"
208
- : statuspm === "Request"
209
- ? "text-gray-600 bg-gray-100"
210
- : "text-red-600 bg-red-100"
211
- } `}
212
- >
213
- { statuspm }
214
- </ Typography >
215
- </ Link >
216
- </ td >
217
- < td className = "p-4 border-b border-blue-gray-50" >
218
- < Link href = { { pathname : "/projectpm" , query : { projectid } } } >
219
- < Typography
220
- variant = "small"
221
- className = { `font-normal px-2 py-1 rounded-md
222
- ${ statusops === "Approved"
223
- ? "text-green-600 bg-green-100 px-2"
224
- : statusops === "Under Review"
225
- ? "text-amber-600 bg-amber-100"
226
- : statusops === "Request"
227
- ? "text-gray-600 bg-gray-100"
228
- : "text-red-600 bg-red-100"
229
- } `}
230
- >
231
- { statusops }
232
- </ Typography >
233
- </ Link >
234
- </ td >
235
- </ tr >
236
- ) ;
237
- } ) }
238
-
239
- { userRole === 'ops' &&
240
- sortedRows . map ( ( { projectid, projectname, describe, statuspm, statusops } , index ) => {
241
- const isOdd = index % 2 === 1 ;
242
- const rowBgColor = isOdd ? "bg-gray-50" : "bg-white" ;
243
-
244
- return (
245
- < tr key = { projectid } className = { `${ rowBgColor } cursor-pointer` } >
246
- < td className = "p-4 border-b border-blue-gray-50" >
247
- < Link href = { { pathname : "/projectops" , query : { projectid } } } >
248
158
< Typography
249
159
variant = "small"
250
160
color = "blue-gray"
251
161
className = "font-normal"
252
162
>
253
- { projectname }
163
+ { type }
254
164
</ Typography >
255
165
</ Link >
256
166
</ td >
257
167
< td className = "p-4 border-b border-blue-gray-50" >
258
- < Link href = { { pathname : "/projectops" , query : { projectid } } } >
259
- < Typography
260
- variant = "small"
261
- color = "blue-gray"
262
- className = "font-normal"
263
- >
264
- { describe }
265
- </ Typography >
266
- </ Link >
267
- </ td >
268
- < td className = "p-4 border-b border-blue-gray-50" >
269
- < Link href = { { pathname : "/projectops" , query : { projectid } } } >
168
+ < Link href = { { pathname : "/projectpm" , query : { projectid } } } >
270
169
< Typography
271
170
variant = "small"
272
171
className = { `font-normal px-2 py-1 rounded-md
@@ -284,7 +183,7 @@ export default function RequestList() {
284
183
</ Link >
285
184
</ td >
286
185
< td className = "p-4 border-b border-blue-gray-50" >
287
- < Link href = { { pathname : "/projectops " , query : { projectid } } } >
186
+ < Link href = { { pathname : "/projectpm " , query : { projectid } } } >
288
187
< Typography
289
188
variant = "small"
290
189
className = { `font-normal px-2 py-1 rounded-md
@@ -305,54 +204,15 @@ export default function RequestList() {
305
204
) ;
306
205
} ) }
307
206
308
- </ tbody >
309
- </ table >
310
- </ div >
311
-
312
- < p className = "text-5xl font-bold mx-16 my-5" > Delete Requests</ p >
313
-
314
- { /* Details box */ }
315
- < div className = "overflow-hidden bg-white mx-16 my-8 text-black text-x1 font-normal rounded-lg" >
316
- < table className = "table-fixed w-full" >
317
- < thead >
318
- < tr >
319
- { TABLE_HEAD_REQ . map ( ( head ) => (
320
- < th
321
- key = { head }
322
- className = "border-b border-blue-gray-100 bg-gray-100 p-4 text-black font-semibold"
323
- >
324
- < Typography
325
- variant = "small"
326
- className = "font-medium text-sm leading-none opacity-70 flex flex-row items-center"
327
- onClick = { [ "Status PM" , "Status Ops" ] . includes ( head ) ? toggleSortOrder : undefined }
328
- >
329
- { [ "Status PM" , "Status Ops" ] . includes ( head ) && (
330
- < span className = "mr-2" >
331
- < Image
332
- src = { sortAsc ? filter : unfilter }
333
- alt = "filter"
334
- height = "20"
335
- width = "20"
336
- />
337
- </ span >
338
- ) }
339
- { head }
340
- </ Typography >
341
- </ th >
342
- ) ) }
343
- </ tr >
344
- </ thead >
345
- < tbody >
346
-
347
- { userRole === 'pm' &&
348
- sortedRows . map ( ( { projectid, projectname, describe, statuspm, statusops } , index ) => {
207
+ { userRole === 'ops' &&
208
+ sortedRows . map ( ( { projectid, projectname, describe, type, statuspm, statusops } , index ) => {
349
209
const isOdd = index % 2 === 1 ;
350
210
const rowBgColor = isOdd ? "bg-gray-50" : "bg-white" ;
351
211
352
212
return (
353
213
< tr key = { projectid } className = { `${ rowBgColor } cursor-pointer` } >
354
214
< td className = "p-4 border-b border-blue-gray-50" >
355
- < Link href = { { pathname : "/projectpm " , query : { projectid } } } >
215
+ < Link href = { { pathname : "/projectops " , query : { projectid } } } >
356
216
< Typography
357
217
variant = "small"
358
218
color = "blue-gray"
@@ -362,72 +222,14 @@ export default function RequestList() {
362
222
</ Typography >
363
223
</ Link >
364
224
</ td >
365
- < td className = "p-4 border-b border-blue-gray-50" >
366
- < Link href = { { pathname : "/projectpm" , query : { projectid } } } >
367
- < Typography
368
- variant = "small"
369
- color = "blue-gray"
370
- className = "font-normal"
371
- >
372
- { describe }
373
- </ Typography >
374
- </ Link >
375
- </ td >
376
- < td className = "p-4 border-b border-blue-gray-50" >
377
- < Link href = { { pathname : "/projectpm" , query : { projectid } } } >
378
- < Typography
379
- variant = "small"
380
- className = { `font-normal px-2 py-1 rounded-md
381
- ${ statuspm === "Approved"
382
- ? "text-green-600 bg-green-100 px-2"
383
- : statuspm === "Under Review"
384
- ? "text-amber-600 bg-amber-100"
385
- : statuspm === "Request"
386
- ? "text-gray-600 bg-gray-100"
387
- : "text-red-600 bg-red-100"
388
- } `}
389
- >
390
- { statuspm }
391
- </ Typography >
392
- </ Link >
393
- </ td >
394
- < td className = "p-4 border-b border-blue-gray-50" >
395
- < Link href = { { pathname : "/projectpm" , query : { projectid } } } >
396
- < Typography
397
- variant = "small"
398
- className = { `font-normal px-2 py-1 rounded-md
399
- ${ statusops === "Approved"
400
- ? "text-green-600 bg-green-100 px-2"
401
- : statusops === "Under Review"
402
- ? "text-amber-600 bg-amber-100"
403
- : statusops === "Request"
404
- ? "text-gray-600 bg-gray-100"
405
- : "text-red-600 bg-red-100"
406
- } `}
407
- >
408
- { statusops }
409
- </ Typography >
410
- </ Link >
411
- </ td >
412
- </ tr >
413
- ) ;
414
- } ) }
415
-
416
- { userRole === 'ops' &&
417
- sortedRows . map ( ( { projectid, projectname, describe, statuspm, statusops } , index ) => {
418
- const isOdd = index % 2 === 1 ;
419
- const rowBgColor = isOdd ? "bg-gray-50" : "bg-white" ;
420
-
421
- return (
422
- < tr key = { projectid } className = { `${ rowBgColor } cursor-pointer` } >
423
225
< td className = "p-4 border-b border-blue-gray-50" >
424
226
< Link href = { { pathname : "/projectops" , query : { projectid } } } >
425
227
< Typography
426
228
variant = "small"
427
229
color = "blue-gray"
428
230
className = "font-normal"
429
231
>
430
- { projectname }
232
+ { describe }
431
233
</ Typography >
432
234
</ Link >
433
235
</ td >
@@ -438,7 +240,7 @@ export default function RequestList() {
438
240
color = "blue-gray"
439
241
className = "font-normal"
440
242
>
441
- { describe }
243
+ { type }
442
244
</ Typography >
443
245
</ Link >
444
246
</ td >
0 commit comments