postal-code.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { useTranslation } from 'react-i18next'
  2. import { FormGroup, ControlLabel } from 'react-bootstrap'
  3. import useValidateField from '../../../hooks/use-validate-field'
  4. import classnames from 'classnames'
  5. import { callFnsInSequence } from '../../../../../utils/functions'
  6. type PostalCodeProps = {
  7. errorFields: Record<string, boolean> | undefined
  8. value: string
  9. onChange: (e: React.ChangeEvent<HTMLInputElement>) => void
  10. }
  11. function PostalCode(props: PostalCodeProps) {
  12. const { t } = useTranslation()
  13. const { validate, isValid } = useValidateField()
  14. return (
  15. <FormGroup
  16. controlId="postal-code"
  17. className={classnames({
  18. 'has-error': !isValid || props.errorFields?.postal_code,
  19. })}
  20. >
  21. <ControlLabel>{t('postal_code')}</ControlLabel>
  22. <input
  23. id="postal-code"
  24. className="form-control"
  25. name="postalCode"
  26. data-recurly="postal_code"
  27. type="text"
  28. required
  29. maxLength={255}
  30. onBlur={validate}
  31. onChange={callFnsInSequence(validate, props.onChange)}
  32. value={props.value}
  33. />
  34. {!isValid && (
  35. <span className="input-feedback-message">
  36. {t('this_field_is_required')}
  37. </span>
  38. )}
  39. </FormGroup>
  40. )
  41. }
  42. export default PostalCode