All files / client/src/components ErrorBar.tsx

64.28% Statements 9/14
100% Branches 0/0
42.85% Functions 3/7
61.53% Lines 8/13

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                356x 370x 370x   1530x   370x                                             1x           1x         1x            
import { ReactElement } from "react";
import styled from "styled-components";
import { useTranslation } from "react-i18next";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useAppDispatch, useAppSelector } from "client/utils/hooks";
import { removeError } from "client/views/admin/adminSlice";
import { HEADER_HEIGHT } from "client/components/Header";
 
export const ErrorBar = (): ReactElement | null => {
  const { t } = useTranslation();
  const dispatch = useAppDispatch();
 
  const errors = useAppSelector((state) => state.admin.errors);
 
  const errorList = errors.map((error) => {
    return (
      <StyledError
        key={error}
        onClick={() => {
          dispatch(removeError(error));
        }}
      >
        <span>{error}</span>{" "}
        <span>
          {" "}
          <FontAwesomeIcon
            icon="xmark"
            aria-label={t("iconAltText.closeError")}
          />
        </span>
      </StyledError>
    );
  });
 
  return <ErrorContainer>{errorList}</ErrorContainer>;
};
 
const StyledError = styled.p`
  display: flex;
  justify-content: space-between;
  padding: 10px;
  background-color: ${(props) => props.theme.backgroundWarning};
  color: ${(props) => props.theme.textMain};
  border: 1px solid ${(props) => props.theme.borderWarning};
  border-radius: 4px;
  margin: 4px 2px;
`;
 
const ErrorContainer = styled.div`
  position: sticky;
  top: ${HEADER_HEIGHT}px;
  z-index: 10;
  cursor: pointer;
`;