All files / src/features/Merchants/MerchantSidePanel/components/ErrorState ErrorState.tsx

100% Statements 7/7
75% Branches 3/4
100% Functions 3/3
100% Lines 5/5

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                          23x         4x   4x                                                                             23x                 23x                      
import React from "react";
import { Box, Stack } from "@mui/material";
import { FileXIcon } from "@phosphor-icons/react";
import GiveText from "@shared/Text/GiveText";
import GiveButton from "@shared/Button/GiveButton";
import { styled, useAppTheme } from "@theme/v2/Provider";
 
interface ErrorStateProps {
  title?: string;
  message?: string;
  onRetry?: () => void;
}
 
export const ErrorState = ({
  title = "Information could not be loaded",
  message = "We were unable to retrieve this information.",
  onRetry,
}: ErrorStateProps) => {
  const theme = useAppTheme();
 
  return (
    <ErrorStateContainer data-testid="error-state">
      <Stack gap={3} alignItems="center">
        <IconWrapper>
          <FileXIcon
            size={28}
            weight="regular"
            fill={theme.palette?.text?.secondary}
          />
        </IconWrapper>
 
        <Stack gap={0.5} alignItems="center">
          <GiveText variant="bodyL" textAlign="center">
            {title}
          </GiveText>
 
          <GiveText
            variant="bodyS"
            color="secondary"
            textAlign="center"
            sx={{ maxWidth: 400 }}
          >
            {message}
          </GiveText>
        </Stack>
 
        {onRetry && (
          <GiveButton
            label="Try Again"
            variant="outline"
            size="large"
            onClick={onRetry}
          />
        )}
      </Stack>
    </ErrorStateContainer>
  );
};
 
const ErrorStateContainer = styled(Box)(({ theme }) => ({
  display: "flex",
  flexDirection: "column",
  alignItems: "center",
  justifyContent: "center",
  padding: theme.spacing(4),
  textAlign: "center",
}));
 
const IconWrapper = styled(Box)(({ theme }) => ({
  width: 68,
  height: 68,
  borderRadius: 64,
  display: "flex",
  alignItems: "center",
  justifyContent: "center",
  backgroundColor: theme.palette?.primitive?.transparent["darken-5"],
}));
 
export default ErrorState;