mirror of
https://github.com/spliit-app/spliit.git
synced 2026-03-10 14:09:06 +01:00
* add expense categories * set category to Payment for reimbursements * Insert categories as part of the migration * Display category groups --------- Co-authored-by: Sebastien Castiel <sebastien@castiel.me>
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { ExpenseForm } from '@/components/expense-form'
|
|
import { deleteExpense, getExpense, getCategories, getGroup, updateExpense } from '@/lib/api'
|
|
import { expenseFormSchema } from '@/lib/schemas'
|
|
import { Metadata } from 'next'
|
|
import { notFound, redirect } from 'next/navigation'
|
|
|
|
export const metadata: Metadata = {
|
|
title: 'Edit expense',
|
|
}
|
|
|
|
export default async function EditExpensePage({
|
|
params: { groupId, expenseId },
|
|
}: {
|
|
params: { groupId: string; expenseId: string }
|
|
}) {
|
|
const categories = await getCategories()
|
|
const group = await getGroup(groupId)
|
|
if (!group) notFound()
|
|
const expense = await getExpense(groupId, expenseId)
|
|
if (!expense) notFound()
|
|
|
|
async function updateExpenseAction(values: unknown) {
|
|
'use server'
|
|
const expenseFormValues = expenseFormSchema.parse(values)
|
|
await updateExpense(groupId, expenseId, expenseFormValues)
|
|
redirect(`/groups/${groupId}`)
|
|
}
|
|
|
|
async function deleteExpenseAction() {
|
|
'use server'
|
|
await deleteExpense(expenseId)
|
|
redirect(`/groups/${groupId}`)
|
|
}
|
|
|
|
return (
|
|
<ExpenseForm
|
|
group={group}
|
|
expense={expense}
|
|
categories={categories}
|
|
onSubmit={updateExpenseAction}
|
|
onDelete={deleteExpenseAction}
|
|
/>
|
|
)
|
|
}
|