From 570aa713b1b2becf7c06c89610c75d2cb119b532 Mon Sep 17 00:00:00 2001 From: Sebastien Castiel Date: Wed, 6 Dec 2023 15:08:52 -0500 Subject: Delete expense --- src/components/expense-form.tsx | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/components/expense-form.tsx') diff --git a/src/components/expense-form.tsx b/src/components/expense-form.tsx index 35c6aaf..3202788 100644 --- a/src/components/expense-form.tsx +++ b/src/components/expense-form.tsx @@ -1,4 +1,5 @@ 'use client' +import { AsyncButton } from '@/components/async-button' import { SubmitButton } from '@/components/submit-button' import { Card, @@ -33,10 +34,12 @@ import { useForm } from 'react-hook-form' export type Props = { group: NonNullable>> expense?: NonNullable>> - onSubmit: (values: ExpenseFormValues) => void + onSubmit: (values: ExpenseFormValues) => Promise + onDelete?: () => Promise } -export function ExpenseForm({ group, expense, onSubmit }: Props) { +export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) { + const isCreate = expense === undefined const form = useForm({ resolver: zodResolver(expenseFormSchema), defaultValues: expense @@ -54,7 +57,9 @@ export function ExpenseForm({ group, expense, onSubmit }: Props) {
onSubmit(values))}> - Expense information + + {isCreate ? <>Create expense : <>Edit expense} + - - Submit + + + {isCreate ? <>Create : <>Save} + + {!isCreate && onDelete && ( + + Delete + + )}
-- cgit v1.3