Files
evidencija-rezija/app/lib/formatStrings.ts
Knee Cola c025c6f2ce Update formatCurrency to use currency code from UserSettings
Changes:
- Updated formatCurrency function:
  - Added currencyCode parameter with EUR default
  - Implemented Intl.NumberFormat for proper currency formatting
  - Added fallback for invalid currency codes
- Updated component hierarchy to pass currency:
  - HomePage: Fetch userSettings and pass to MonthLocationList
  - MonthLocationList: Accept and pass currency to child components
  - LocationCard: Accept currency prop and use in formatCurrency
  - MonthCard: Accept currency prop and use in formatCurrency
  - ViewLocationCard: Pass currency from userSettings to formatCurrency
- Removed hardcoded $ symbols, now using proper currency formatting

All currency amounts now display with the user's selected currency code
from their settings, using locale-appropriate formatting (hr-HR).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 23:04:42 +01:00

43 lines
1.4 KiB
TypeScript

export const formatCurrency = (amount: number, currencyCode: string = "EUR") => {
// format number with 2 decimal places and a thousand separator
// amount is in cents
const amountInUnits = amount / 100;
// Use Intl.NumberFormat for proper currency formatting
try {
return new Intl.NumberFormat('hr-HR', {
style: 'currency',
currency: currencyCode,
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(amountInUnits);
} catch (e) {
// Fallback if invalid currency code
console.error(`Invalid currency code: ${currencyCode}`, e);
}
}
/**
* Formats an IBAN for display with proper spacing
* Format: XX12 XXXX XXXX XXXX XXXX XX
* First group: 2 letters (country) + 2 digits (check) = 4 chars
* Following groups: 4 characters each
* Last group: can be less than 4 characters
* @param iban - IBAN string without spaces
* @returns Formatted IBAN with spaces
*/
export const formatIban = (iban: string | null | undefined): string => {
if (!iban) return "";
// Remove any existing spaces
const cleaned = iban.replace(/\s/g, '');
// Split into groups: first 4 chars, then groups of 4
const groups: string[] = [];
for (let i = 0; i < cleaned.length; i += 4) {
groups.push(cleaned.slice(i, i + 4));
}
return groups.join(' ');
}