index.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React, { useEffect } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import Dialog from '../Dialog';
  4. import Button from '../Button';
  5. import useKeyPress from '../../hooks/useKeyPress';
  6. import { TextWrapper, BtnWrapper } from './styled';
  7. type Props = {
  8. onCancel: () => void;
  9. onDelete: () => void;
  10. };
  11. const index: React.FC<Props> = ({ onCancel, onDelete }: Props) => {
  12. const { t } = useTranslation('dialog');
  13. const enterKeyPress = useKeyPress('Enter');
  14. const escKeyPress = useKeyPress('Escape');
  15. useEffect(() => {
  16. if (enterKeyPress) {
  17. onDelete();
  18. }
  19. if (escKeyPress) {
  20. onCancel();
  21. }
  22. }, [enterKeyPress, escKeyPress]);
  23. return (
  24. <Dialog open>
  25. <TextWrapper>{t('deleteAnnotationAlert')}</TextWrapper>
  26. <BtnWrapper>
  27. <Button appearance="default-hollow" onClick={onCancel}>
  28. {t('cancel')}
  29. </Button>
  30. <Button
  31. appearance="primary"
  32. onClick={onDelete}
  33. style={{ marginLeft: '16px' }}
  34. >
  35. {t('continue')}
  36. </Button>
  37. </BtnWrapper>
  38. </Dialog>
  39. );
  40. };
  41. export default index;