All files / app/features/messages MessagesHeader.tsx

86.36% Statements 19/22
38.46% Branches 5/13
100% Functions 4/4
85% Lines 17/20

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 572x 2x 2x 2x 2x 2x 2x   2x   2x         2x             2x     2x               2x               2x 2x 2x 2x                        
import { useFeatureValue } from "@growthbook/growthbook-react";
import { styled } from "@mui/material";
import HtmlMeta from "components/HtmlMeta";
import PageTitle from "components/PageTitle";
import MarkAllReadButton from "features/messages/requests/MarkAllReadButton";
import { useTranslation } from "i18n";
import { MESSAGES } from "i18n/namespaces";
import { MessageFilterType } from "routes";
import { assertNever } from "utils/assertNever";
 
const StyledRoot = styled("div")(({ theme }) => ({
  paddingLeft: theme.spacing(2),
  paddingRight: theme.spacing(2),
}));
 
const StyledHeader = styled("div")(({ theme }) => ({
  display: "flex",
  alignItems: "center",
  gap: theme.spacing(2),
}));
 
// Map tab to MarkAllReadButton type (excluding archived)
const getMarkAllReadType = (
  tab: MessageFilterType,
): "chats" | "hosting" | "surfing" | "all" | "public-trips" | null => {
  switch (tab) {
    case "chats":
    case "hosting":
    case "surfing":
    case "public-trips":
      return tab;
    case "all":
    case "unread":
      return "all";
    case "archived":
      return null;
    default:
      return assertNever(tab);
  }
};
 
export default function MessagesHeader({ tab }: { tab: MessageFilterType }) {
  const { t } = useTranslation(MESSAGES);
  const isPublicTripsEnabled = useFeatureValue("public_trips_enabled", false);
  const markAllReadType = getMarkAllReadType(tab === "public-trips" && !isPublicTripsEnabled ? "all" : tab);
 
  return (
    <StyledRoot>
      <HtmlMeta title={t("messages_page.title")} />
      <StyledHeader>
        <PageTitle>{t("messages_page.title")}</PageTitle>
        {markAllReadType && <MarkAllReadButton type={markAllReadType} />}
      </StyledHeader>
    </StyledRoot>
  );
}