All files / src/features/ChangeLog ChangelogButton.tsx

90.9% Statements 20/22
54.83% Branches 17/31
100% Functions 6/6
100% Lines 18/18

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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102                                      22x               284x   284x   284x   284x 116x 83x 83x         284x 284x             284x 50x 50x 50x     284x   284x             29x                                                               22x          
import { StyledIconButton } from "@common/IconButton";
import { Box, styled } from "@mui/material";
import { useCustomTheme } from "@theme/hooks/useCustomTheme";
import { ClockCounterwiseIcon } from "@assets/icons/RebrandedIcons";
import { palette } from "@palette";
import { useEffect, useMemo, useState } from "react";
import { animated, useSpring } from "react-spring";
import { SIDE_PANEL_BUTTON_OFFSET } from "@constants/constants";
import { NEW_BASE_PANEL_WIDTH } from "@shared/SidePanel/GiveSidePanel";
 
type Props = {
  isLoading?: boolean;
  handleOpenChangelogModal: (open?: boolean | undefined) => void;
  isOpen?: boolean;
  doublePanelActive?: boolean;
  isOpenConversations?: boolean;
  secondPanelWidth?: number;
};
 
const ChangelogButton = ({
  isLoading = false,
  handleOpenChangelogModal,
  isOpen = false,
  doublePanelActive,
  isOpenConversations,
  secondPanelWidth = NEW_BASE_PANEL_WIDTH,
}: Props) => {
  const { isMobileView } = useCustomTheme();
 
  const isOpenState = Boolean(isOpen);
 
  const [visible, setVisible] = useState(false);
  // Trigger animation once data is loaded and approved
  useEffect(() => {
    if (!isLoading) {
      const timeout = setTimeout(() => setVisible(true), 10);
      return () => clearTimeout(timeout);
    }
  }, [isLoading]);
 
  // Animate slide + opacity
  const shouldShow = visible && !isOpen;
  const springStyles = useSpring({
    opacity: shouldShow ? 1 : 0,
    transform: shouldShow ? "translateY(0px)" : "translateY(100px)",
    bottom: isOpenConversations ? 24 : 90,
    config: { duration: 300 },
  });
 
  const bottom = useMemo(() => {
    Iif (isMobileView) return "initial";
    Iif (isOpenConversations) return "24px";
    return "90px";
  }, [isMobileView, isOpenConversations]);
 
  const AnimatedButton = animated(StyledIconButton);
 
  return (
    <AnimatedButton
      style={{
        ...springStyles,
        transition: "right 250ms ease-in-out",
      }}
      id="changelogButton"
      onClick={() => handleOpenChangelogModal(!isMobileView ? true : !isOpen)}
      disabled={isLoading}
      sx={{
        borderRadius: "50%",
        position: isMobileView ? (isOpenState ? "relative" : "fixed") : "fixed",
        bottom: bottom,
        right: isMobileView
          ? isOpenState
            ? "0px"
            : "initial"
          : `${
              (doublePanelActive
                ? NEW_BASE_PANEL_WIDTH + secondPanelWidth
                : secondPanelWidth) + SIDE_PANEL_BUTTON_OFFSET
            }px`,
        boxShadow: isMobileView
          ? "0px 2.625px 13.125px 0px rgba(2, 2, 2, 0.15)"
          : "initial",
        backgroundColor: palette.neutral.white,
        zIndex: 3,
      }}
      data-testid="changelog-button"
    >
      <StyledContainer>
        <ClockCounterwiseIcon width="30px" height="30px" />
      </StyledContainer>
    </AnimatedButton>
  );
};
 
export default ChangelogButton;
 
const StyledContainer = styled(Box)({
  borderRadius: "50%",
  padding: "10px 10px 4px 10px",
  backgroundColor: palette.neutral.white,
});