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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | 3x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 3x 48x 48x 48x | import { Box } from "@mui/material";
import { useAppTheme } from "@theme/v2/Provider";
import { SingeleThreadType } from "../giveNotificationTypes";
import { useGiveNotificationContext } from "../provider/GiveNotificationProvider";
import { Stack } from "@mui/material";
import CounterCircle from "@features/GiveConversation/components/CounterCircle";
import { EnvelopeSimpleIcon, WarningIcon } from "@phosphor-icons/react";
import GiveText from "@shared/Text/GiveText";
import GiveDateTooltip from "@shared/Tooltip/GiveDateTooltip";
import GiveTruncateText from "@shared/Text/GiveTruncateText";
import GiveLink from "@shared/Link/GiveLink";
import useNotificationActions from "../hooks/useNotificationActions";
import FloatingAvatars from "@features/GiveConversation/components/FloatingAvatars";
import { useMarkAsRead } from "@features/GiveConversation/hooks/useManageApi";
import { isEmpty } from "lodash";
import NotificationItemTitleInfo from "./NotificationItemTitleInfo";
import { checkPortals } from "@utils/routing";
const SingleNotificationItem = ({
isRead,
primaryImageURL,
primaryFallbackString,
secondaryImageURL,
secondaryFallbackString,
messageText,
time,
title,
mandatory,
id,
onClick,
}: SingeleThreadType) => {
const { palette } = useAppTheme();
const { isAcquirerPortal } = checkPortals();
const { tab, merchantId } = useGiveNotificationContext();
const isMessageTab = tab === "messages";
const shouldShowDot = !isRead;
const { markAsReadMutation } = useNotificationActions();
const { markAsReadMutation: markMessageAsRead } = useMarkAsRead({
threadId: id as number,
merchantId: merchantId,
selectedTab: "merchant",
isMentioned: false,
});
const handleMarkAsRead = () => {
if (id && tab === "notifications") {
markAsReadMutation.mutate([id]);
} else {
markMessageAsRead.mutate();
}
};
const showTitleInfo =
(tab === "merchant" || tab === "provider" || tab === "team") &&
isAcquirerPortal;
//TODO replace when we have data from BE
const mockedName = "Jhone Doe";
return (
<Box
onClick={onClick}
sx={{
transition: "background-color 0.3s ease",
backgroundColor: "transparent",
borderBottom: `1px solid ${palette.surface?.tertiary}`,
cursor: "pointer",
"&:hover": {
backgroundColor: palette.surface?.["secondary-transparent"],
},
"&:hover .mark-as-read": {
opacity: 1,
visibility: "visible",
},
}}
data-testid="give-notification-item"
>
<Stack
direction="row"
alignItems="flex-start"
gap="12px"
pb="16px"
pl={"8px"}
pr="20px"
pt="16px"
>
{/* Icon section */}
<Stack direction="row" alignItems="center" gap="8px">
{shouldShowDot ? (
<CounterCircle
sx={{ padding: 0 }}
size={6}
displayEmptyDot
variant={mandatory ? "tagged" : isMessageTab ? "reply" : "unread"}
/>
) : (
<Box height={6} width={6} />
)}
{isMessageTab ? (
<FloatingAvatars
primaryImageURL={primaryImageURL}
primaryFallbackString={primaryFallbackString}
secondaryImageURL={secondaryImageURL}
secondaryFallbackString={secondaryFallbackString}
/>
) : (
<AvatarContainer
bgType={mandatory && !isRead ? "required" : "normal"}
>
{mandatory ? (
<WarningIcon
fill={
isRead
? palette.icon?.["icon-secondary"]
: palette.primitive?.warning?.[50]
}
size={24}
/>
) : (
<EnvelopeSimpleIcon
fill={palette.icon?.["icon-secondary"]}
size={24}
/>
)}
</AvatarContainer>
)}
</Stack>
{/* Text section */}
<Box>
{showTitleInfo && <NotificationItemTitleInfo name={mockedName} />}
<GiveText fontSize="14px" fontWeight={500}>
{title}
</GiveText>
<GiveTruncateText
lineClamp={4}
useParse
fontSize="14px"
fontWeight={400}
mt="8px"
>
{!isEmpty(messageText) ? messageText : "Document attached"}
</GiveTruncateText>
<Stack mt="8px" direction="row" gap="8px" alignItems="center">
<GiveDateTooltip>
<GiveText color="secondary" fontSize="12px" fontWeight={400}>
{time}
</GiveText>
</GiveDateTooltip>
{!isRead && (
<GiveLink
component="button"
className="mark-as-read"
fontSize="12px"
color={palette.primitive?.blue[100]}
fontWeight={400}
sx={{
opacity: {
xs: 1,
sm: 0,
},
visibility: {
xs: "visible",
sm: "hidden",
},
transition: "opacity 0.2s ease",
}}
onClick={(event) => {
event.stopPropagation();
handleMarkAsRead();
}}
>
Mark as read
</GiveLink>
)}
</Stack>
</Box>
</Stack>
</Box>
);
};
// Avatar container with background styling
const AvatarContainer = ({
children,
bgType = "normal",
}: {
children: React.ReactNode;
bgType?: "normal" | "required";
}) => {
const { palette } = useAppTheme();
const backgroundColors = {
normal: palette.primitive?.transparent["darken-5"],
required: palette.primitive?.warning[10],
};
return (
<Box
width="40px"
height="40px"
borderRadius="50%"
display="flex"
alignItems="center"
justifyContent="center"
bgcolor={backgroundColors[bgType]}
>
{children}
</Box>
);
};
export default SingleNotificationItem;
|