All files / src/features/Merchants/MerchantSidePanel/UnderwritingTasks/components HeaderElements.tsx

90.9% Statements 10/11
60% Branches 12/20
100% Functions 3/3
100% Lines 10/10

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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188                                                                            84x 84x   84x   84x                                                   168x 168x                                                                                                   84x 84x 84x   84x                                                                                                                              
import { Stack, Box, StackProps } from "@mui/material";
import GiveText from "@shared/Text/GiveText";
import { ModalMerchantData, TaskStatus } from "../types";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import {
  ChatsCircleIcon,
  FlagIcon,
  InfoIcon,
  PaperPlaneTiltIcon,
} from "@phosphor-icons/react";
import { NewStatusDisplayName, StatusDisplayName } from "../utils";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { useAppTheme } from "@theme/v2/Provider";
import { BadgeContentCircle, StyledBadge } from "./Sections.atoms";
import { TTaskStatus } from "../../ApprovalFlowPanel/types";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import { NO_PAH_MESSAGE } from "@constants/permissions";
import { ConversationMenu } from "@features/GiveConversation/components/ConversationMenu";
import { getCounterVariant } from "@features/GiveConversation/utils";
 
interface TitleProps {
  title: string;
  info: string;
  statusName: TaskStatus | TTaskStatus;
  requestAttention?: boolean;
  isError?: boolean;
  hideTooltip?: boolean;
}
 
export function ModalTitle({
  title,
  statusName,
  info,
  requestAttention,
  isError,
  hideTooltip,
}: TitleProps) {
  const { isMobileView } = useCustomThemeV2();
  const { isNewApprovalFlowEnabled } = useGetFeatureFlagValues();
 
  Iif (isError) return <GiveText>There&apos;s been an error</GiveText>;
 
  return (
    <Stack gap="4px">
      <StackWithTooltip
        info={info}
        show={isMobileView}
        requestAttention={requestAttention && isMobileView}
      >
        <GiveText color="secondary" variant="bodyS">
          {isNewApprovalFlowEnabled
            ? NewStatusDisplayName[statusName as TTaskStatus]
            : StatusDisplayName[statusName as TaskStatus]}
        </GiveText>
      </StackWithTooltip>
      <StackWithTooltip info={info} show={!isMobileView && !hideTooltip}>
        <GiveText>{title}</GiveText>
      </StackWithTooltip>
    </Stack>
  );
}
 
function StackWithTooltip({
  show,
  info,
  children,
  requestAttention,
}: StackProps & { show: boolean; info: string; requestAttention?: boolean }) {
  const { palette } = useAppTheme();
  return (
    <Stack direction="row" alignItems="center" gap="4px">
      {children}
      {show && (
        <Box width="20px">
          <GiveTooltip title={info}>
            <InfoIcon size="20px" color={palette.text.secondary} />
          </GiveTooltip>
        </Box>
      )}
      {requestAttention && (
        <FlagIcon size={20} fill={palette?.primitive?.error?.[50]} />
      )}
    </Stack>
  );
}
 
interface RightContentProps {
  openConversation?: () => void;
  openNotification?: () => void;
  didMerchantReply?: boolean;
  hasUnreadMessages?: boolean;
  isMentioned?: boolean;
  unreadMessagesCount?: number;
  requestAttention?: boolean;
  merchantData: ModalMerchantData;
  id: number;
  name: string;
  images?: string[];
  predefinedReason?: string;
  internalThreadID?: number;
  threadID?: number;
}
 
export function RightContent({
  openConversation,
  openNotification,
  didMerchantReply,
  hasUnreadMessages,
  requestAttention,
  merchantData,
  id,
  name,
  images,
  predefinedReason,
  internalThreadID,
  threadID,
  unreadMessagesCount,
  isMentioned,
}: RightContentProps) {
  const { palette } = useAppTheme();
  const { isNewConversationsEnabled } = useGetFeatureFlagValues();
  const hasPAH = !!merchantData?.primaryAccountHolder?.email;
 
  return (
    <Stack direction="row" gap="16px" alignItems="center">
      {requestAttention && (
        <Box p="10px" height="40px" width="40px">
          <FlagIcon size={20} fill={palette?.primitive?.error?.[50]} />
        </Box>
      )}
      {isNewConversationsEnabled ? (
        <ConversationMenu
          images={images}
          taskID={id}
          threadName={name}
          merchantData={{
            id:
              merchantData?.merchantInfo?.merchantID || merchantData.merchantId,
          }}
          messageCount={unreadMessagesCount}
          counterVariant={getCounterVariant({
            isMentioned: !!isMentioned,
            didMerchantReply: !!didMerchantReply,
            unreadMessagesCount: unreadMessagesCount,
          })}
          predefinedMessage={predefinedReason}
          internalThreadID={internalThreadID}
          threadID={threadID}
        />
      ) : (
        <>
          <GiveTooltip title="Conversation">
            <StyledBadge
              invisible={!hasUnreadMessages}
              overlap="circular"
              badgeContent={
                <BadgeContentCircle blue={hasUnreadMessages} small />
              }
            >
              <GiveIconButton
                Icon={ChatsCircleIcon}
                variant="ghost"
                onClick={openConversation}
              />
            </StyledBadge>
          </GiveTooltip>
 
          <GiveTooltip title={hasPAH ? "Message Merchant" : NO_PAH_MESSAGE}>
            <StyledBadge
              invisible={!didMerchantReply}
              overlap="circular"
              badgeContent={<BadgeContentCircle small />}
            >
              <GiveIconButton
                Icon={PaperPlaneTiltIcon}
                variant="ghost"
                onClick={openNotification}
                disabled={!hasPAH}
              />
            </StyledBadge>
          </GiveTooltip>
        </>
      )}
    </Stack>
  );
}