1
- 'use client'
2
1
import { CategorySelector } from '@/components/category-selector'
3
2
import { ExpenseDocumentsInput } from '@/components/expense-documents-input'
4
3
import { SubmitButton } from '@/components/submit-button'
@@ -34,7 +33,7 @@ import {
34
33
SelectTrigger ,
35
34
SelectValue ,
36
35
} from '@/components/ui/select'
37
- import { getCategories , getExpense , getGroup , randomId } from '@/lib/api'
36
+ import { randomId } from '@/lib/api'
38
37
import { RuntimeFeatureFlags } from '@/lib/featureFlags'
39
38
import { useActiveUser } from '@/lib/hooks'
40
39
import {
@@ -43,6 +42,7 @@ import {
43
42
expenseFormSchema ,
44
43
} from '@/lib/schemas'
45
44
import { cn } from '@/lib/utils'
45
+ import { AppRouterOutput } from '@/trpc/routers/_app'
46
46
import { zodResolver } from '@hookform/resolvers/zod'
47
47
import { Save } from 'lucide-react'
48
48
import { useTranslations } from 'next-intl'
@@ -51,18 +51,9 @@ import { useSearchParams } from 'next/navigation'
51
51
import { useEffect , useState } from 'react'
52
52
import { useForm } from 'react-hook-form'
53
53
import { match } from 'ts-pattern'
54
- import { DeletePopup } from './delete-popup'
55
- import { extractCategoryFromTitle } from './expense-form-actions'
56
- import { Textarea } from './ui/textarea'
57
-
58
- export type Props = {
59
- group : NonNullable < Awaited < ReturnType < typeof getGroup > > >
60
- expense ?: NonNullable < Awaited < ReturnType < typeof getExpense > > >
61
- categories : NonNullable < Awaited < ReturnType < typeof getCategories > > >
62
- onSubmit : ( values : ExpenseFormValues , participantId ?: string ) => Promise < void >
63
- onDelete ?: ( participantId ?: string ) => Promise < void >
64
- runtimeFeatureFlags : RuntimeFeatureFlags
65
- }
54
+ import { DeletePopup } from '../../../../components/delete-popup'
55
+ import { extractCategoryFromTitle } from '../../../../components/expense-form-actions'
56
+ import { Textarea } from '../../../../components/ui/textarea'
66
57
67
58
const enforceCurrencyPattern = ( value : string ) =>
68
59
value
@@ -73,7 +64,9 @@ const enforceCurrencyPattern = (value: string) =>
73
64
. replace ( / # / , '.' ) // change back # to dot
74
65
. replace ( / [ ^ - \d . ] / g, '' ) // remove all non-numeric characters
75
66
76
- const getDefaultSplittingOptions = ( group : Props [ 'group' ] ) => {
67
+ const getDefaultSplittingOptions = (
68
+ group : AppRouterOutput [ 'groups' ] [ 'get' ] [ 'group' ] ,
69
+ ) => {
77
70
const defaultValue = {
78
71
splitMode : 'EVENLY' as const ,
79
72
paidFor : group . participants . map ( ( { id } ) => ( {
@@ -147,15 +140,23 @@ async function persistDefaultSplittingOptions(
147
140
148
141
export function ExpenseForm ( {
149
142
group,
150
- expense,
151
143
categories,
144
+ expense,
152
145
onSubmit,
153
146
onDelete,
154
147
runtimeFeatureFlags,
155
- } : Props ) {
148
+ } : {
149
+ group : AppRouterOutput [ 'groups' ] [ 'get' ] [ 'group' ]
150
+ categories : AppRouterOutput [ 'categories' ] [ 'list' ] [ 'categories' ]
151
+ expense ?: AppRouterOutput [ 'groups' ] [ 'expenses' ] [ 'get' ] [ 'expense' ]
152
+ onSubmit : ( value : ExpenseFormValues , participantId ?: string ) => Promise < void >
153
+ onDelete ?: ( participantId ?: string ) => Promise < void >
154
+ runtimeFeatureFlags : RuntimeFeatureFlags
155
+ } ) {
156
156
const t = useTranslations ( 'ExpenseForm' )
157
157
const isCreate = expense === undefined
158
158
const searchParams = useSearchParams ( )
159
+
159
160
const getSelectedPayer = ( field ?: { value : string } ) => {
160
161
if ( isCreate && typeof window !== 'undefined' ) {
161
162
const activeUser = localStorage . getItem ( `${ group . id } -activeUser` )
0 commit comments