import { Dialog, DialogContent, DialogHeader, DialogTitle, Button } from '@/components/ui'; import { useCallback } from 'react'; import { CreateExchangeRequest, AddExchangeDialogProps } from '../types'; import { validateExchangeForm } from '../utils/validation'; import { useFormValidation } from '../hooks/useFormValidation'; const initialFormData: CreateExchangeRequest = { code: '', name: '', country: '', currency: '', active: true, }; export function AddExchangeDialog({ isOpen, onClose, onCreateExchange, }: AddExchangeDialogProps) { const { formData, errors, isSubmitting, updateField, handleSubmit, reset, } = useFormValidation(initialFormData, validateExchangeForm); const onSubmit = useCallback( async (data: CreateExchangeRequest) => { await onCreateExchange({ ...data, code: data.code.toUpperCase(), country: data.country.toUpperCase(), currency: data.currency.toUpperCase(), }); }, [onCreateExchange] ); const handleFormSubmit = useCallback( (e: React.FormEvent) => { e.preventDefault(); handleSubmit(onSubmit, onClose); }, [handleSubmit, onSubmit, onClose] ); const handleClose = useCallback(() => { reset(); onClose(); }, [reset, onClose]); return ( Add New Exchange

Create a new master exchange with no provider mappings

{/* Exchange Code */}
updateField('code', e.target.value)} placeholder="e.g., NASDAQ, NYSE, TSX" className={`w-full px-3 py-2 border rounded-md bg-surface text-text-primary focus:ring-2 focus:ring-primary-500 focus:border-primary-500 font-mono ${ errors.code ? 'border-danger' : 'border-border' }`} maxLength={10} required /> {errors.code &&

{errors.code}

}
{/* Exchange Name */}
updateField('name', e.target.value)} placeholder="e.g., NASDAQ Stock Market, New York Stock Exchange" className={`w-full px-3 py-2 border rounded-md bg-surface text-text-primary focus:ring-2 focus:ring-primary-500 focus:border-primary-500 ${ errors.name ? 'border-danger' : 'border-border' }`} maxLength={255} required /> {errors.name &&

{errors.name}

}
{/* Country */}
updateField('country', e.target.value)} placeholder="e.g., US, CA, GB" className={`w-full px-3 py-2 border rounded-md bg-surface text-text-primary focus:ring-2 focus:ring-primary-500 focus:border-primary-500 font-mono ${ errors.country ? 'border-danger' : 'border-border' }`} maxLength={2} required /> {errors.country &&

{errors.country}

}
{/* Currency */}
updateField('currency', e.target.value)} placeholder="e.g., USD, EUR, CAD" className={`w-full px-3 py-2 border rounded-md bg-surface text-text-primary focus:ring-2 focus:ring-primary-500 focus:border-primary-500 font-mono ${ errors.currency ? 'border-danger' : 'border-border' }`} maxLength={3} required /> {errors.currency &&

{errors.currency}

}
{/* Active Toggle */}

Inactive exchanges won't be used for new symbol mappings

{/* Action Buttons */}
); }