Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ Resend message #2174

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 94 additions & 64 deletions components/MessagesTable.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* globals DOMPurify, marked: false */
/* globals DOMPurify, marked, promptError, promptMessage: false */

import { useState, useEffect } from 'react'
import upperFirst from 'lodash/upperFirst'
import Table from './Table'
import { formatTimestamp } from '../lib/utils'
import SpinnerButton from './SpinnerButton'
import api from '../lib/api-client'
import useUser from '../hooks/useUser'
import { isSuperUser } from '../lib/auth'

const MessageContent = ({ content = '' }) => {
const [sanitizedHtml, setSanitizedHtml] = useState(null)
Expand All @@ -21,82 +25,108 @@ const MessageContent = ({ content = '' }) => {
)
}

const MessageRow = ({ message }) => (
<tr>
<td>
<span
className={`status ${message.status === 'delivered' ? 'delivered' : 'not-delivered'}`}
>
{upperFirst(message.status)}
</span>
</td>

<td>
<div className="clearfix">
<div className="email-to pull-left mr-3">
To:{' '}
<a
href={`/profile?email=${encodeURIComponent(message.content?.to)}`}
className="profile-link"
target="_blank"
rel="noreferrer"
const MessageRow = ({ message }) => {
const [isLoading, setIsLoading] = useState(false)
const { user } = useUser()
const showResendButton = isSuperUser(user) && ['bounce', 'dropped'].includes(message.status)
const resendEmail = async () => {
setIsLoading(true)
try {
await api.post('/messages/resend', { id: message.id })
promptMessage('Email is sent', { scrollToTop: false })
} catch (error) {
promptError(error.message, { scrollToTop: false })
}
setIsLoading(false)
}
return (
<tr>
<td>
<span
className={`status ${message.status === 'delivered' ? 'delivered' : 'not-delivered'}`}
>
{upperFirst(message.status)}
</span>
{showResendButton && (
<SpinnerButton
type="primary"
size="xs"
onClick={resendEmail}
disabled={isLoading}
loading={isLoading}
>
{message.content?.to}
</a>
</div>
{message.referrer && (
<div className="email-parent pull-left mr-4">
Parent:{' '}
{isLoading ? '' : 'Resend'}
</SpinnerButton>
)}
</td>

<td>
<div className="clearfix">
<div className="email-to pull-left mr-3">
To:{' '}
<a
href={`/group/edit?id=${encodeURIComponent(message.referrer)}`}
href={`/profile?email=${encodeURIComponent(message.content?.to)}`}
className="profile-link"
target="_blank"
rel="noreferrer"
>
{message.referrer}
{message.content?.to}
</a>
</div>
)}
<div className="email-sent pull-right">
{message.timestamp || message.cdate ? (
<>
Sent: <span>{formatTimestamp(message.timestamp * 1000 || message.cdate)}</span>
</>
) : (
'Not Sent'
{message.referrer && (
<div className="email-parent pull-left mr-4">
Parent:{' '}
<a
href={`/group/edit?id=${encodeURIComponent(message.referrer)}`}
className="profile-link"
target="_blank"
rel="noreferrer"
>
{message.referrer}
</a>
</div>
)}
<div className="email-sent pull-right">
{message.timestamp || message.cdate ? (
<>
Sent: <span>{formatTimestamp(message.timestamp * 1000 || message.cdate)}</span>
</>
) : (
'Not Sent'
)}
</div>
</div>
</div>

<div className="email-title">
<strong>{message.content?.subject}</strong>
</div>

<div
role="button"
tabIndex="0"
className={`email-content collapsed ${
message.content?.text?.startsWith('<p>') ? 'markdown-rendered' : ''
}`}
onClick={(e) => e.currentTarget.classList.toggle('collapsed')}
>
<MessageContent content={message.content?.text} />
<div className="gradient-overlay" />
</div>
<div className="email-title">
<strong>{message.content?.subject}</strong>
</div>

<div>
<a
href={`${process.env.API_V2_URL}/messages?id=${message.id}`}
className="log-link"
target="_blank"
rel="noreferrer"
<div
role="button"
tabIndex="0"
className={`email-content collapsed ${
message.content?.text?.startsWith('<p>') ? 'markdown-rendered' : ''
}`}
onClick={(e) => e.currentTarget.classList.toggle('collapsed')}
>
Message Log
</a>
</div>
</td>
</tr>
)
<MessageContent content={message.content?.text} />
<div className="gradient-overlay" />
</div>

<div>
<a
href={`${process.env.API_V2_URL}/messages?id=${message.id}`}
className="log-link"
target="_blank"
rel="noreferrer"
>
Message Log
</a>
</div>
</td>
</tr>
)
}

const MessagesTable = ({ messages }) => {
if (!messages) return null
Expand Down