first-name.tsx 1.2 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 FirstNameProps = {
  7. errorFields: Record<string, boolean> | undefined
  8. value: string
  9. onChange: (e: React.ChangeEvent<HTMLInputElement>) => void
  10. }
  11. function FirstName(props: FirstNameProps) {
  12. const { t } = useTranslation()
  13. const { validate, isValid } = useValidateField()
  14. return (
  15. <FormGroup
  16. controlId="first-name"
  17. className={classnames({
  18. 'has-error': !isValid || props.errorFields?.first_name,
  19. })}
  20. >
  21. <ControlLabel>{t('first_name')}</ControlLabel>
  22. <input
  23. id="first-name"
  24. className="form-control"
  25. name="firstName"
  26. data-recurly="first_name"
  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 FirstName