From 289b436236e64f2eadc9c10ca113300ef336aaeb Mon Sep 17 00:00:00 2001 From: vas3k Date: Thu, 22 May 2025 19:42:41 +0200 Subject: [PATCH] fix #23: allow empty convertedTotal --- app/(app)/unsorted/page.tsx | 2 +- components/transactions/edit.tsx | 20 +++++++++++--------- forms/transactions.ts | 10 ++++++---- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/(app)/unsorted/page.tsx b/app/(app)/unsorted/page.tsx index 3179939..2627c1b 100644 --- a/app/(app)/unsorted/page.tsx +++ b/app/(app)/unsorted/page.tsx @@ -13,7 +13,7 @@ import { getFields } from "@/models/fields" import { getUnsortedFiles } from "@/models/files" import { getProjects } from "@/models/projects" import { getSettings } from "@/models/settings" -import { FileText, PartyPopper, Settings, Upload, Brain } from "lucide-react" +import { FileText, PartyPopper, Settings, Upload } from "lucide-react" import { Metadata } from "next" import Link from "next/link" diff --git a/components/transactions/edit.tsx b/components/transactions/edit.tsx index 44ed37b..d2b0f8e 100644 --- a/components/transactions/edit.tsx +++ b/components/transactions/edit.tsx @@ -146,15 +146,17 @@ export default function TransactionEditForm({ /> {formData.currencyCode !== settings.default_currency || formData.convertedTotal !== 0 ? ( <> - + {formData.convertedTotal !== null && ( + + )} {(!formData.convertedCurrencyCode || formData.convertedCurrencyCode !== settings.default_currency) && ( { + if (!val || val.trim() === '') return null const num = parseFloat(val) if (isNaN(num)) { throw new z.ZodError([{ message: "Invalid total", path: ["total"], code: z.ZodIssueCode.custom }]) } return Math.round(num * 100) // convert to cents - }) - .optional(), + }), currencyCode: z.string().max(5).optional(), convertedTotal: z .string() + .optional() .transform((val) => { + if (!val || val.trim() === '') return null const num = parseFloat(val) if (isNaN(num)) { throw new z.ZodError([ @@ -27,8 +30,7 @@ export const transactionFormSchema = z ]) } return Math.round(num * 100) // convert to cents - }) - .optional(), + }), convertedCurrencyCode: z.string().max(5).optional(), categoryCode: z.string().optional(), projectCode: z.string().optional(),