|
| 1 | +import type { BookmarkAccount } from '@workspace/db/bookmark-account/bookmark-account' |
| 2 | +import { Button } from '@workspace/ui/components/button' |
| 3 | +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@workspace/ui/components/table' |
| 4 | +import { UiConfirm } from '@workspace/ui/components/ui-confirm' |
| 5 | +import { UiIcon } from '@workspace/ui/components/ui-icon' |
| 6 | +import { ExplorerUiLinkAddress } from './explorer-ui-link-address.tsx' |
| 7 | + |
| 8 | +export function ExplorerUiBookmarkAccountTable({ |
| 9 | + basePath, |
| 10 | + deleteItem, |
| 11 | + updateItem, |
| 12 | + items, |
| 13 | +}: { |
| 14 | + basePath: string |
| 15 | + deleteItem: (item: BookmarkAccount) => Promise<void> |
| 16 | + items: BookmarkAccount[] |
| 17 | + updateItem: (item: BookmarkAccount) => Promise<void> |
| 18 | +}) { |
| 19 | + return ( |
| 20 | + <Table> |
| 21 | + <TableHeader> |
| 22 | + <TableRow className="hover:bg-transparent"> |
| 23 | + <TableHead>LABEL</TableHead> |
| 24 | + <TableHead>ADDRESS</TableHead> |
| 25 | + <TableHead className="w-[120px] text-right">ACTIONS</TableHead> |
| 26 | + </TableRow> |
| 27 | + </TableHeader> |
| 28 | + <TableBody> |
| 29 | + {items.map((item) => ( |
| 30 | + <TableRow key={item.id}> |
| 31 | + <TableCell className=""> |
| 32 | + {item.label ? <span>{item.label}</span> : <span className="text-muted-foreground">No label</span>} |
| 33 | + </TableCell> |
| 34 | + <TableCell className=""> |
| 35 | + <ExplorerUiLinkAddress address={item.address} basePath={basePath} /> |
| 36 | + </TableCell> |
| 37 | + <TableCell className="text-right"> |
| 38 | + <div className="space-x-2"> |
| 39 | + <Button |
| 40 | + onClick={async () => { |
| 41 | + const label = window.prompt('New label?', item.label ?? '') |
| 42 | + await updateItem({ ...item, label: label ?? '' }) |
| 43 | + }} |
| 44 | + size="icon" |
| 45 | + title="Edit label" |
| 46 | + variant="outline" |
| 47 | + > |
| 48 | + <UiIcon icon="edit" /> |
| 49 | + </Button> |
| 50 | + <UiConfirm |
| 51 | + action={async () => { |
| 52 | + await deleteItem(item) |
| 53 | + }} |
| 54 | + actionLabel="Export" |
| 55 | + description={'ARE YOU SURE DELETE'} |
| 56 | + title={'DELETE BOOKMARK'} |
| 57 | + > |
| 58 | + <Button size="icon" title="Delete label" variant="outline"> |
| 59 | + <UiIcon className="text-red-500" icon="delete" /> |
| 60 | + </Button> |
| 61 | + </UiConfirm> |
| 62 | + </div> |
| 63 | + </TableCell> |
| 64 | + </TableRow> |
| 65 | + ))} |
| 66 | + </TableBody> |
| 67 | + </Table> |
| 68 | + ) |
| 69 | +} |
0 commit comments