All files / client/src/components EmailNotificationField.tsx

77.77% Statements 7/9
75% Branches 3/4
75% Functions 3/4
77.77% Lines 7/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 49 50 51 52 53 54 55 56 57 58 59              356x               356x         214x                                 6x           1x         1x     127x              
import { ReactElement, ReactNode } from "react";
import styled from "styled-components";
import { useTranslation } from "react-i18next";
import { RadioButtonGroup } from "client/components/RadioButtonGroup";
import { RadioButton } from "client/components/RadioButton";
import { UncontrolledInput } from "client/components/UncontrolledInput";
 
export const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
 
interface Props {
  enabled: boolean;
  onEnabledChange: (enabled: boolean) => void;
  children: ReactNode;
}
 
export const EmailNotificationField = ({
  enabled,
  onEnabledChange,
  children,
}: Props): ReactElement => {
  const { t } = useTranslation();
 
  return (
    <RadioButtonGroup>
      <RadioButton
        checked={enabled}
        id={"email-notifications-enabled"}
        label={t("email.notifications.accepted")}
        name={"emailNotifications"}
        onChange={() => onEnabledChange(true)}
      />
      <InputContainer>{children}</InputContainer>
      <RadioButton
        checked={!enabled}
        id={"email-notifications-disabled"}
        label={t("email.notifications.rejected")}
        name={"emailNotifications"}
        onChange={() => onEnabledChange(false)}
      />
    </RadioButtonGroup>
  );
};
 
const InputContainer = styled.div`
  display: flex;
  flex-direction: column;
`;
 
export const StyledEmailInput = styled(UncontrolledInput)`
  width: min(250px, 100%);
  ${(props) =>
    props.disabled &&
    `
      background-color: ${props.theme.backgroundDisabled || "#f5f5f5"};
      cursor: not-allowed;
      opacity: 0.6;
    `};
`;