-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperation.js
124 lines (114 loc) · 3.67 KB
/
Operation.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
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
import supabase from "../config/supabaseClient";
import { useEffect, useState } from "react";
import { Link, useNavigate } from "react-router-dom";
const Operation = () => {
const navigate = useNavigate();
const [fetchError, setFetchError] = useState(null);
const [Operation, setOperation] = useState(null);
const [searchTerm, setSearchTerm] = useState("");
const [filteredOperation, setFilteredOperation] = useState(null);
const fetchOperations = async () => {
const { data, error } = await supabase.from("Operation").select();
if (error) {
setOperation(null);
setFetchError("Couldn't fetch the operations data");
console.log(error);
}
if (data) {
setOperation(data);
setFetchError(null);
}
};
useEffect(() => {
fetchOperations();
}, []);
useEffect(() => {
if (Operation) {
const filteredData = Operation.filter((op) =>
op.OperationName.toLowerCase().includes(searchTerm.toLowerCase())
);
setFilteredOperation(filteredData);
}
}, [searchTerm, Operation]);
const handleCreateOperation = () => {
navigate("/createOperation");
};
const handleDelete = async (operationID) => {
const confirmed = window.confirm("Are you sure you want to delete?");
if (confirmed) {
await supabase.from("Operation").delete().eq("ID", operationID);
fetchOperations();
}
};
return (
<div className="page home">
<div className="createOperation">
<h1 className="tablesubj">Operations Info</h1>
<button className="createButton" onClick={handleCreateOperation}>
Create New
</button>
<label id="searchLabel">
<input
style={{ textAlign: "center" }}
type="text"
placeholder="Search by Name"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
</label>
</div>
{fetchError && <p>{fetchError}</p>}
{filteredOperation && Operation && (
<table className="table">
<thead>
<tr>
<th>Operation ID</th>
<th>Name</th>
<th>Room</th>
<th>Date</th>
<th>Time</th>
<th>Notes</th>
<th>Prosthetic ID</th>
<th>Patient ID</th>
<th>Doctor ID</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{filteredOperation.map((operation) => (
<tr key={operation.id}>
<td>{operation.ID}</td>
<td>{operation.OperationName}</td>
<td>{operation.Room}</td>
<td style={{whiteSpace: 'nowrap'}}>{operation.Date}</td>
<td style={{textAlign:"right"}}>{operation.Time}</td>
<td style={{wordWrap: "break-word", whiteSpace: "pre-wrap"}}>{operation.Notes}</td>
<td>{operation.Prosthetic_ID}</td>
<td>{operation.Patient_ID}</td>
<td>{operation.Doctor_ID}</td>
<td className="buttons">
<Link to={"/operation" + operation.ID}>
<i className="material-icons">edit</i>
</Link>
</td>
<td className="buttons">
<i
className="material-icons"
style={{ cursor: "pointer" }}
onClick={() => handleDelete(operation.ID)}
>
delete
</i>
</td>
</tr>
))}
</tbody>
</table>
)}
</div>
);
};
export default Operation;
/*
*/