mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 13:25:18 +00:00
fix #23: allow empty convertedTotal
This commit is contained in:
@@ -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"
|
||||
|
||||
|
||||
@@ -146,15 +146,17 @@ export default function TransactionEditForm({
|
||||
/>
|
||||
{formData.currencyCode !== settings.default_currency || formData.convertedTotal !== 0 ? (
|
||||
<>
|
||||
<FormInput
|
||||
title={`Total converted to ${formData.convertedCurrencyCode || "UNKNOWN CURRENCY"}`}
|
||||
type="number"
|
||||
step="0.01"
|
||||
name="convertedTotal"
|
||||
defaultValue={formData.convertedTotal.toFixed(2)}
|
||||
isRequired={fieldMap.convertedTotal.isRequired}
|
||||
className="max-w-36"
|
||||
/>
|
||||
{formData.convertedTotal !== null && (
|
||||
<FormInput
|
||||
title={`Total converted to ${formData.convertedCurrencyCode || "UNKNOWN CURRENCY"}`}
|
||||
type="number"
|
||||
step="0.01"
|
||||
name="convertedTotal"
|
||||
defaultValue={formData.convertedTotal.toFixed(2)}
|
||||
isRequired={fieldMap.convertedTotal.isRequired}
|
||||
className="max-w-36"
|
||||
/>
|
||||
)}
|
||||
{(!formData.convertedCurrencyCode || formData.convertedCurrencyCode !== settings.default_currency) && (
|
||||
<FormSelectCurrency
|
||||
title="Convert to"
|
||||
|
||||
@@ -8,18 +8,21 @@ export const transactionFormSchema = z
|
||||
type: z.string().optional(),
|
||||
total: z
|
||||
.string()
|
||||
.optional()
|
||||
.transform((val) => {
|
||||
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(),
|
||||
|
||||
Reference in New Issue
Block a user