All files / src/features/Minibuilders/Conversations/Modal Chat.tsx

100% Statements 6/6
83.33% Branches 5/6
100% Functions 1/1
100% Lines 6/6

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                        21x                                     33x       33x 33x   33x           33x                                                                                    
import { DialogContent } from "@mui/material";
import { useAppSelector } from "@redux/hooks";
import { selectThreads } from "@redux/slices/conversations";
import { useCustomTheme } from "@theme/hooks/useCustomTheme";
import { useState } from "react";
import ChatAction from "../Chat/ChatAction";
import ChatMainContent from "../Chat/ChatMainContent";
import { useListThreads } from "../hooks/useListThreads";
import { TQueryObject } from "../types";
import { TMentionedUser } from "../utils/functions";
import ReplySection from "./ReplySection";
 
const Chat = ({
  merchantId,
  queryObject,
  numberOfUnreadMessages,
  handleScroll,
  isRepliesOpen,
  isExpanded,
  onMessageSubmit,
  handleOpenConversationsModal,
}: {
  queryObject: TQueryObject;
  merchantId: number;
  numberOfUnreadMessages: number;
  handleScroll: (e: any) => void;
  isRepliesOpen: boolean;
  isExpanded: boolean;
  onMessageSubmit?: (...props: any[]) => void;
  handleOpenConversationsModal: (open?: boolean) => void;
}) => {
  const [mentionedUser, setMentionedUser] = useState<TMentionedUser>({
    user: "",
    authorAccID: undefined,
  });
  const threads = useAppSelector(selectThreads);
  const { isMobileView } = useCustomTheme();
 
  const { isLoading, isRefetching, ...rest } = useListThreads({
    merchantId,
    hasUnreadMessages: !!numberOfUnreadMessages,
    topicId: queryObject.id as number,
  });
 
  return (
    <>
      <DialogContent
        sx={{
          "&.MuiDialogContent-root, & .MuiDialogContent-root": {
            padding: "0px !important",
          },
        }}
        data-testid="conversation-scroll-container"
        onScroll={handleScroll}
      >
        {isRepliesOpen ? (
          <ReplySection data={rest.data} isMobileView={isMobileView} />
        ) : (
          <ChatMainContent
            isMobileView={isMobileView}
            isExpanded={isExpanded}
            setMentionedUser={setMentionedUser}
            topicId={queryObject.id || undefined}
            parentThreadName={queryObject.name}
            merchantId={merchantId}
            hasUnreadMessages={!!numberOfUnreadMessages}
            data={rest.data}
            isLoading={isLoading}
            isRefetching={isRefetching}
            threads={threads}
          />
        )}
      </DialogContent>
      <ChatAction
        mentionedUser={isRepliesOpen ? mentionedUser : undefined}
        merchantId={merchantId}
        defaultMessage={queryObject.defaultMessage}
        shouldHideMentionIcon={queryObject.shouldHideMentionIcon}
        onMessageSubmit={onMessageSubmit}
        handleOpenConversationsModal={handleOpenConversationsModal}
      />
    </>
  );
};
 
export default Chat;