11import { GripVertical , Receipt , X } from 'lucide-react'
22import { Reorder , useDragControls } from 'motion/react'
3- import { type RefObject , useMemo , useRef } from 'react'
3+ import { type RefObject , useRef } from 'react'
44
55import { CategoryCombobox } from '@/components/category-combobox'
66import { CurrencyAmountInput } from '@/components/currency-amount-input'
@@ -17,22 +17,19 @@ import {
1717import { Input } from '@/components/ui/input'
1818import {
1919 Table ,
20- TableBody ,
2120 TableCell ,
2221 TableHead ,
2322 TableHeader ,
2423 TableRow
2524} from '@/components/ui/table'
2625import { type CategoryReadWithChildren , type CurrencyRead } from '@/lib/client'
27- import { type EventEntryDraft , buildCategoryNameMap } from '@/lib/types'
28- import { formatCurrency } from '@/lib/utils'
26+ import { type EventEntryDraft } from '@/lib/types'
2927
3028interface EventEntriesFieldProps {
3129 categories : CategoryReadWithChildren [ ]
3230 currencies : CurrencyRead [ ]
3331 value : EventEntryDraft [ ]
3432 onChange : ( value : EventEntryDraft [ ] ) => void
35- readOnly ?: boolean
3633}
3734
3835interface EventEntryRowProps {
@@ -48,13 +45,8 @@ export function EventEntriesField({
4845 categories,
4946 currencies,
5047 value,
51- onChange,
52- readOnly = false
48+ onChange
5349} : EventEntriesFieldProps ) {
54- const categoryNames = useMemo (
55- ( ) => buildCategoryNameMap ( categories ) ,
56- [ categories ]
57- )
5850 // A row dragged past the table is clipped by the scroll container `Table`
5951 // wraps it in, so keep the drag inside the body.
6052 const body = useRef < HTMLTableSectionElement > ( null )
@@ -81,7 +73,6 @@ export function EventEntriesField({
8173 onChange ( value . filter ( ( item ) => item . key !== key ) )
8274
8375 if ( value . length === 0 ) {
84- if ( readOnly ) return null
8576 return (
8677 < Empty className = "border border-dashed py-8" >
8778 < EmptyHeader >
@@ -102,61 +93,20 @@ export function EventEntriesField({
10293 )
10394 }
10495
105- const header = (
106- < TableHeader >
107- < TableRow >
108- { ! readOnly && < TableHead className = "w-6 px-0" /> }
109- < TableHead > Category</ TableHead >
110- < TableHead className = "w-56" > Amount</ TableHead >
111- < TableHead className = "w-16" > Qty</ TableHead >
112- { readOnly ? (
113- < TableHead > Description</ TableHead >
114- ) : (
115- < TableHead className = "w-8 px-0" />
116- ) }
117- { ! readOnly && < TableHead className = "w-8 px-0" /> }
118- </ TableRow >
119- </ TableHeader >
120- )
121-
122- if ( readOnly ) {
123- return (
124- < div className = "rounded-md border" >
125- < Table >
126- { header }
127- < TableBody >
128- { value . map ( ( entry ) => (
129- < TableRow key = { entry . key } >
130- < TableCell >
131- { entry . categoryId != null
132- ? categoryNames . get ( entry . categoryId )
133- : null }
134- </ TableCell >
135- < TableCell >
136- { entry . currencyCode
137- ? formatCurrency (
138- parseFloat ( entry . amount ) ,
139- entry . currencyCode
140- )
141- : entry . amount }
142- </ TableCell >
143- < TableCell > { entry . quantity } </ TableCell >
144- < TableCell className = "text-muted-foreground" >
145- { entry . description }
146- </ TableCell >
147- </ TableRow >
148- ) ) }
149- </ TableBody >
150- </ Table >
151- </ div >
152- )
153- }
154-
15596 return (
15697 < div className = "space-y-3" >
15798 < div className = "rounded-md border" >
15899 < Table >
159- { header }
100+ < TableHeader >
101+ < TableRow >
102+ < TableHead className = "w-6 px-0" />
103+ < TableHead > Category</ TableHead >
104+ < TableHead className = "w-56" > Amount</ TableHead >
105+ < TableHead className = "w-16" > Qty</ TableHead >
106+ < TableHead className = "w-8 px-0" />
107+ < TableHead className = "w-8 px-0" />
108+ </ TableRow >
109+ </ TableHeader >
160110 < Reorder . Group
161111 as = "tbody"
162112 ref = { body }
0 commit comments