// ** React Imports import { Fragment, useState, ReactNode } from 'react' // ** MUI Imports import List from '@mui/material/List' import Avatar from '@mui/material/Avatar' import Divider from '@mui/material/Divider' import ListItem from '@mui/material/ListItem' import { styled } from '@mui/material/styles' import IconButton from '@mui/material/IconButton' import Box, { BoxProps } from '@mui/material/Box' import Typography from '@mui/material/Typography' import ListItemIcon from '@mui/material/ListItemIcon' // ** Icon Imports import Icon from 'src/@core/components/icon' // ** Third Party Imports import PerfectScrollbar from 'react-perfect-scrollbar' // ** Hooks import { useSettings } from 'src/@core/hooks/useSettings' // ** Custom Components Imports import Sidebar from 'src/@core/components/sidebar' import CustomChip from 'src/@core/components/mui/chip' import OptionsMenu from 'src/@core/components/option-menu' // ** Types import { ThemeColor } from 'src/@core/layouts/types' import { OptionType } from 'src/@core/components/option-menu/types' import { MailType, MailLabelType, MailDetailsType, MailFoldersArrType, MailAttachmentType } from 'src/types/apps/emailTypes' import Image from 'next/image' const HiddenReplyBack = styled(Box)(({ theme }) => ({ height: 11, width: '90%', opacity: 0.5, borderWidth: 1, borderBottom: 0, display: 'block', marginLeft: 'auto', marginRight: 'auto', borderStyle: 'solid', borderColor: theme.palette.divider, borderTopLeftRadius: theme.shape.borderRadius, borderTopRightRadius: theme.shape.borderRadius, backgroundColor: theme.palette.background.paper })) const HiddenReplyFront = styled(Box)(({ theme }) => ({ height: 12, width: '95%', opacity: 0.7, borderWidth: 1, borderBottom: 0, display: 'block', marginLeft: 'auto', marginRight: 'auto', borderStyle: 'solid', borderColor: theme.palette.divider, borderTopLeftRadius: theme.shape.borderRadius, borderTopRightRadius: theme.shape.borderRadius, backgroundColor: theme.palette.background.paper })) const MailDetails = (props: MailDetailsType) => { // ** Props const { mail, hidden, folders, dispatch, direction, updateMail, foldersObj, labelColors, routeParams, paginateMail, handleStarMail, mailDetailsOpen, handleLabelUpdate, handleFolderUpdate, setMailDetailsOpen } = props // ** State const [showReplies, setShowReplies] = useState(false) // ** Hook const { settings } = useSettings() const handleMoveToTrash = () => { dispatch(updateMail({ emailIds: [mail.id], dataToUpdate: { folder: 'trash' } })) setMailDetailsOpen(false) } const handleReadMail = () => { dispatch(updateMail({ emailIds: [mail.id], dataToUpdate: { isRead: false } })) setMailDetailsOpen(false) } const handleLabelsMenu = () => { const array: OptionType[] = [] Object.entries(labelColors).map(([key, value]: string[]) => { array.push({ text: {key}, icon: ( ), menuItemProps: { onClick: () => { handleLabelUpdate([mail.id], key as MailLabelType) setMailDetailsOpen(false) } } }) }) return array } const handleFoldersMenu = () => { const array: OptionType[] = [] if (routeParams && routeParams.folder && !routeParams.label && foldersObj[routeParams.folder]) { foldersObj[routeParams.folder].map((folder: MailFoldersArrType) => { array.length = 0 array.push({ icon: folder.icon, text: {folder.name}, menuItemProps: { onClick: () => { handleFolderUpdate(mail.id, folder.name) setMailDetailsOpen(false) } } }) }) } else if (routeParams && routeParams.label) { folders.map((folder: MailFoldersArrType) => { array.length = 0 array.push({ icon: folder.icon, text: {folder.name}, menuItemProps: { onClick: () => { handleFolderUpdate(mail.id, folder.name) setMailDetailsOpen(false) } } }) }) } else { foldersObj['inbox'].map((folder: MailFoldersArrType) => { array.length = 0 array.push({ icon: folder.icon, text: {folder.name}, menuItemProps: { onClick: () => { handleFolderUpdate(mail.id, folder.name) setMailDetailsOpen(false) } } }) }) } return array } const prevMailIcon = direction === 'rtl' ? 'mdi:chevron-right' : 'mdi:chevron-left' const nextMailIcon = direction === 'rtl' ? 'mdi:chevron-left' : 'mdi:chevron-right' const goBackIcon = prevMailIcon const ScrollWrapper = ({ children }: { children: ReactNode }) => { if (hidden) { return {children} } else { return {children} } } return ( { setMailDetailsOpen(false) setShowReplies(false) }} > {mail ? ( `1px solid ${theme.palette.divider}` }} > { setMailDetailsOpen(false) setShowReplies(false) }} > {mail.subject} {mail.labels && mail.labels.length ? mail.labels.map((label: MailLabelType) => { return ( ) }) : null} dispatch(paginateMail({ dir: 'previous', emailId: mail.id }))} > dispatch(paginateMail({ dir: 'next', emailId: mail.id }))} > theme.spacing(3, 2, 3, 3), borderBottom: theme => `1px solid ${theme.palette.divider}` }} > {routeParams && routeParams.folder !== 'trash' ? ( ) : null} } /> } />
handleStarMail(e, mail.id, !mail.isStarred)} sx={{ mr: 1, ...(mail.isStarred ? { color: 'warning.main' } : {}) }} > {mail.replies.length ? ( (showReplies ? setShowReplies(false) : setShowReplies(true))}> {showReplies ? ( ) : ( )} ) : null}
{mail.replies.length && !showReplies ? ( setShowReplies(true)} sx={{ mt: 1, mb: 5, color: 'text.secondary', cursor: 'pointer' }} > {mail.replies.length} Earlier Messages ) : null} {showReplies ? mail.replies.map((reply: MailType, index: number) => { return ( `1px solid ${theme.palette.divider}` }} > {reply.from.name} {reply.from.email} {new Date(reply.time).toDateString()}{' '} {new Date(reply.time).toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: true })} {mail.attachments.length ? ( ) : null} {reply.attachments.length ? ( Attachments {reply.attachments.map((item: MailAttachmentType) => { return ( {item.fileName} {item.fileName} ) })} ) : null} ) }) : null} {mail.replies.length && !showReplies ? ( setShowReplies(true)} /> setShowReplies(true)} /> ) : null} `1px solid ${theme.palette.divider}` }} > {mail.from.name} {mail.from.email} {new Date(mail.time).toDateString()}{' '} {new Date(mail.time).toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: true })} {mail.attachments.length ? ( ) : null} }, { text: 'Forward', menuItemProps: { sx: { '& svg': { mr: 2 } } }, icon: } ]} /> {mail.attachments.length ? ( Attachments {mail.attachments.map((item: MailAttachmentType) => { return ( {item.fileName} {item.fileName} ) })} ) : null} Click here to{' '} Reply {' '} or{' '} Forward
) : null}
) } export default MailDetails