@@ -14,6 +14,7 @@ import "./LogHistory.css";
1414import { useAuth } from "../../contexts/AuthContext" ;
1515import { fetchData } from "../../utils/helpers/fetchData" ;
1616import supabase from "../../config/supabase" ;
17+ import { useNavigate } from "react-router-dom" ;
1718
1819const convertToCSV = ( data ) => {
1920 if ( ! data || data . length === 0 ) return '' ;
@@ -72,6 +73,7 @@ export default function LogHistory() {
7273}
7374
7475function 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 */
190217const 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