All files / src/componentsV2/AccountProfile/NotificationCenter/components Header.tsx

78.57% Statements 11/14
40% Branches 4/10
62.5% Functions 5/8
72.72% Lines 8/11

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                                                      1x                 3x   9x 3x   8x 8x   3x       9x                                                                                                                    
import { Box } from "@mui/material";
import { Divider } from "@mui/material";
import GiveText from "@shared/Text/GiveText";
import { SelectAllContainer } from "./Header.style";
import { TReceiver } from "../GiveNotificationCenterTypes";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import CheckBoxWithLabel from "./CheckBoxWithLabel";
import GiveTabs from "@shared/Tabs/GiveTabs";
import {
  TAlertMethods,
  TParsedAlert,
} from "@components/ProfileMenu/modals/types";
import { TabsArrayItem } from "@components/ProfileMenu/modals/hooks/useAlertsTabs";
 
type Props = {
  tabs: TabsArrayItem[];
  setCurrentTab: React.Dispatch<React.SetStateAction<TReceiver>>;
  currentTab: string;
  isLoading: boolean;
  handleCheckAll: (method: TAlertMethods, operation: "add" | "remove") => void;
  totalAssigned: {
    emailCount: number;
    pushCount: number;
  };
  alerts: TParsedAlert[];
};
 
const Header = ({
  tabs,
  setCurrentTab,
  currentTab,
  isLoading,
  handleCheckAll,
  totalAssigned,
  alerts,
}: Props) => {
  const { isMobileView } = useCustomThemeV2();
 
  const displayedTabs = tabs?.filter((tab) => !tab?.hidden);
  const hasOneTab = displayedTabs?.length === 1;
 
  const emailTotal = alerts?.filter((alert) => !alert?.disabled?.email)?.length;
  const pushTotal = alerts?.filter((alert) => !alert?.disabled?.push)?.length;
 
  return (
    <>
      {!hasOneTab && (
        <GiveTabs
          items={Object.values(tabs)?.map((tab) => ({
            ...tab,
            label: tab?.name,
          }))}
          selected={currentTab}
          type="segmented"
          onClick={(val) => setCurrentTab(val as TReceiver)}
          containerSx={{
            width: "100%",
            justifyContent: "space-around",
            padding: "4px",
          }}
          tabSx={{ flex: 1, justifyContent: "center" }}
        />
      )}
      <SelectAllContainer isMobileView={isMobileView} hasTabs={!hasOneTab}>
        <GiveText variant="bodyS">Set your notification preferences:</GiveText>
        <Box display="flex" flexDirection="row" gap="24px">
          <CheckBoxWithLabel
            label="Push"
            indeterminate={
              pushTotal === totalAssigned?.pushCount
                ? false
                : totalAssigned?.pushCount > 0
            }
            checked={pushTotal === totalAssigned?.pushCount}
            isDisabled={isLoading}
            onChange={() =>
              handleCheckAll(
                "push",
                totalAssigned?.pushCount === 0 ? "add" : "remove",
              )
            }
          />
          <CheckBoxWithLabel
            label="Email"
            indeterminate={
              emailTotal === totalAssigned?.emailCount
                ? false
                : totalAssigned?.emailCount > 0
            }
            checked={emailTotal === totalAssigned?.emailCount}
            isDisabled={isLoading}
            onChange={() =>
              handleCheckAll(
                "email",
                totalAssigned?.emailCount === 0 ? "add" : "remove",
              )
            }
          />
        </Box>
      </SelectAllContainer>
      <Divider sx={{ width: "100%" }} />
    </>
  );
};
 
export default Header;