You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.8 KiB

4 weeks ago
'use client';
import { Button } from '@/components/ui/button';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';
import { useGroupSensors } from '@/hooks/useGroupSensor';
import Link from 'next/link';
import { useParams, useRouter } from 'next/navigation';
export default function GroupSensorsPage() {
const params = useParams();
const groupId = Number(params.groupId);
const router = useRouter();
const { data, isLoading, isError, refetch } = useGroupSensors(groupId);
return (
<main className="mx-auto max-w-full px-4 py-6">
<div className="mb-4 flex items-center justify-between">
<div className="flex items-center gap-2">
<Button variant="ghost" onClick={() => router.back()}>
</Button>
<h1 className="text-xl font-semibold"> </h1>
</div>
<Button onClick={() => refetch()}></Button>
</div>
{isLoading && <p className="text-gray-500"> ...</p>}
{isError && <p className="text-red-600"> .</p>}
{!isLoading && !isError && (
<div className="overflow-x-auto rounded border">
<Table>
<TableHeader>
<TableRow>
<TableHead className="px-4 py-2 text-center">ID</TableHead>
<TableHead className="px-4 py-2 text-center"></TableHead>
<TableHead className="px-4 py-2 text-center"></TableHead>
<TableHead className="px-4 py-2 text-center"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{data && data.length > 0 ? (
data.map((s) => (
<TableRow key={s.id}>
<TableCell className="px-4 py-2 text-center">{s.id}</TableCell>
<TableCell className="px-4 py-2 text-center">{s.name}</TableCell>
<TableCell className="px-4 py-2 text-center">{s.unit ?? '-'}</TableCell>
<TableCell className="flex items-center justify-center px-4 py-2 text-center">
<Button asChild variant="outline">
<Link href={`/sensors/${s.id}`}></Link>
</Button>
</TableCell>
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={4} className="px-4 py-6 text-center text-gray-500">
.
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
</div>
)}
</main>
);
}