1+ // app/(with-layout)/cameras/page.tsx
12import * as StatusCard from "../../components/Utilities/StatusCard" ;
23import CreateEventForm from "@/app/components/Forms/CreateEventForm" ;
34import { Separator } from "@/components/ui/separator" ;
@@ -9,30 +10,34 @@ import CreateCameraForm from "@/app/components/Forms/CreateCameraForm";
910import EventGrid from "@/app/components/Events/EventCardGrid" ;
1011
1112type ViewMode = "grid" | "list" ;
13+ type SP = Record < string , string | string [ ] | undefined > ;
1214
1315export default async function CamerasPage ( {
1416 searchParams,
1517} : {
16- searchParams ?: {
17- view ?: ViewMode ;
18- q ?: string ;
19- status ?: 'Active' | 'Inactive' ;
20- location ?: string ;
21- type ?: string ;
22- } ;
18+ /** Next.js 15: searchParams เป็น Promise แล้ว */
19+ searchParams : Promise < SP > ;
2320} ) {
21+ // ✅ ต้อง await ก่อนใช้งาน
22+ const sp = await searchParams ;
2423
25- const viewMode : ViewMode = searchParams ?. view === "list" ? "list" : "grid" ;
26- const q = searchParams ?. q ?? "" ;
27- const status = searchParams ?. status ;
28- const location = searchParams ?. location ;
29- const type = searchParams ?. type ;
24+ // helper ดึงค่าแบบ string เดี่ยว (กันกรณีเป็น array)
25+ const pick = ( key : keyof SP ) =>
26+ typeof sp ?. [ key ] === "string" ? ( sp [ key ] as string ) : undefined ;
27+
28+ const viewParam = pick ( "view" ) ;
29+ const q = pick ( "q" ) ?? "" ;
30+ const status = pick ( "status" ) as "Active" | "Inactive" | undefined ;
31+ const location = pick ( "location" ) ;
32+ const type = pick ( "type" ) ;
33+
34+ const viewMode : ViewMode = viewParam === "list" ? "list" : "grid" ;
3035
3136 return (
3237 < div className = "space-y-6" >
3338 < StatusCard . DashboardSummaryCameraSection />
3439
35- < div className = "rounded-lg bg-[var(--color-white)] shadow-md p-6 " >
40+ < div className = "rounded-lg bg-[var(--color-white)] shadow-md p-6" >
3641 < div className = "flex flex-col sm:flex-row sm:flex-wrap sm:items-start gap-3 justify-center mb-3" >
3742 < label
3843 htmlFor = "cameraName"
@@ -67,7 +72,7 @@ export default async function CamerasPage({
6772 />
6873 </ div >
6974
70- < div className = "rounded-lg bg-[var(--color-white)] shadow-md p-6 " >
75+ < div className = "rounded-lg bg-[var(--color-white)] shadow-md p-6" >
7176 < div className = "flex flex-wrap items-start gap-3 justify-center mb-3" >
7277 < label
7378 htmlFor = "cameraName"
0 commit comments