diff --git a/src/components/EmailHeader/EmailHeader.js b/src/components/EmailHeader/EmailHeader.js index b48d59f..8482d1c 100644 --- a/src/components/EmailHeader/EmailHeader.js +++ b/src/components/EmailHeader/EmailHeader.js @@ -1,18 +1,26 @@ import React from "react"; import PropTypes from "prop-types"; -import { Card, CardHeader, makeStyles, useTheme } from "@material-ui/core"; +import { Paper, Grid, makeStyles, useTheme, Typography } from "@material-ui/core"; +import RelativeTime from "react-relative-time"; import UserAvatar from "../UserAvatar/"; -export default function EmailHeader({name, date, email}){ +export default function EmailHeader({ datetime, from_name, from_email, to, cc }){ const theme = useTheme(); const useStyles = makeStyles({ - "verticalPadding": { - paddingTop: theme.spacing(1), - paddingBottom: theme.spacing(1), + "paperWrapper": { + padding: theme.spacing(1) }, - "removeCardHeaderPadding": { - padding: "0" + "removeNegativeMargin": { + margin: 0 + }, + "secondaryInformation": { + backgroundColor: theme.palette.grey[100], + marginTop: theme.spacing(1), + marginLeft: -theme.spacing(1), + marginRight: -theme.spacing(1), + marginBottom: -theme.spacing(1), + padding: theme.spacing(1) } }); const classes = useStyles(); @@ -30,43 +38,89 @@ export default function EmailHeader({name, date, email}){ * return "" * @returns {string} */ - function buildTitle(name, email){ - let title = ""; + function buildEmailNameString(name, email){ + let emailNameString = ""; const isNotEmpty = (value) => { return value === "" || value === null ? false : true; }; if (isNotEmpty(name)){ - title += `${name}`; + emailNameString += `${name}`; }; if (isNotEmpty(email)){ - title += ` <${email}>` + emailNameString += ` <${email}>` + } + return emailNameString; + }; + + /** + * Returns a string of emails with names. + * @param {array} Array of objects containing names and emails. + * @returns {string} String of email with names. + */ + function buildRecipientString(recipients){ + if (recipients.length === 0){ + return "Tits"; } - return title; + + let recipientString = ""; + recipients.map( (recipient, index) => { + recipientString += buildEmailNameString(recipient.name, recipient.email) + index < recipients.length - 1 ? recipientString += ", " : recipientString += "" + }) + return recipientString; }; + // const toString = build + return( - - } - title={buildTitle(name, email)} - subheader={Date(date)} - classes={{root: classes.removeCardHeaderPadding}} - /> - + + + + + + + + {buildEmailNameString(from_name, from_email)} + + + + + + + { (to.length === 0 && cc.length === 0) ? null : + + + {to.length === 0 ? null : <>To: {buildRecipientString(to)}} + + + {cc.length === 0 ? null : <>Cc: {buildRecipientString(cc)} } + + + } + ); }; EmailHeader.propTypes = { - /** Name of the user. */ - "name": PropTypes.string, - /** Date of the message. */ - "date": PropTypes.string, - /** Email address of the user. */ - "email": PropTypes.string + /** Name of message sender. */ + "from_name": PropTypes.string, + /** Date the message was sent in ISO 8601 format. */ + "datetime": PropTypes.string, + /** Email address of message sender. */ + "from_email": PropTypes.string, + /** Array of people the message was sent to */ + "to": PropTypes.array, + /** Array of people the message was cc'd to */ + "cc": PropTypes.array }; EmailHeader.defaultProps = { - "name": "", - "date": "", - "email": "" + "from_name": "Name Unavailable", + "datetime": new Date(1970, 1, 1, 0, 0, 0, 0), + "from_email": "Email Unavailable", + "to": [], + "cc": [] }; \ No newline at end of file