All files / src/pages/Dashboard/components Summary.tsx

0% Statements 0/8
0% Branches 0/8
0% Functions 0/4
0% Lines 0/8

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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121                                                                                                                                                                                                                                                 
import { Text } from "@common/Text";
import { Box, Grid, Stack } from "@mui/material";
import SummaryComponent from "./SummaryComponent";
import TrendsComponent from "./TrendsComponent";
import CustomerComponent from "./CustomerComponent";
import { palette } from "@palette";
import { useDashboardContext } from "../Provider/DashboardContext";
import { Skeleton } from "@mui/material";
import { CustomerPeopleIcon } from "@assets/rebrandIcons";
import FadeUpWrapper from "@components/animation/FadeUpWrapper";
import { useThemeContext } from "@components/EnterpriseSettings/Branding/Provider/CustomThemeProvider";
 
function Summary() {
  const { gradient } = useThemeContext();
  const { isLoading, data } = useDashboardContext();
  const hasCustomers = data?.topCustomers && data?.topCustomers?.length > 0;
 
  return (
    <>
      {isLoading ? (
        <Box my="24px">
          <Skeleton
            variant="rectangular"
            height="290px"
            width="100%"
            sx={{ borderRadius: "12px" }}
          />
        </Box>
      ) : (
        <Grid
          justifyContent="space-between"
          container
          width="100%"
          my="24px"
          bgcolor={palette.neutral[5]}
          p="10px 6px"
          borderRadius="12px"
          columnSpacing="40px"
          rowSpacing={2}
          mx="auto"
          pr="16px"
        >
          <Grid item xs={12} sm={6}>
            <FadeUpWrapper delay={300}>
              <>
                <Title label="Summary" />
                {data?.summaryArr.map((c, idx, arr) => (
                  <SummaryComponent
                    idx={idx}
                    key={c.label + c.value}
                    arr={arr}
                    {...c}
                  />
                ))}
              </>
            </FadeUpWrapper>
          </Grid>
          <Grid
            overflow="hidden"
            item
            xs={12}
            sm={6}
          >
            <FadeUpWrapper
              delay={350}
              containerProps={{ height: "100%" }}
              customStyle={{ height: "100%" }}
            >
              <Stack
                alignItems="stretch"
                justifyContent="flex-start"
                height="inherit"
              >
                <Title label="Top Customers" noMb={!hasCustomers} />
                {hasCustomers ? (
                  <>
                    {data?.topCustomers.map((c, idx) => (
                      <CustomerComponent key={c.name + idx} {...c} />
                    ))}
                  </>
                ) : (
                  <Stack
                    justifyContent="center"
                    direction="column"
                    alignItems="center"
                    sx={{ "& p": { flexGrow: 0 } }}
                  >
                    <CustomerPeopleIcon gradient width={32} height={32} />
                    <Text
                      gradient={gradient}
                      fontSize="12px"
                      fontWeight="book"
                      lineHeight="14.4px"
                    >
                      You don&apos;t have any customers yet
                    </Text>
                  </Stack>
                )}
              </Stack>
            </FadeUpWrapper>
          </Grid>
        </Grid>
      )}
    </>
  );
}
 
export default Summary;
 
const Title = ({ label, noMb }: { label: string; noMb?: boolean }) => (
  <Text
    lineHeight="21px"
    fontSize="18px"
    fontWeight="book"
    color={palette.neutral[80]}
    mb={noMb ? 0 : "16px"}
  >
    {label}
  </Text>
);