-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.tsx
More file actions
91 lines (85 loc) · 2.68 KB
/
index.tsx
File metadata and controls
91 lines (85 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import * as React from 'react'
import { useNavigate } from 'react-router-dom'
import type { ColumnDef } from '@tanstack/react-table'
import { DataTable } from '@/shared/data-table'
import { StatusBadge } from '@/shared/status-badge'
import { TimeDisplay } from '@/shared/time-display'
import { EntityLink } from '@/shared'
import { Button } from '@/components/ui/button'
import { AccountStatus } from '@/api/gen/meridian/current_account/v1/current_account_pb'
import { CreateAccountDialog } from './create-account-dialog'
import type { CurrentAccount } from './types'
import { useAccountsTable } from '../hooks'
const STATUS_OPTIONS = [
{ label: 'Active', value: String(AccountStatus.ACTIVE) },
{ label: 'Frozen', value: String(AccountStatus.FROZEN) },
{ label: 'Closed', value: String(AccountStatus.CLOSED) },
]
export function AccountsPage() {
const navigate = useNavigate()
const [createOpen, setCreateOpen] = React.useState(false)
const { queryKey, queryFn } = useAccountsTable()
const columns: ColumnDef<CurrentAccount>[] = [
{
accessorKey: 'accountId',
header: 'Account ID',
},
{
accessorKey: 'externalReference',
header: 'External Ref',
},
{
accessorKey: 'status',
header: 'Status',
cell: ({ row }) => <StatusBadge status={row.original.status} />,
},
{
accessorKey: 'instrumentCode',
header: 'Instrument',
},
{
accessorKey: 'partyId',
header: 'Party',
cell: ({ row }) => row.original.partyId
? <EntityLink type="party" id={row.original.partyId} />
: <span className="text-muted-foreground">—</span>,
},
{
accessorKey: 'createdAt',
header: 'Created',
cell: ({ row }) => <TimeDisplay timestamp={row.original.createdAt} format="relative" />,
},
]
return (
<div className="p-6">
<div className="mb-6 flex items-center justify-between">
<h1 className="text-2xl font-semibold">Accounts</h1>
<Button onClick={() => setCreateOpen(true)}>Create Account</Button>
</div>
<DataTable
queryKey={queryKey}
queryFn={queryFn}
columns={columns}
filters={[
{
field: 'status',
label: 'Status',
type: 'select',
options: STATUS_OPTIONS,
},
{
field: 'externalReference',
label: 'External Ref',
type: 'text',
},
]}
onRowClick={(row) => navigate(`/accounts/${row.accountId}`)}
/>
<CreateAccountDialog
open={createOpen}
onOpenChange={setCreateOpen}
onCreated={(accountId) => navigate(`/accounts/${accountId}`)}
/>
</div>
)
}