feat: recurring templates, planned and to-confirm lists
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
63620f8c52
commit
bfaa38510b
10 files changed
+792
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { FormPage } from "@/components/FormPage";
|
||||
import { RecurringForm } from "@/components/recurrents/RecurringForm";
|
||||
import { decimalFromCents } from "@/domain/money";
|
||||
import { todayParis } from "@/lib/dates";
|
||||
import { requireUser } from "@/server/auth";
|
||||
import { prisma } from "@/server/db";
|
||||
import { getFormData, getRecurringDefs } from "@/server/repo";
|
||||
|
||||
export default async function EditRecurringPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const user = await requireUser();
|
||||
const { id } = await params;
|
||||
const today = todayParis();
|
||||
const [data, defs, row] = await Promise.all([
|
||||
getFormData(today),
|
||||
getRecurringDefs(),
|
||||
prisma.recurring.findUnique({ where: { id }, select: { loanId: true } }),
|
||||
]);
|
||||
const def = defs.find((d) => d.id === id);
|
||||
if (!def || !row) notFound();
|
||||
if (row.loanId) redirect(`/credits/${row.loanId}`);
|
||||
const targets = defs.filter((d) => d.kind === "EXPENSE").map((d) => ({ id: d.id, label: d.label, split: d.split }));
|
||||
return (
|
||||
<FormPage title="Modifier le récurrent" back="/recurrents">
|
||||
<p className="mb-4 rounded-[10px] bg-accent-soft px-3 py-2 text-[13px] text-accent">
|
||||
Les changements s'appliquent aux prochaines échéances. Les opérations déjà passées ne bougent pas.
|
||||
</p>
|
||||
<RecurringForm
|
||||
{...data}
|
||||
targets={targets}
|
||||
currentUserId={user.id}
|
||||
today={today}
|
||||
initial={{ ...def, amount: decimalFromCents(def.amount).replace(".", ",") }}
|
||||
/>
|
||||
</FormPage>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user