-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKanbanBoard.js
67 lines (57 loc) · 1.85 KB
/
KanbanBoard.js
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
// src/components/KanbanBoard.js
import React, { useState, useEffect } from "react";
import { fetchTickets } from "../apiResponse";
import KanbanColumn from "./KanbanColumn";
const KanbanBoard = () => {
const [tickets, setTickets] = useState([]);
const [groupBy, setGroupBy] = useState("status");
const [groupedTickets, setGroupedTickets] = useState({});
useEffect(() => {
const loadTickets = async () => {
const data = await fetchTickets();
// Extract tickets array from the data
const ticketsArray = data.tickets || [];
setTickets(ticketsArray);
groupTickets(ticketsArray, groupBy);
};
loadTickets();
}, []);
useEffect(() => {
groupTickets(tickets, groupBy);
}, [groupBy, tickets]);
const groupTickets = (tickets, criterion) => {
if (!Array.isArray(tickets)) {
console.error("Tickets is not an array:", tickets);
return;
}
const grouped = tickets.reduce((acc, ticket) => {
const key = ticket[criterion] || "Unassigned";
if (!acc[key]) {
acc[key] = [];
}
acc[key].push(ticket);
return acc;
}, {});
setGroupedTickets(grouped);
};
return (
<div>
<h1>Kanban Board</h1>
<div style={{ marginBottom: "20px" }}>
<label>Group By: </label>
<select onChange={(e) => setGroupBy(e.target.value)} value={groupBy}>
<option value="status">Status</option>
<option value="userId">User</option>
<option value="priority">Priority</option>
</select>
<button onClick={() => groupTickets(tickets, groupBy)}>Display</button>
</div>
<div style={{ display: "flex", gap: "20px" }}>
{Object.keys(groupedTickets).map((key) => (
<KanbanColumn key={key} title={key} tickets={groupedTickets[key]} />
))}
</div>
</div>
);
};
export default KanbanBoard;