diff --git a/resources/js/packages/ui/src/utils/money.ts b/resources/js/packages/ui/src/utils/money.ts index 41c01c65..20e1d564 100644 --- a/resources/js/packages/ui/src/utils/money.ts +++ b/resources/js/packages/ui/src/utils/money.ts @@ -43,6 +43,13 @@ export function formatCents( return formatMoney(amount / 100, currency, format, currencySymbol, numberFormat); } +/* + * Converts a major-unit amount (e.g. 19.99) to integer hundredths (i.e. cents) + */ +export function toCents(value: number | undefined | null): number { + return Math.round((value || 0) * 100); +} + export function getOrganizationCurrencySymbol(currency: string) { return (0) .toLocaleString('de-DE', { diff --git a/resources/js/utils/apiValidation.ts b/resources/js/utils/apiValidation.ts index fcc06853..c48e9f8f 100644 --- a/resources/js/utils/apiValidation.ts +++ b/resources/js/utils/apiValidation.ts @@ -23,6 +23,21 @@ export function getApiValidationFieldErrors(error: unknown): Record { + return Object.fromEntries( + Object.entries(getApiValidationFieldErrors(error)).map(([field, message]) => [ + field.replace(/\.(\d+)(?=\.|$)/g, '[$1]'), + message, + ]) + ); +} + export function getApiValidationMessage(error: unknown, fallback: string): string { if (!isApiValidationError(error)) { return fallback;