Add loading spinner for API keys page

This commit is contained in:
KMKoushik
2024-06-03 07:45:18 +10:00
parent ba0e1b2dcd
commit ae7ebb6a34

View File

@@ -11,6 +11,7 @@ import {
import { formatDistanceToNow } from "date-fns"; import { formatDistanceToNow } from "date-fns";
import { api } from "~/trpc/react"; import { api } from "~/trpc/react";
import DeleteApiKey from "./delete-api-key"; import DeleteApiKey from "./delete-api-key";
import Spinner from "@unsend/ui/src/spinner";
export default function ApiList() { export default function ApiList() {
const apiKeysQuery = api.apiKey.getApiKeys.useQuery(); const apiKeysQuery = api.apiKey.getApiKeys.useQuery();
@@ -30,24 +31,35 @@ export default function ApiList() {
</TableRow> </TableRow>
</TableHeader> </TableHeader>
<TableBody> <TableBody>
{apiKeysQuery.data?.map((apiKey) => ( {apiKeysQuery.isLoading ? (
<TableRow key={apiKey.id}> <TableRow className="h-32">
<TableCell>{apiKey.name}</TableCell> <TableCell colSpan={6} className="text-center py-4">
<TableCell>{apiKey.partialToken}</TableCell> <Spinner
<TableCell>{apiKey.permission}</TableCell> className="w-6 h-6 mx-auto"
<TableCell> innerSvgClass="stroke-primary"
{apiKey.lastUsed />
? formatDistanceToNow(apiKey.lastUsed)
: "Never"}
</TableCell>
<TableCell>
{formatDistanceToNow(apiKey.createdAt, { addSuffix: true })}
</TableCell>
<TableCell>
<DeleteApiKey apiKey={apiKey} />
</TableCell> </TableCell>
</TableRow> </TableRow>
))} ) : (
apiKeysQuery.data?.map((apiKey) => (
<TableRow key={apiKey.id}>
<TableCell>{apiKey.name}</TableCell>
<TableCell>{apiKey.partialToken}</TableCell>
<TableCell>{apiKey.permission}</TableCell>
<TableCell>
{apiKey.lastUsed
? formatDistanceToNow(apiKey.lastUsed)
: "Never"}
</TableCell>
<TableCell>
{formatDistanceToNow(apiKey.createdAt, { addSuffix: true })}
</TableCell>
<TableCell>
<DeleteApiKey apiKey={apiKey} />
</TableCell>
</TableRow>
))
)}
</TableBody> </TableBody>
</Table> </Table>
</div> </div>