Skip to content

Commit 4682166

Browse files
committed
✨ [feat][frontend] Make event entries editable when editing an event
1 parent 83c5715 commit 4682166

2 files changed

Lines changed: 13 additions & 66 deletions

File tree

frontend/src/components/event/event-entries-field.tsx

Lines changed: 13 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GripVertical, Receipt, X } from 'lucide-react'
22
import { Reorder, useDragControls } from 'motion/react'
3-
import { type RefObject, useMemo, useRef } from 'react'
3+
import { type RefObject, useRef } from 'react'
44

55
import { CategoryCombobox } from '@/components/category-combobox'
66
import { CurrencyAmountInput } from '@/components/currency-amount-input'
@@ -17,22 +17,19 @@ import {
1717
import { Input } from '@/components/ui/input'
1818
import {
1919
Table,
20-
TableBody,
2120
TableCell,
2221
TableHead,
2322
TableHeader,
2423
TableRow
2524
} from '@/components/ui/table'
2625
import { 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

3028
interface EventEntriesFieldProps {
3129
categories: CategoryReadWithChildren[]
3230
currencies: CurrencyRead[]
3331
value: EventEntryDraft[]
3432
onChange: (value: EventEntryDraft[]) => void
35-
readOnly?: boolean
3633
}
3734

3835
interface 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}

frontend/src/components/event/event-form.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ export function EventForm({
9393
isEditing ? editingEvent.entries.map(toEventEntryDraft) : []
9494
)
9595

96-
// The API can only batch-create entries, so an existing event's entries are
97-
// shown but not editable.
9896
const incompleteEntry = entries.some(
9997
(entry) =>
10098
entry.categoryId == null ||
@@ -180,7 +178,6 @@ export function EventForm({
180178
currencies={currencies}
181179
value={entries}
182180
onChange={setEntries}
183-
readOnly={isEditing}
184181
/>
185182
</Field>
186183

0 commit comments

Comments
 (0)