The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
import { differenceInDays } from 'date-fns'
import { MoreVerticalIcon, TrashIcon } from 'lucide-react'
import {
Button,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
TableCell,
TableRow,
} from 'ui'
import { Input } from 'ui-patterns/DataInputs/Input'
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
export const StorageCredItem = ({
description,
id,
created_at,
access_key,
onDeleteClick,
}: {
description: string
id: string
created_at: string
access_key: string
onDeleteClick: (id: string) => void
}) => {
const { can: canRemoveAccessKey } = useAsyncCheckPermissionsV2(
FGA_PERMISSIONS.PROJECT.STORAGE_CONFIG_WRITE
)
function daysSince(date: string) {
const now = new Date()
const created = new Date(date)
const diffInDays = differenceInDays(now, created)
if (diffInDays === 0) {
return 'Today'
} else if (diffInDays === 1) {
return `${diffInDays} day ago`
} else {
return `${diffInDays} days ago`
}
}
return (
<TableRow className="h-8 text-ellipsis group">
<TableCell>
<span className="text-foreground">{description}</span>
</TableCell>
<TableCell>
<Input readOnly copy value={access_key} className="font-mono" />
</TableCell>
<TableCell className="text-foreground-lighter whitespace-nowrap">
{daysSince(created_at)}
</TableCell>
<TableCell className="text-right">
{canRemoveAccessKey && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
icon={<MoreVerticalIcon size={14} strokeWidth={1} />}
variant="text"
className="px-1.5 text-foreground-lighter hover:text-foreground"
/>
</DropdownMenuTrigger>
<DropdownMenuContent className="max-w-40" align="end">
<DropdownMenuItem
className="flex gap-1.5 "
onClick={(e) => {
e.preventDefault()
onDeleteClick(id)
}}
>
<TrashIcon size="14" />
Revoke key
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)}
</TableCell>
</TableRow>
)
}