All files / src/features/GiveNotificationModal/components FooterSelector.tsx

71.42% Statements 15/21
69.23% Branches 9/13
50% Functions 3/6
68.42% Lines 13/19

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                                          30x 30x 30x       30x 30x           30x 30x 18x   4x     30x                               30x 1x     30x                                                    
import MessageInput from "@features/GiveConversation/components/MessageInput";
import NiceModal from "@ebay/nice-modal-react";
import { useGiveNotificationContext } from "../provider/GiveNotificationProvider";
import { Stack } from "@mui/material";
import GiveButton from "@shared/Button/GiveButton";
import { PROFILE_MODAL } from "modals/modal_names";
import useOpenGiveNotification from "../hooks/useOpenGiveNotification";
import useNotificationActions from "../hooks/useNotificationActions";
import { useMemo } from "react";
import { useMarkAsRead } from "@features/GiveConversation/hooks/useManageApi";
 
function FooterSelector() {
  const {
    isLoading,
    isEmptyData,
    currentThread,
    setCurrentThread,
    merchantId,
    tab,
    unreadNotifications,
    unreadMessagesCount,
  } = useGiveNotificationContext();
  const { markAllAsReadNotification } = useNotificationActions();
  const { markAsReadMutation: markMessageAsRead } = useMarkAsRead({
    merchantId: merchantId,
    selectedTab: "merchant",
  });
  const { handleClose } = useOpenGiveNotification();
  const openProfileModal = () => {
    handleClose();
    NiceModal.show(PROFILE_MODAL, {
      initialTab: "Notifications",
    });
  };
  const isNotificationTab = tab === "notifications";
  const allRead = useMemo(() => {
    if (isNotificationTab) return !unreadNotifications;
 
    return !unreadMessagesCount;
  }, [unreadMessagesCount, unreadNotifications, isNotificationTab]);
 
  Iif (currentThread && currentThread.id)
    return (
      <MessageInput
        defaultContext={{
          currentThread,
          setCurrentThread,
          setSectionInView: () => null,
          sectionInView: "message_chats",
          subject: currentThread?.name || "",
          setSubject: () => null,
          merchantData: { id: merchantId },
          showMentions: false,
        }}
      />
    );
 
  const markAsRead = () => {
    Eif (isNotificationTab) return markAllAsReadNotification();
    markMessageAsRead.mutate();
  };
  return (
    <Stack
      p="16px 20px"
      gap="8px"
      direction="row"
      justifyContent="flex-end"
      alignItems="center"
      width="100%"
    >
      <GiveButton onClick={openProfileModal} variant="ghost" label="Settings" />
 
      <GiveButton
        sx={{
          borderRadius: "8px",
          padding: "7px 12px",
        }}
        onClick={markAsRead}
        variant="outline"
        disabled={isLoading || isEmptyData || allRead}
        label="Mark All as Read"
      />
    </Stack>
  );
}
 
export default FooterSelector;