@@ -10,7 +10,7 @@ import {
10
10
CircularProgress ,
11
11
Alert ,
12
12
Collapse ,
13
- Link
13
+ Link ,
14
14
} from "@mui/material" ;
15
15
import {
16
16
Timeline ,
@@ -19,30 +19,31 @@ import {
19
19
TimelineConnector ,
20
20
TimelineContent ,
21
21
TimelineDot ,
22
- TimelineOppositeContent
22
+ TimelineOppositeContent ,
23
23
} from "@mui/lab" ;
24
24
import { Grid } from "@mui/system" ;
25
25
import { Layout as DashboardLayout } from "/src/layouts/index.js" ;
26
26
import { HeaderedTabbedLayout } from "/src/layouts/HeaderedTabbedLayout" ;
27
27
import { ApiGetCall } from "/src/api/ApiCall" ;
28
28
import { useRouter } from "next/router" ;
29
- import {
30
- Policy ,
31
- Sync ,
32
- PlayArrow ,
29
+ import {
30
+ Policy ,
31
+ Sync ,
32
+ PlayArrow ,
33
33
Error as ErrorIcon ,
34
34
Warning as WarningIcon ,
35
35
Info as InfoIcon ,
36
36
CheckCircle as SuccessIcon ,
37
- ExpandMore
37
+ ExpandMore ,
38
38
} from "@mui/icons-material" ;
39
39
import tabOptions from "./tabOptions.json" ;
40
+ import { useSettings } from "../../../../hooks/use-settings" ;
40
41
41
42
const Page = ( ) => {
42
43
const router = useRouter ( ) ;
43
44
const { templateId } = router . query ;
44
- const [ daysToLoad , setDaysToLoad ] = useState ( 7 ) ;
45
- const [ tenant ] = useState ( "oglenet.onmicrosoft.com" ) ; // You might want to get this from context or props
45
+ const [ daysToLoad , setDaysToLoad ] = useState ( 5 ) ;
46
+ const tenant = useSettings ( ) . currentTenant ;
46
47
const [ expandedMessages , setExpandedMessages ] = useState ( new Set ( ) ) ;
47
48
48
49
// Toggle message expansion
@@ -64,7 +65,7 @@ const Page = () => {
64
65
return {
65
66
text : message . substring ( 0 , maxLength ) + "..." ,
66
67
fullText : message ,
67
- isTruncated : true
68
+ isTruncated : true ,
68
69
} ;
69
70
} ;
70
71
@@ -73,16 +74,15 @@ const Page = () => {
73
74
const endDate = new Date ( ) ;
74
75
const startDate = new Date ( ) ;
75
76
startDate . setDate ( endDate . getDate ( ) - days ) ;
76
-
77
+
77
78
return {
78
- startDate : startDate . toISOString ( ) . split ( 'T' ) [ 0 ] . replace ( / - / g, '' ) ,
79
- endDate : endDate . toISOString ( ) . split ( 'T' ) [ 0 ] . replace ( / - / g, '' )
79
+ startDate : startDate . toISOString ( ) . split ( "T" ) [ 0 ] . replace ( / - / g, "" ) ,
80
+ endDate : endDate . toISOString ( ) . split ( "T" ) [ 0 ] . replace ( / - / g, "" ) ,
80
81
} ;
81
82
} ;
82
83
83
84
const { startDate, endDate } = getDateRange ( daysToLoad ) ;
84
85
85
- // API call to get logs
86
86
const logsData = ApiGetCall ( {
87
87
url : `/api/Listlogs?tenant=${ tenant } &StartDate=${ startDate } &EndDate=${ endDate } &Filter=true` ,
88
88
queryKey : `Listlogs-${ tenant } -${ startDate } -${ endDate } ` ,
@@ -92,39 +92,39 @@ const Page = () => {
92
92
const getSeverityConfig = ( severity ) => {
93
93
const severityLower = severity ?. toLowerCase ( ) ;
94
94
switch ( severityLower ) {
95
- case ' error' :
96
- return { icon : < ErrorIcon /> , color : ' error' , chipColor : ' error' } ;
97
- case ' warning' :
98
- return { icon : < WarningIcon /> , color : ' warning' , chipColor : ' warning' } ;
99
- case ' info' :
100
- return { icon : < InfoIcon /> , color : ' info' , chipColor : ' info' } ;
101
- case ' success' :
102
- return { icon : < SuccessIcon /> , color : ' success' , chipColor : ' success' } ;
95
+ case " error" :
96
+ return { icon : < ErrorIcon /> , color : " error" , chipColor : " error" } ;
97
+ case " warning" :
98
+ return { icon : < WarningIcon /> , color : " warning" , chipColor : " warning" } ;
99
+ case " info" :
100
+ return { icon : < InfoIcon /> , color : " info" , chipColor : " info" } ;
101
+ case " success" :
102
+ return { icon : < SuccessIcon /> , color : " success" , chipColor : " success" } ;
103
103
default :
104
- return { icon : < InfoIcon /> , color : ' grey' , chipColor : ' default' } ;
104
+ return { icon : < InfoIcon /> , color : " grey" , chipColor : " default" } ;
105
105
}
106
106
} ;
107
107
108
108
// Format date for display
109
109
const formatDate = ( dateString ) => {
110
110
const date = new Date ( dateString ) ;
111
111
return {
112
- time : date . toLocaleTimeString ( 'en-US' , {
113
- hour : '2-digit' ,
114
- minute : '2-digit' ,
115
- hour12 : false
112
+ time : date . toLocaleTimeString ( "en-US" , {
113
+ hour : "2-digit" ,
114
+ minute : "2-digit" ,
115
+ hour12 : false ,
116
+ } ) ,
117
+ date : date . toLocaleDateString ( "en-US" , {
118
+ month : "short" ,
119
+ day : "numeric" ,
120
+ year : "numeric" ,
116
121
} ) ,
117
- date : date . toLocaleDateString ( 'en-US' , {
118
- month : 'short' ,
119
- day : 'numeric' ,
120
- year : 'numeric'
121
- } )
122
122
} ;
123
123
} ;
124
124
125
125
// Load more days
126
126
const handleLoadMore = ( ) => {
127
- setDaysToLoad ( prev => prev + 7 ) ;
127
+ setDaysToLoad ( ( prev ) => prev + 7 ) ;
128
128
} ;
129
129
130
130
// Actions for the ActionsMenu
@@ -175,9 +175,9 @@ const Page = () => {
175
175
] ;
176
176
177
177
// Sort logs by date (newest first)
178
- const sortedLogs = logsData . data ? [ ... logsData . data ] . sort ( ( a , b ) =>
179
- new Date ( b . DateTime ) - new Date ( a . DateTime )
180
- ) : [ ] ;
178
+ const sortedLogs = logsData . data
179
+ ? [ ... logsData . data ] . sort ( ( a , b ) => new Date ( b . DateTime ) - new Date ( a . DateTime ) )
180
+ : [ ] ;
181
181
182
182
return (
183
183
< HeaderedTabbedLayout
@@ -203,15 +203,11 @@ const Page = () => {
203
203
) }
204
204
205
205
{ logsData . isError && (
206
- < Alert severity = "error" >
207
- Failed to load activity logs. Please try again.
208
- </ Alert >
206
+ < Alert severity = "error" > Failed to load activity logs. Please try again.</ Alert >
209
207
) }
210
208
211
209
{ logsData . data && sortedLogs . length === 0 && (
212
- < Alert severity = "info" >
213
- No activity logs found for the selected time period.
214
- </ Alert >
210
+ < Alert severity = "info" > No activity logs found for the selected time period.</ Alert >
215
211
) }
216
212
217
213
{ logsData . data && sortedLogs . length > 0 && (
@@ -233,58 +229,67 @@ const Page = () => {
233
229
const { time, date } = formatDate ( log . DateTime ) ;
234
230
const { text, fullText, isTruncated } = truncateMessage ( log . Message ) ;
235
231
const isExpanded = expandedMessages . has ( index ) ;
236
-
232
+
237
233
return (
238
234
< TimelineItem key = { index } >
239
235
< TimelineOppositeContent
240
- sx = { { m : ' auto 0' , minWidth : 100 , maxWidth : 100 } }
236
+ sx = { { m : " auto 0" , minWidth : 100 , maxWidth : 100 } }
241
237
align = "right"
242
238
variant = "body2"
243
239
color = "text.secondary"
244
240
>
245
241
< Typography variant = "caption" display = "block" fontSize = "0.7rem" >
246
242
{ date }
247
243
</ Typography >
248
- < Typography variant = "caption" display = "block" fontWeight = "bold" fontSize = "0.75rem" >
244
+ < Typography
245
+ variant = "caption"
246
+ display = "block"
247
+ fontWeight = "bold"
248
+ fontSize = "0.75rem"
249
+ >
249
250
{ time }
250
251
</ Typography >
251
252
</ TimelineOppositeContent >
252
-
253
+
253
254
< TimelineSeparator >
254
255
< TimelineDot color = { color } variant = "outlined" size = "small" >
255
256
{ icon }
256
257
</ TimelineDot >
257
258
{ index < sortedLogs . length - 1 && < TimelineConnector /> }
258
259
</ TimelineSeparator >
259
-
260
- < TimelineContent sx = { { py : ' 8px' , px : 2 } } >
260
+
261
+ < TimelineContent sx = { { py : " 8px" , px : 2 } } >
261
262
< Stack spacing = { 1 } >
262
263
< Box display = "flex" alignItems = "center" gap = { 1 } flexWrap = "wrap" >
263
264
< Chip
264
265
label = { log . Severity }
265
266
color = { chipColor }
266
267
size = "small"
267
268
variant = "outlined"
268
- sx = { { fontSize : ' 0.7rem' , height : 20 } }
269
+ sx = { { fontSize : " 0.7rem" , height : 20 } }
269
270
/>
270
271
< Chip
271
272
label = { log . API }
272
273
size = "small"
273
274
variant = "outlined"
274
- sx = { { fontSize : ' 0.7rem' , height : 20 } }
275
+ sx = { { fontSize : " 0.7rem" , height : 20 } }
275
276
/>
276
277
{ log . IP && (
277
278
< Chip
278
279
label = { `IP: ${ log . IP } ` }
279
280
size = "small"
280
281
variant = "outlined"
281
- sx = { { fontSize : ' 0.7rem' , height : 20 } }
282
+ sx = { { fontSize : " 0.7rem" , height : 20 } }
282
283
/>
283
284
) }
284
285
</ Box >
285
-
286
+
286
287
< Box >
287
- < Typography variant = "body2" fontWeight = "medium" sx = { { fontSize : '0.875rem' } } >
288
+ < Typography
289
+ variant = "body2"
290
+ fontWeight = "medium"
291
+ sx = { { fontSize : "0.875rem" } }
292
+ >
288
293
{ isExpanded ? fullText : text }
289
294
</ Typography >
290
295
{ isTruncated && (
@@ -294,18 +299,22 @@ const Page = () => {
294
299
onClick = { ( ) => toggleMessageExpansion ( index ) }
295
300
sx = { {
296
301
mt : 0.5 ,
297
- display : ' block' ,
298
- textAlign : ' left' ,
299
- fontSize : ' 0.75rem'
302
+ display : " block" ,
303
+ textAlign : " left" ,
304
+ fontSize : " 0.75rem" ,
300
305
} }
301
306
>
302
- { isExpanded ? ' Show less' : ' Show more' }
307
+ { isExpanded ? " Show less" : " Show more" }
303
308
</ Link >
304
309
) }
305
310
</ Box >
306
-
311
+
307
312
{ log . User && (
308
- < Typography variant = "caption" color = "text.secondary" sx = { { fontSize : '0.7rem' } } >
313
+ < Typography
314
+ variant = "caption"
315
+ color = "text.secondary"
316
+ sx = { { fontSize : "0.7rem" } }
317
+ >
309
318
User: { log . User }
310
319
</ Typography >
311
320
) }
@@ -315,7 +324,7 @@ const Page = () => {
315
324
) ;
316
325
} ) }
317
326
</ Timeline >
318
-
327
+
319
328
< Box display = "flex" justifyContent = "center" mt = { 3 } >
320
329
< Button
321
330
variant = "outlined"
@@ -337,4 +346,4 @@ const Page = () => {
337
346
338
347
Page . getLayout = ( page ) => < DashboardLayout > { page } </ DashboardLayout > ;
339
348
340
- export default Page ;
349
+ export default Page ;
0 commit comments