summaryrefslogtreecommitdiff
path: root/src/components/proxies/ClosePrevConns.tsx
blob: 6718fb265924df73b8d9ae12de046aab4dd122d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import * as React from 'react';

import Button from '../Button';
import { FlexCenter } from '../shared/Styled';

const { useRef, useEffect } = React;

type Props = {
  onClickPrimaryButton?: () => void;
  onClickSecondaryButton?: () => void;
};

export function ClosePrevConns({ onClickPrimaryButton, onClickSecondaryButton }: Props) {
  const primaryButtonRef = useRef<HTMLButtonElement>(null);
  const secondaryButtonRef = useRef<HTMLButtonElement>(null);
  useEffect(() => {
    primaryButtonRef.current.focus();
  }, []);

  const handleKeyDown = (e: React.KeyboardEvent) => {
    if (e.keyCode === 39) {
      secondaryButtonRef.current.focus();
    } else if (e.keyCode === 37) {
      primaryButtonRef.current.focus();
    }
  };

  return (
    // eslint-disable-next-line jsx-a11y/no-static-element-interactions
    <div onKeyDown={handleKeyDown}>
      <h2>Close Connections?</h2>
      <p>
        Click 'Yes' to close those connections that are still using the old selected proxy in this
        group
      </p>
      <div style={{ height: 30 }} />
      <FlexCenter>
        <Button onClick={onClickPrimaryButton} ref={primaryButtonRef}>
          Yes
        </Button>
        <div style={{ width: 20 }} />
        <Button onClick={onClickSecondaryButton} ref={secondaryButtonRef}>
          No
        </Button>
      </FlexCenter>
    </div>
  );
}