File tree Expand file tree Collapse file tree 1 file changed +62
-3
lines changed Expand file tree Collapse file tree 1 file changed +62
-3
lines changed Original file line number Diff line number Diff line change 1- import React from "react" ;
1+ import React , { useEffect , useState } from "react" ;
22
33export default function Dashboard ( ) {
4+ const [ tasks , setTasks ] = useState ( [ ] ) ;
5+ const [ loading , setLoading ] = useState ( true ) ;
6+ const API_URL = import . meta. env . VITE_API_URL || "https://fat-eibl-backend.onrender.com" ;
7+
8+ useEffect ( ( ) => {
9+ const fetchTasks = async ( ) => {
10+ try {
11+ const response = await fetch ( `${ API_URL } /tasks` ) ;
12+ if ( ! response . ok ) throw new Error ( "Failed to load tasks" ) ;
13+ const data = await response . json ( ) ;
14+ setTasks ( data ) ;
15+ } catch ( err ) {
16+ console . error ( "Error loading tasks:" , err ) ;
17+ } finally {
18+ setLoading ( false ) ;
19+ }
20+ } ;
21+
22+ fetchTasks ( ) ;
23+ } , [ API_URL ] ) ;
24+
425 return (
5- < div style = { { textAlign : "center" , marginTop : "100px" } } >
6- < h2 > Dashboard Page</ h2 >
26+ < div style = { { textAlign : "center" , marginTop : "60px" , fontFamily : "Arial" } } >
27+ < h1 style = { { color : "#0047AB" } } > Finance Audit Dashboard</ h1 >
28+ < h3 style = { { color : "#666" } } > Edme Insurance Brokers Limited</ h3 >
29+ { loading ? (
30+ < p > Loading reports...</ p >
31+ ) : (
32+ < table
33+ border = "1"
34+ cellPadding = "10"
35+ style = { {
36+ margin : "30px auto" ,
37+ borderCollapse : "collapse" ,
38+ width : "80%" ,
39+ background : "#f9f9f9" ,
40+ } }
41+ >
42+ < thead >
43+ < tr style = { { background : "#0047AB" , color : "white" } } >
44+ < th > ID</ th >
45+ < th > Task</ th >
46+ < th > Status</ th >
47+ </ tr >
48+ </ thead >
49+ < tbody >
50+ { tasks . length > 0 ? (
51+ tasks . map ( ( task ) => (
52+ < tr key = { task . id } >
53+ < td > { task . id } </ td >
54+ < td > { task . title } </ td >
55+ < td > { task . status } </ td >
56+ </ tr >
57+ ) )
58+ ) : (
59+ < tr >
60+ < td colSpan = "3" > No data available</ td >
61+ </ tr >
62+ ) }
63+ </ tbody >
64+ </ table >
65+ ) }
766 </ div >
867 ) ;
968}
You can’t perform that action at this time.
0 commit comments