Skip to content

Commit

Permalink
Feature/email logs page (#439)
Browse files Browse the repository at this point in the history
* Add new page for email logs, add filters and columns

Signed-off-by: Tomás Castillo <[email protected]>

* Add template and dates filters

Signed-off-by: Tomás Castillo <[email protected]>

* Fix template and date filters

Signed-off-by: Tomás Castillo <[email protected]>

* Change layout, adjust ddl and default order

Signed-off-by: Tomás Castillo <[email protected]>

* Adjust params for template search, change menu text, initial order dir on reducer

Signed-off-by: Tomás Castillo <[email protected]>

* Remove console log

Signed-off-by: Tomás Castillo <[email protected]>

---------

Signed-off-by: Tomás Castillo <[email protected]>
  • Loading branch information
tomrndom authored Jul 9, 2024
1 parent 12b60b3 commit 4fe8f82
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 148 deletions.
54 changes: 47 additions & 7 deletions src/actions/email-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import {
fetchErrorHandler,
escapeFilterValue
} from 'openstack-uicore-foundation/lib/utils/actions';
import {getAccessTokenSafely} from '../utils/methods';
import {checkOrFilter,getAccessTokenSafely} from '../utils/methods';
import { saveMarketingSetting } from "./marketing-actions";
import URI from "urijs";


export const REQUEST_TEMPLATES = 'REQUEST_TEMPLATES';
Expand Down Expand Up @@ -234,10 +235,19 @@ const normalizeEntity = (entity) => {
export const queryTemplates = _.debounce(async (input, callback) => {

const accessToken = await getAccessTokenSafely();


let endpoint = URI(`${window.EMAIL_API_BASE_URL}/api/v1/mail-templates`);

input = escapeFilterValue(input);

fetch(`${window.EMAIL_API_BASE_URL}/api/v1/mail-templates?identifier__contains=${input}&access_token=${accessToken}`)
endpoint.addQuery('access_token', accessToken);
endpoint.addQuery('order','-id')

if(input) {
endpoint.addQuery('identifier__contains', input);
}

fetch(endpoint)
.then(fetchResponseHandler)
.then((json) => {
const options = [...json.data];
Expand Down Expand Up @@ -283,18 +293,17 @@ export const getSentEmailsByTemplatesAndEmail = (templates = [], toEmail , page
);
};

export const getSentEmails = (term = null, page = 1, perPage = 10, order = 'id', orderDir = 1 ) => async (dispatch, getState) => {
export const getSentEmails = (term = null, page = 1, perPage = 10, order = 'id', orderDir = 1, filters = {} ) => async (dispatch, getState) => {

const accessToken = await getAccessTokenSafely();

dispatch(startLoading());

const params = {
let params = {
page : page,
per_page : perPage,
access_token : accessToken,
expand: 'template',
is_sent: 1,
};

if (term) {
Expand All @@ -307,12 +316,18 @@ export const getSentEmails = (term = null, page = 1, perPage = 10, order = 'id',
params['order']= `${orderDirSign}${order}`;
}

const filter = parseFilters(filters);

if (Object.keys(filter).length > 0) {
params = {...params, ...filter};
}

return getRequest(
createAction(REQUEST_EMAILS),
createAction(RECEIVE_EMAILS),
`${window.EMAIL_API_BASE_URL}/api/v1/mails`,
authErrorHandler,
{order, orderDir, term}
{order, orderDir, term, filters}
)(params)(dispatch).then(() => {
dispatch(stopLoading());
}
Expand Down Expand Up @@ -440,3 +455,28 @@ export const customErrorHandler = (err, res) => (dispatch, state) => {
dispatch(authErrorHandler(err, res));
}
}

const parseFilters = (filters) => {
let filter = {};

if(filters.is_sent_filter){
if(filters.is_sent_filter === '1')
filter = {...filter, is_sent: 1};
if(filters.is_sent_filter === '0')
filter = {...filter, is_sent: 0}
}

if (filters.sent_date_filter && filters.sent_date_filter.some(e => e !== null)) {
if(filters.sent_date_filter.every(e => e !== null )) {
filter = {...filter, from_sent_date: filters.sent_date_filter[0], to_sent_date: filters.sent_date_filter[1]};
} else {
filter = {...filter, [`${filters.sent_date_filter[0] !== null ? 'from_sent_date' : 'to_sent_date'}`]: filters.sent_date_filter[0] !== null ? filters.sent_date_filter[0] : filters.sent_date_filter[1]}
}
}

if (filters.template_filter) {
filter = {...filter, template__identifier__in: filters.template_filter}
}

return checkOrFilter(filters, filter);
};
4 changes: 2 additions & 2 deletions src/components/inputs/email-template-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export default class EmailTemplateInput extends React.Component {
}

getTemplates (input, callback) {
const {ownerId } = this.props;
const {ownerId, defaultOptions} = this.props;

if (!input) {
if (!input && !defaultOptions) {
return Promise.resolve({ options: [] });
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/nav-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class NavMenu extends React.Component {
{name: 'emails', iconClass: 'fa-envelope-o', accessRoute: 'emails',
childs: [
{name:'email_templates', linkUrl:`emails/templates`},
{name:'sent_email', linkUrl:`emails/sent`},
{name:'email_logs', linkUrl:`emails/log`},
]
},
{name: 'admin_access', iconClass: 'fa-arrow-circle-o-right', linkUrl: 'admin-access', accessRoute: 'admin-access'},
Expand Down
20 changes: 20 additions & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
"emails": "Emails",
"email_templates": "Templates",
"sent_email": "Sent Emails",
"email_logs": "Logs",
"summitdocs": "Event Docs",
"email_flow_events": "Email Events",
"email_flow_overrides": "Overrides",
Expand Down Expand Up @@ -2365,6 +2366,25 @@
"see_version": "see version at Github"
}
},
"email_logs": {
"email_logs": "Email Logs",
"email_list": "Email List",
"apply_filters": "Apply Filters",
"email_templates": "Email Templates",
"subject": "Subject",
"from_email": "From Email",
"to_email": "To Email",
"sent_date": "Sent Date",
"last_error": "Last Error",
"payload": "Payload",
"select_fields":"Show Columns",
"placeholders": {
"select_fields": "Select data to display",
"template": "Filter by Template",
"sent_date_from": "Filter Sent Date from",
"sent_date_to": "Filter Sent Date to"
}
},
"summitdoc": {
"summitdocs": "Event Docs",
"summitdoc": "Event Doc",
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/email-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Breadcrumb } from 'react-breadcrumbs';
import Restrict from '../routes/restrict';
import EmailTemplateListPage from "../pages/emails/email-template-list-page";
import EditEmailTemplatePage from "../pages/emails/edit-email-template-page";
import SentEmailListPage from "../pages/emails/sent-email-list-page";
import EmailLogListPage from '../pages/emails/email-log-list-page';

class EmailLayout extends React.Component {

Expand All @@ -34,7 +34,7 @@ class EmailLayout extends React.Component {
<Route exact strict path={`${match.url}/templates`} component={EmailTemplateListPage}/>
<Route strict exact path={`${match.url}/templates/new`} component={EditEmailTemplatePage}/>
<Route path={`${match.url}/templates/:template_id`} component={EditEmailTemplatePage}/>
<Route exact strict path={`${match.url}/sent`} component={SentEmailListPage}/>
<Route exact strict path={`${match.url}/log`} component={EmailLogListPage}/>
<Redirect to={`/app/emails/templates`} />
</Switch>
</div>
Expand Down
Loading

0 comments on commit 4fe8f82

Please sign in to comment.