diff --git a/src/components/bulk-email-tool/bulk-email-task-manager/BulkEmailContentHistory.jsx b/src/components/bulk-email-tool/bulk-email-task-manager/BulkEmailContentHistory.jsx
index 00a2922..6a70151 100644
--- a/src/components/bulk-email-tool/bulk-email-task-manager/BulkEmailContentHistory.jsx
+++ b/src/components/bulk-email-tool/bulk-email-task-manager/BulkEmailContentHistory.jsx
@@ -1,41 +1,241 @@
-import React, { useState, useEffect } from 'react';
+import React, { useState } from 'react';
+import PropTypes from 'prop-types';
import { useParams } from 'react-router-dom';
+import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
-import { FormattedMessage } from '@edx/frontend-platform/i18n';
+import {
+ Alert, Button, DataTable, Modal,
+} from '@edx/paragon';
+import messages from './messages';
import { getSentEmailHistory } from './api';
-export default function BulkEmailContentHistory() {
+export function BulkEmailContentHistory({ intl }) {
const { courseId } = useParams();
- const [emailHistoryData, setEmailHistoryData] = useState(); // eslint-disable-line no-unused-vars
+ const [emailHistoryData, setEmailHistoryData] = useState();
+ const [errorRetrievingData, setErrorRetrievingData] = useState(false);
+ const [showHistoricalEmailContentTable, setShowHistoricalEmailContentTable] = useState(false);
+ const [isMessageModalOpen, setIsMessageModalOpen] = useState(false);
+ const [messageContent, setMessageContent] = useState();
- useEffect(() => {
- async function fetchSentEmailHistoryData() {
- const data = await getSentEmailHistory(courseId);
+ /**
+ * Async function that makes a REST API call to retrieve historical email message data sent by the bulk course email
+ * tool from edx-platform.
+ */
+ async function fetchSentEmailHistoryData() {
+ let data = null;
+ try {
+ data = await getSentEmailHistory(courseId);
+ } catch (error) {
+ setErrorRetrievingData(true);
+ }
+
+ if (data) {
const { emails } = data;
setEmailHistoryData(emails);
+ setShowHistoricalEmailContentTable(true);
}
- fetchSentEmailHistoryData();
- }, []);
+ }
+
+ /**
+ * This function is responsible for setting the current `messageContent` state data. This will be the contents of a
+ * previously sent email message from the bulk course email tool. This also toggles a modal to be visible to display
+ * the message contents to the end user.
+ */
+ const onViewMessageClick = (tableData) => {
+ setMessageContent(tableData);
+ setIsMessageModalOpen(true);
+ };
+
+ /**
+ * Render function for the email content history table. If an error occurs while attempting to fetch data from
+ * edx-platform we will render this error instead of the table.
+ */
+ const renderError = () => (
+
+ );
+
+ /**
+ * Render function for the email content history table. If there is no data to display in our table we will render
+ * this informative message instead.
+ */
+ const renderEmpty = () => (
+
+
+
+ {intl.formatMessage(messages.noEmailData)}
+
+
+
+ );
+
+ /**
+ * Renders a modal that will display the contents of a single historical email message sent via the bulk course email
+ * tool to a user.
+ */
+ const renderMessageModal = () => (
+
+ )}
+ onClose={() => setIsMessageModalOpen(false)}
+ />
+
+ );
+
+ /**
+ * Render function for the email content history table. This function is responsible for displaying data inside of
+ * the table when the `Show Sent Email History` button is pressed on the page.
+ */
+ const renderTable = () => {
+ // Do a little data manipulation to make it easier to display what we want in the table. Pull the email subject out
+ // of the email data. Transforms the `sent_to` array to a string for easier display in our table.
+ const tableData = emailHistoryData.map((item) => ({
+ ...item,
+ subject: item.email.subject,
+ sent_to: item.sent_to.join(', '),
+ }));
+
+ return (
+
+ );
+ };
+
+ /**
+ * Today there can be three states which the renderTableData function will handle:
+ * 1. There was an error retrieving data from edx-platform and we can't display anything (for now).
+ * 2. There is no email history for this course-run and we have nothing to display to the end user.
+ * 3. We were able to receive historical email content and it will be presented in a table.
+ */
+ const renderTableData = () => {
+ if (errorRetrievingData) {
+ return renderError();
+ }
+
+ if (!emailHistoryData.length) {
+ return renderEmpty();
+ }
+
+ return renderTable();
+ };
return (