coupon-code.tsx 894 B

12345678910111213141516171819202122232425262728293031323334
  1. import { useTranslation } from 'react-i18next'
  2. import { FormGroup, ControlLabel } from 'react-bootstrap'
  3. import { usePaymentContext } from '../../../context/payment-context'
  4. type CouponCodeProps = {
  5. value: string
  6. onChange: (e: React.ChangeEvent<HTMLInputElement>) => void
  7. }
  8. function CouponCode(props: CouponCodeProps) {
  9. const { t } = useTranslation()
  10. const { addCoupon } = usePaymentContext()
  11. const handleApplyCoupon = (e: React.FocusEvent<HTMLInputElement>) => {
  12. addCoupon(e.target.value)
  13. }
  14. return (
  15. <FormGroup controlId="coupon-code">
  16. <ControlLabel>{t('coupon_code')}</ControlLabel>
  17. <input
  18. id="coupon-code"
  19. className="form-control"
  20. data-recurly="coupon"
  21. type="text"
  22. onBlur={handleApplyCoupon}
  23. onChange={props.onChange}
  24. value={props.value}
  25. />
  26. </FormGroup>
  27. )
  28. }
  29. export default CouponCode