Skip to content

Commit 8d11075

Browse files
committed
Merge branch 'develop'
2 parents 7415e34 + b6cf924 commit 8d11075

File tree

7 files changed

+419
-290
lines changed

7 files changed

+419
-290
lines changed

client/my-app/src/app/(with-layout)/cameras/page.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// app/(with-layout)/cameras/page.tsx
12
import * as StatusCard from "../../components/Utilities/StatusCard";
23
import CreateEventForm from "@/app/components/Forms/CreateEventForm";
34
import { Separator } from "@/components/ui/separator";
@@ -9,30 +10,34 @@ import CreateCameraForm from "@/app/components/Forms/CreateCameraForm";
910
import EventGrid from "@/app/components/Events/EventCardGrid";
1011

1112
type ViewMode = "grid" | "list";
13+
type SP = Record<string, string | string[] | undefined>;
1214

1315
export 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

Comments
 (0)