Skip to content

Commit 0ba4281

Browse files
committed
view log implemented
1 parent 4614d0f commit 0ba4281

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

frontend/src/pages/log_history/LogHistory.jsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import "./LogHistory.css";
1414
import { useAuth } from "../../contexts/AuthContext";
1515
import { fetchData } from "../../utils/helpers/fetchData";
1616
import supabase from "../../config/supabase";
17+
import { useNavigate } from "react-router-dom";
1718

1819
const convertToCSV = (data) => {
1920
if (!data || data.length === 0) return '';
@@ -72,6 +73,7 @@ export default function LogHistory() {
7273
}
7374

7475
function MainContent() {
76+
const navigate = useNavigate();
7577

7678
/** Retrieve user's logs from API */
7779
const [logs, setLogs] = useState([]);
@@ -186,6 +188,31 @@ function MainContent() {
186188
}
187189
};
188190

191+
const handleViewLog = async (selectedLogs) => {
192+
const selectedLogIds = Object.entries(selectedLogs)
193+
.filter(([, isSelected]) => isSelected)
194+
.map(([id]) => id);
195+
196+
if (selectedLogIds.length === 0) {
197+
alert("Please select a log to view/edit");
198+
return;
199+
}
200+
if (selectedLogIds.length > 1) {
201+
alert("Please select only one log to view/edit");
202+
return;
203+
}
204+
205+
const selectedLog = logs.find(log => log.id === selectedLogIds[0]);
206+
if (selectedLog) {
207+
navigate("/manualEntry", {
208+
state: {
209+
logData: selectedLog,
210+
isEditing: true
211+
}
212+
});
213+
}
214+
};
215+
189216
/** Array of log actions */
190217
const logActions = [
191218
// {
@@ -206,7 +233,7 @@ const logActions = [
206233
{
207234
label: "View",
208235
icon: EyeIcon,
209-
onClick: () => {},
236+
onClick: () => handleViewLog(selectedLogs),
210237
},
211238
{
212239
label: "Delete",

0 commit comments

Comments
 (0)