Improve UI
This commit is contained in:
@@ -27,7 +27,15 @@ export const CURRENCY_CONFIG = {
|
||||
},
|
||||
} as const;
|
||||
|
||||
type CurrencyCode = keyof typeof CURRENCY_CONFIG;
|
||||
export type CurrencyCode = keyof typeof CURRENCY_CONFIG;
|
||||
|
||||
// Default currency for the application (Euro)
|
||||
export const DEFAULT_CURRENCY: CurrencyCode = 'EUR';
|
||||
|
||||
// Get currency symbol
|
||||
export const getCurrencySymbol = (currencyCode: CurrencyCode = DEFAULT_CURRENCY): string => {
|
||||
return CURRENCY_CONFIG[currencyCode]?.symbol || '€';
|
||||
};
|
||||
|
||||
// Format currency amount
|
||||
export const formatCurrency = (
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { SmartAction as ImportedSmartAction, SmartActionType } from '../api/types/events';
|
||||
import { useTenantStore } from '../stores/tenant.store';
|
||||
import { getTenantCurrencySymbol } from '../hooks/useTenantCurrency';
|
||||
|
||||
// ============================================================
|
||||
// Types (using imported types from events.ts)
|
||||
@@ -168,7 +170,7 @@ export class SmartActionHandler {
|
||||
body: JSON.stringify({
|
||||
action: 'approve',
|
||||
approved_by: 'current_user',
|
||||
notes: `Approved via alert action${amount ? ` (€${amount})` : ''}`,
|
||||
notes: `Approved via alert action${amount ? ` (${getTenantCurrencySymbol(useTenantStore.getState().currentTenant?.currency)}${amount})` : ''}`,
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -2,14 +2,49 @@
|
||||
* Validation utilities for forms and data
|
||||
*/
|
||||
|
||||
// Email validation
|
||||
import { z } from 'zod';
|
||||
|
||||
// =============================================================================
|
||||
// ZOD SCHEMAS - Centralized validation schemas for consistent validation
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Email validation schema using Zod
|
||||
* - Uses Zod's built-in email validator (RFC 5322 compliant)
|
||||
* - Trims whitespace before validation
|
||||
* - Provides consistent error messages in Spanish
|
||||
*/
|
||||
export const emailSchema = z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1, 'El email es requerido')
|
||||
.email('Por favor, ingrese un email válido');
|
||||
|
||||
/**
|
||||
* Validates an email string using the centralized Zod schema
|
||||
* @param email - The email string to validate
|
||||
* @returns Object with isValid boolean and optional error message
|
||||
*/
|
||||
export const validateEmail = (email: string): { isValid: boolean; error?: string } => {
|
||||
const result = emailSchema.safeParse(email);
|
||||
if (result.success) {
|
||||
return { isValid: true };
|
||||
}
|
||||
return { isValid: false, error: result.error.errors[0]?.message };
|
||||
};
|
||||
|
||||
// =============================================================================
|
||||
// LEGACY VALIDATION FUNCTIONS - Kept for backward compatibility
|
||||
// =============================================================================
|
||||
|
||||
// Email validation (legacy - use validateEmail or emailSchema instead)
|
||||
export const isValidEmail = (email: string): boolean => {
|
||||
if (!email || typeof email !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
return emailRegex.test(email.trim());
|
||||
const result = emailSchema.safeParse(email);
|
||||
return result.success;
|
||||
};
|
||||
|
||||
// Spanish phone number validation
|
||||
|
||||
Reference in New Issue
Block a user