Skip to content

Commit

Permalink
feat(imap): added activity log
Browse files Browse the repository at this point in the history
  • Loading branch information
batamar committed Mar 29, 2023
1 parent 8c07574 commit 75ba423
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/plugin-imap-api/src/configs.ts
Expand Up @@ -7,8 +7,9 @@ import { initBroker } from './messageBroker';
import { generateModels } from './connectionResolver';
import { getSubdomain } from '@erxes/api-utils/src/core';
import listen, { findAttachmentParts, generateImap, toUpper } from './utils';
import { debugError, debugInfo } from '@erxes/api-utils/src/debuggers';
import { debugError } from '@erxes/api-utils/src/debuggers';
import { routeErrorHandling } from '@erxes/api-utils/src/requests';
import logs from './logUtils';

export let mainDb;
export let graphqlPubsub;
Expand All @@ -31,7 +32,8 @@ export default {
kind: 'imap',
label: 'IMap'
}
]
],
logs: { providesActivityLog: true, consumers: logs }
},
apolloServerContext: async (context, req) => {
const subdomain = getSubdomain(req);
Expand Down
45 changes: 45 additions & 0 deletions packages/plugin-imap-api/src/logUtils.ts
@@ -0,0 +1,45 @@
import { generateModels } from './connectionResolver';
import { sendContactsMessage } from './messageBroker';

export default {
collectItems: async ({ subdomain, data }) => {
const { contentId } = data;

const customer = await sendContactsMessage({
subdomain,
action: 'customers.findOne',
isRPC: true,
data: {
_id: contentId
}
});

if (!customer) {
return {
status: 'success',
data: []
};
}

const models = await generateModels(subdomain);
const messages = await models.Messages.find({
'to.address': customer.primaryEmail
});

const results: any = [];

for (const message of messages) {
results.push({
_id: message._id,
contentType: 'imap:customer',
createdAt: message.createdAt,
contentTypeDetail: message
});
}

return {
status: 'success',
data: results
};
}
};
35 changes: 35 additions & 0 deletions packages/plugin-imap-ui/src/components/ActivityLog.tsx
@@ -0,0 +1,35 @@
import React from 'react';

type Props = {
contentType: string;
activity: any;
currentUser: any;
};

class ActivityItem extends React.Component<Props> {
render() {
const { activity } = this.props;
const { contentTypeDetail } = activity;
const { body, subject } = contentTypeDetail;

return (
<div>
<span>
<strong>Sent an email</strong>
</span>

<p>
<span>Subject:</span>
<div>{subject}</div>
</p>

<p>
<span>Content:</span>
<div dangerouslySetInnerHTML={{ __html: body }} />
</p>
</div>
);
}
}

export default ActivityItem;
4 changes: 3 additions & 1 deletion packages/plugin-imap-ui/src/configs.js
Expand Up @@ -7,6 +7,7 @@ module.exports = {
"./inboxIntegrationSettings": "./src/components/IntegrationSettings.tsx",
"./inboxIntegrationForm": "./src/components/IntegrationForm.tsx",
"./inboxConversationDetail": "./src/components/ConversationDetail.tsx",
'./activityLog': './src/components/ActivityLog.tsx',
},
routes: {
url: 'http://localhost:3014/remoteEntry.js',
Expand All @@ -28,5 +29,6 @@ module.exports = {
category:
'All integrations, For support teams, Marketing automation, Email marketing',
components: ['inboxConversationDetail'],
}]
}],
activityLog: './activityLog',
};
2 changes: 1 addition & 1 deletion scripts/pluginsMap.js

Large diffs are not rendered by default.

0 comments on commit 75ba423

Please sign in to comment.