All files / src/components/common/Filter ClearFiltersButton.tsx

83.33% Statements 10/12
50% Branches 1/2
80% Functions 4/5
80% Lines 8/10

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            2x                             2x 3x 3x   3x 18x 3x   3x                    
import Stack from "@mui/material/Stack";
import { useAppDispatch } from "@redux/hooks";
import { ActionCreatorWithoutPayload } from "@reduxjs/toolkit";
import { useAppSelector } from "@redux/hooks";
import { RootState } from "@redux/types/store";
 
const btnStyle = {
  gap: 0.5,
  ml: "auto",
  fontSize: 14,
  cursor: "pointer",
  flexDirection: "row",
  alignItems: "center",
  color: "#575353",
};
 
interface ClearFiltersButtonProps {
  clear: ActionCreatorWithoutPayload<string>;
  selector: (state: RootState) => any;
}
 
const ClearFiltersButton = ({ clear, selector }: ClearFiltersButtonProps) => {
  const dispatch = useAppDispatch();
  const filters = useAppSelector(selector);
 
  const empt = [filters]
    .map((x: any) => Object.values(x).every((x) => !x))
    .every((x: any) => x);
 
  Eif (empt) return null;
 
  return (
    <Stack sx={btnStyle} onClick={() => dispatch(clear())}>
      Clear Filters
    </Stack>
  );
};
 
export default ClearFiltersButton;