import { useEffect, useState } from "react";
import { Button } from "@/components/ui/button";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
const placeholderUrl = "https://jsonplaceholder.typicode.com/users";
export default function ApiKeysTable() {
const [rows, setRows] = useState([]);
useEffect(() => {
const loadRows = async () => {
const response = await fetch(placeholderUrl);
const users = await response.json();
setRows(
users.slice(0, 5).map((user) => ({
id: `key_${user.id}`,
label: `${user.company.name} key`,
prefix: "ls_live_AbCd...",
createdAt: new Date().toISOString(),
lastUsedAt: "-",
}))
);
};
loadRows();
}, []);
return (
<div className="space-y-4">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-muted-foreground">
Replace the placeholder API with your Lettuce Stream requests once
your auth flow is ready.
</p>
</div>
<Button>Create key</Button>
</div>
<Table>
<TableHeader>
<TableRow>
<TableHead>Label</TableHead>
<TableHead>Prefix</TableHead>
<TableHead>Created</TableHead>
<TableHead>Last used</TableHead>
<TableHead className="text-right">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{rows.map((row) => (
<TableRow key={row.id}>
<TableCell className="font-medium">{row.label}</TableCell>
<TableCell>{row.prefix}</TableCell>
<TableCell>{row.createdAt}</TableCell>
<TableCell>{row.lastUsedAt}</TableCell>
<TableCell className="text-right">
<Button variant="ghost">Revoke</Button>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
);
}