@@ -7,6 +7,45 @@ import { Eye, CheckCircle2, XCircle, MapPin, ArrowUpDown, ArrowUp, ArrowDown } f
77import * as Icons from "lucide-react" ;
88import type { LucideProps } from "lucide-react" ;
99
10+ const SEVERITY_STYLES = {
11+ critical : { pill : "bg-rose-50 text-rose-700 ring-rose-200" , Icon : Icons . TriangleAlert } ,
12+ high : { pill : "bg-orange-50 text-orange-700 ring-orange-200" , Icon : Icons . CircleAlert } ,
13+ medium : { pill : "bg-yellow-50 text-yellow-700 ring-yellow-200" , Icon : Icons . Minus } ,
14+ low : { pill : "bg-emerald-50 text-emerald-700 ring-emerald-200" , Icon : Icons . ArrowDown } ,
15+ default : { pill : "bg-slate-50 text-slate-700 ring-slate-200" , Icon : Icons . CircleAlert } ,
16+ } as const ;
17+
18+ function SeverityBadge ( { value } : { value ?: string } ) {
19+ const key = ( value ?? "" ) . trim ( ) . toLowerCase ( ) as keyof typeof SEVERITY_STYLES ;
20+ const { pill, Icon } = SEVERITY_STYLES [ key ] ?? SEVERITY_STYLES . default ;
21+ return (
22+ < span className = { `inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium ring-1 ring-inset ${ pill } ` } >
23+ < Icon className = "w-3.5 h-3.5" aria-hidden = "true" />
24+ < span className = "capitalize" > { value ?? "Unknown" } </ span >
25+ </ span >
26+ ) ;
27+ }
28+
29+ const STATUS_STYLES = {
30+ active : "bg-emerald-50 text-emerald-700 ring-emerald-200" ,
31+ resolved : "bg-sky-50 text-sky-700 ring-sky-200" ,
32+ dismissed : "bg-rose-50 text-rose-700 ring-rose-200" ,
33+ // pending: "bg-amber-50 text-amber-700 ring-amber-200",
34+ // acknowledged: "bg-indigo-50 text-indigo-700 ring-indigo-200",
35+ // inactive: "bg-slate-100 text-slate-700 ring-slate-300",
36+ default : "bg-slate-50 text-slate-700 ring-slate-200" ,
37+ } as const ;
38+
39+ function StatusBadge ( { value } : { value ?: string } ) {
40+ const key = ( value ?? "" ) . trim ( ) . toLowerCase ( ) as keyof typeof STATUS_STYLES ;
41+ const pill = STATUS_STYLES [ key ] ?? STATUS_STYLES . default ;
42+ return (
43+ < span className = { `inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ring-1 ring-inset ${ pill } ` } >
44+ < span className = "capitalize" > { value ?? "Unknown" } </ span >
45+ </ span >
46+ ) ;
47+ }
48+
1049export type Alert = {
1150 id : number ;
1251 severity : string ;
@@ -126,12 +165,31 @@ export default function AlertTable({ alerts }: Props) {
126165 < TableBody >
127166 { sortedAlerts . map ( ( alr ) => {
128167 const EventIcon = iconFromName ( alr . event ?. icon ) ;
168+ const alrCode = `ALT${ String ( alr . id ) . padStart ( 3 , "0" ) } ` ;
169+
129170 return (
130171 < TableRow key = { alr . id } >
131- < TableCell > { alr . severity } </ TableCell >
132- < TableCell > { alr . id } </ TableCell >
133- < TableCell > { alr . create_date } { alr . create_time } </ TableCell >
134- < TableCell > { alr . camera . name } </ TableCell >
172+ < TableCell >
173+ < SeverityBadge value = { alr . severity } />
174+ </ TableCell >
175+
176+ < TableCell > { alrCode } </ TableCell >
177+
178+ < TableCell >
179+ < div className = "flex items-center gap-2" >
180+ < Icons . Clock3 className = "h-4 w-4 text-[var(--color-primary)]" aria-hidden = "true" />
181+ < span > { alr . create_date } { alr . create_time } </ span >
182+ </ div >
183+ </ TableCell >
184+ { /* <TableCell>{alr.create_date} {alr.create_time}</TableCell> */ }
185+
186+ < TableCell >
187+ < div className = "flex items-center gap-2" >
188+ < Icons . Camera className = "h-4 w-4 text-[var(--color-primary)]" aria-hidden = "true" />
189+ < span > { alr . camera . name } </ span >
190+ </ div >
191+ </ TableCell >
192+ { /* <TableCell>{alr.camera.name}</TableCell> */ }
135193
136194 { /* Event Type + icon */ }
137195 < TableCell >
@@ -149,21 +207,30 @@ export default function AlertTable({ alerts }: Props) {
149207 </ div >
150208 </ TableCell >
151209
152- < TableCell > { alr . status } </ TableCell >
210+ < TableCell >
211+ < StatusBadge value = { alr . status } />
212+ </ TableCell >
153213
154214 < TableCell className = "flex gap-2" >
155- < button className = "inline-flex items-center gap-2 bg-[var(--color-primary)] text-white px-4 py-1 rounded-sm hover:opacity-90" >
215+ { /* ปุ่ม View แสดงเสมอ */ }
216+ < button className = "inline-flex items-center justify-center gap-2 px-3 py-1 rounded-sm bg-white border border-[var(--color-primary)] text-[var(--color-primary)] hover:bg-[var(--color-primary)] hover:border-[var(--color-primary)] hover:text-white transition focus:outline-none focus:ring-2 focus:ring-offset-2" >
156217 < Eye className = "h-4 w-4" aria-hidden = "true" />
157218 < span > View</ span >
158219 </ button >
159- < button className = "inline-flex items-center gap-2 bg-[var(--color-success)] text-white px-4 py-1 rounded-sm hover:opacity-90" >
160- < CheckCircle2 className = "h-4 w-4" aria-hidden = "true" />
161- < span > Resolved</ span >
162- </ button >
163- < button className = "inline-flex items-center gap-2 bg-[var(--color-danger)] text-white px-4 py-1 rounded-sm hover:opacity-90" >
164- < XCircle className = "h-4 w-4" aria-hidden = "true" />
165- < span > Dismiss</ span >
166- </ button >
220+
221+ { /* แสดงปุ่ม Resolved / Dismiss เฉพาะเมื่อสถานะเป็น Active */ }
222+ { alr . status ?. trim ( ) . toLowerCase ( ) === "active" && (
223+ < >
224+ < button className = "inline-flex items-center justify-center gap-2 px-3 py-1 rounded-sm bg-white border border-[var(--color-success)] text-[var(--color-success)] hover:bg-[var(--color-success)] hover:border-[var(--color-success)] hover:text-white transition focus:outline-none focus:ring-2 focus:ring-offset-2" >
225+ < CheckCircle2 className = "h-4 w-4" aria-hidden = "true" />
226+ < span > Resolved</ span >
227+ </ button >
228+ < button className = "inline-flex items-center justify-center gap-2 px-3 py-1 rounded-sm bg-white border border-[var(--color-danger)] text-[var(--color-danger)] hover:bg-[var(--color-danger)] hover:border-[var(--color-danger)] hover:text-white transition focus:outline-none focus:ring-2 focus:ring-offset-2" >
229+ < XCircle className = "h-4 w-4" aria-hidden = "true" />
230+ < span > Dismiss</ span >
231+ </ button >
232+ </ >
233+ ) }
167234 </ TableCell >
168235 </ TableRow >
169236 ) ;
0 commit comments