TimeToRetainBtn.tsx 696 B

1234567891011121314151617181920212223242526272829
  1. import React from 'react';
  2. import { useFormContext } from 'react-hook-form';
  3. import cx from 'classnames';
  4. import { MILLISECONDS_IN_WEEK } from 'lib/constants';
  5. interface Props {
  6. inputName: string;
  7. text: string;
  8. value: number;
  9. }
  10. const TimeToRetainBtn: React.FC<Props> = ({ inputName, text, value }) => {
  11. const { setValue, watch } = useFormContext();
  12. const watchedValue = watch(inputName, MILLISECONDS_IN_WEEK.toString());
  13. return (
  14. <button
  15. type="button"
  16. className={cx('button', {
  17. 'is-info': watchedValue === value.toString(),
  18. })}
  19. onClick={() => setValue(inputName, value)}
  20. >
  21. {text}
  22. </button>
  23. );
  24. };
  25. export default TimeToRetainBtn;