From b1180428fc9b41e21c7da88ae61b3b5c0c704384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Bal=C3=A7a?= Date: Sat, 10 Dec 2022 02:08:22 +0000 Subject: [PATCH 1/4] Add integration done email to integrationProcessor --- backend/.env.dist.local | 1 + backend/config/custom-environment-variables.json | 1 + backend/src/config/configTypes.ts | 1 + backend/src/config/index.ts | 1 + ...U1670422647__addEmailSentAtToIntegrations.sql | 1 + ...V1670422647__addEmailSentAtToIntegrations.sql | 1 + backend/src/database/models/integration.ts | 3 +++ .../repositories/integrationRepository.ts | 2 ++ backend/src/i18n/en.ts | 13 +++++++++++++ .../services/integrationProcessor.ts | 16 ++++++++++++++++ backend/src/services/emailSender.ts | 1 + 11 files changed, 41 insertions(+) create mode 100644 backend/src/database/migrations/U1670422647__addEmailSentAtToIntegrations.sql create mode 100644 backend/src/database/migrations/V1670422647__addEmailSentAtToIntegrations.sql diff --git a/backend/.env.dist.local b/backend/.env.dist.local index c80a89d684..9423a41899 100755 --- a/backend/.env.dist.local +++ b/backend/.env.dist.local @@ -82,6 +82,7 @@ CROWD_SENDGRID_TEMPLATE_EMAIL_ADDRESS_VERIFICATION= CROWD_SENDGRID_TEMPLATE_INVITATION= CROWD_SENDGRID_TEMPLATE_PASSWORD_RESET= CROWD_SENDGRID_TEMPLATE_WEEKLY_ANALYTICS= +CROWD_SENDGRID_TEMPLATE_INTEGRATION_DONE= CROWD_SENDGRID_WEEKLY_ANALYTICS_UNSUBSCRIBE_GROUP_ID= # Stripe settings diff --git a/backend/config/custom-environment-variables.json b/backend/config/custom-environment-variables.json index da025fc13a..1aabade754 100644 --- a/backend/config/custom-environment-variables.json +++ b/backend/config/custom-environment-variables.json @@ -89,6 +89,7 @@ "templateInvitation": "CROWD_SENDGRID_TEMPLATE_INVITATION", "templatePasswordReset": "CROWD_SENDGRID_TEMPLATE_PASSWORD_RESET", "templateWeeklyAnalytics": "CROWD_SENDGRID_TEMPLATE_WEEKLY_ANALYTICS", + "templateIntegrationDone": "CROWD_SENDGRID_TEMPLATE_INTEGRATION_DONE", "weeklyAnalyticsUnsubscribeGroupId": "CROWD_SENDGRID_WEEKLY_ANALYTICS_UNSUBSCRIBE_GROUP_ID" }, "plans": { diff --git a/backend/src/config/configTypes.ts b/backend/src/config/configTypes.ts index eb567ba500..fdcf31dc29 100644 --- a/backend/src/config/configTypes.ts +++ b/backend/src/config/configTypes.ts @@ -150,6 +150,7 @@ export interface SendgridConfiguration { templateInvitation: string templatePasswordReset: string templateWeeklyAnalytics: string + templateIntegrationDone: string weeklyAnalyticsUnsubscribeGroupId: string } diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 86d03fab29..f6696a3702 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -192,6 +192,7 @@ export const SENDGRID_CONFIG: SendgridConfiguration = KUBE_MODE templateInvitation: process.env.SENDGRID_TEMPLATE_INVITATION, templatePasswordReset: process.env.SENDGRID_TEMPLATE_PASSWORD_RESET, templateWeeklyAnalytics: process.env.SENDGRID_TEMPLATE_WEEKLY_ANALYTICS, + templateIntegrationDone: process.env.SENDGRID_TEMPLATE_INTEGRATION_DONE } export const NETLIFY_CONFIG: NetlifyConfiguration = KUBE_MODE diff --git a/backend/src/database/migrations/U1670422647__addEmailSentAtToIntegrations.sql b/backend/src/database/migrations/U1670422647__addEmailSentAtToIntegrations.sql new file mode 100644 index 0000000000..a67112b9b3 --- /dev/null +++ b/backend/src/database/migrations/U1670422647__addEmailSentAtToIntegrations.sql @@ -0,0 +1 @@ +ALTER TABLE public.integrations DROP COLUMN "emailSentAt"; \ No newline at end of file diff --git a/backend/src/database/migrations/V1670422647__addEmailSentAtToIntegrations.sql b/backend/src/database/migrations/V1670422647__addEmailSentAtToIntegrations.sql new file mode 100644 index 0000000000..81f77cbaf6 --- /dev/null +++ b/backend/src/database/migrations/V1670422647__addEmailSentAtToIntegrations.sql @@ -0,0 +1 @@ +ALTER TABLE public.integrations ADD "emailSentAt" TIMESTAMP NULL; \ No newline at end of file diff --git a/backend/src/database/models/integration.ts b/backend/src/database/models/integration.ts index b6a2980ef5..9698a19bac 100644 --- a/backend/src/database/models/integration.ts +++ b/backend/src/database/models/integration.ts @@ -41,6 +41,9 @@ export default (sequelize) => { len: [0, 255], }, }, + emailSentAt: { + type: DataTypes.DATE + } }, { indexes: [ diff --git a/backend/src/database/repositories/integrationRepository.ts b/backend/src/database/repositories/integrationRepository.ts index 00b30e117f..c6f54f0d76 100644 --- a/backend/src/database/repositories/integrationRepository.ts +++ b/backend/src/database/repositories/integrationRepository.ts @@ -31,6 +31,7 @@ class IntegrationRepository { 'settings', 'integrationIdentifier', 'importHash', + 'emailSentAt' ]), tenantId: tenant.id, @@ -78,6 +79,7 @@ class IntegrationRepository { 'settings', 'integrationIdentifier', 'importHash', + 'emailSentAt' ]), updatedById: currentUser.id, diff --git a/backend/src/i18n/en.ts b/backend/src/i18n/en.ts index 9cf380aa6f..4576d14bd1 100644 --- a/backend/src/i18n/en.ts +++ b/backend/src/i18n/en.ts @@ -156,6 +156,19 @@ const en = { unique: {}, }, }, + integration: { + name: { + github: 'GitHub', + linkedin: 'LinkedIn', + twitter: 'Twitter', + devto: 'DEV', + stackoverflow: 'Stack Overflow', + reddit: 'Reddit', + discord: 'Discord', + slack: 'Slack', + hackernews: 'Hacker News' + } + } }, } diff --git a/backend/src/serverless/integrations/services/integrationProcessor.ts b/backend/src/serverless/integrations/services/integrationProcessor.ts index f7b0a20e3a..68430e5334 100644 --- a/backend/src/serverless/integrations/services/integrationProcessor.ts +++ b/backend/src/serverless/integrations/services/integrationProcessor.ts @@ -26,6 +26,10 @@ import { TwitterReachIntegrationService } from './integrations/twitterReachInteg import { SlackIntegrationService } from './integrations/slackIntegrationService' import { GithubIntegrationService } from './integrations/githubIntegrationService' import { LoggingBase } from '../../../services/loggingBase' +import { API_CONFIG } from '../../../config' +import EmailSender from '../../../services/emailSender' +import UserRepository from "../../../database/repositories/userRepository" +import {i18n} from "../../../i18n" const MAX_STREAM_RETRIES = 5 @@ -452,10 +456,22 @@ export class IntegrationProcessor extends LoggingBase { logger.error(err, 'Error while processing integration!') setError = req.onboarding } finally { + let emailSentAt + if (!setError && !integration.emailSentAt) { + const tenantUsers = await UserRepository.findAllUsersOfTenant(integration.tenantId) + emailSentAt = new Date() + for (const user of tenantUsers) { + await new EmailSender(EmailSender.TEMPLATES.INTEGRATION_DONE, { + integrationName: i18n('en', `entities.integration.name.${integration.platform}`), + link: API_CONFIG.frontendUrl + }).sendTo(user.email) + } + } await IntegrationRepository.update( integration.id, { status: setError ? 'error' : 'done', + emailSentAt, settings: stepContext.integration.settings, refreshToken: stepContext.integration.refreshToken, token: stepContext.integration.token, diff --git a/backend/src/services/emailSender.ts b/backend/src/services/emailSender.ts index 0f3fce3da7..690080a33e 100644 --- a/backend/src/services/emailSender.ts +++ b/backend/src/services/emailSender.ts @@ -28,6 +28,7 @@ export default class EmailSender extends LoggingBase { INVITATION: SENDGRID_CONFIG.templateInvitation, PASSWORD_RESET: SENDGRID_CONFIG.templatePasswordReset, WEEKLY_ANALYTICS: SENDGRID_CONFIG.templateWeeklyAnalytics, + INTEGRATION_DONE: SENDGRID_CONFIG.templateIntegrationDone } } From 88a8df65416856d995e7cb9fdab853f77088fb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Bal=C3=A7a?= Date: Sat, 10 Dec 2022 02:25:01 +0000 Subject: [PATCH 2/4] Add integration in progress alert bar --- .../src/modules/layout/components/layout.vue | 63 ++++++++++++++++--- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/frontend/src/modules/layout/components/layout.vue b/frontend/src/modules/layout/components/layout.vue index 5f50cdcf06..5c1ef96c23 100644 --- a/frontend/src/modules/layout/components/layout.vue +++ b/frontend/src/modules/layout/components/layout.vue @@ -23,7 +23,7 @@
+ + +
+
+ {{ + integrationsInProgressToString + }} + integration{{ + integrationsInProgress.length > 1 + ? 's are' + : ' is' + }} + getting set up. + This might take a few minutes, we'll send you + an email once it's done. +
+
- Finishing your workspace setup. The data might - take a few minutes until it is completely - loaded. + Finishing your workspace setup. + The data might take a few minutes until it is + completely loaded. @@ -93,7 +122,26 @@ export default { integrationsInProgress: 'integration/inProgress', integrationsWithErrors: 'integration/withErrors' }), - shouldShowIntegrationsAlert() { + integrationsInProgressToString() { + const arr = this.integrationsInProgress.map( + (i) => i.name + ) + if (arr.length === 1) { + return arr[0] + } else if (arr.length === 2) { + return `${arr[0]} and ${arr[1]}` + } else { + return ( + arr.slice(0, arr.length - 1).join(', ') + + ', and ' + + arr.slice(-1) + ) + } + }, + shouldShowIntegrationsInProgressAlert() { + return this.integrationsInProgress.length > 0 + }, + shouldShowIntegrationsErrorAlert() { return ( this.integrationsWithErrors.length > 0 && this.$route.name !== 'integration' @@ -107,14 +155,15 @@ export default { moment().diff( moment(this.currentTenant.createdAt), 'minutes' - ) <= 10 + ) <= 2 ) }, computedBannerWrapperClass() { return { 'pt-16': this.shouldShowSampleDataAlert || - this.shouldShowIntegrationsAlert || + this.shouldShowIntegrationsErrorAlert || + this.shouldShowIntegrationsInProgressAlert || this.shouldShowTenantCreatingAlert } }, From f5ada2966b589db874ed78b302730c71db252aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Bal=C3=A7a?= Date: Sat, 10 Dec 2022 02:25:37 +0000 Subject: [PATCH 3/4] Format backend code --- backend/src/config/index.ts | 2 +- backend/src/database/models/integration.ts | 4 ++-- backend/src/database/repositories/integrationRepository.ts | 4 ++-- backend/src/i18n/en.ts | 6 +++--- .../integrations/services/integrationProcessor.ts | 6 +++--- backend/src/services/emailSender.ts | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index f6696a3702..8db6e2b7f6 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -192,7 +192,7 @@ export const SENDGRID_CONFIG: SendgridConfiguration = KUBE_MODE templateInvitation: process.env.SENDGRID_TEMPLATE_INVITATION, templatePasswordReset: process.env.SENDGRID_TEMPLATE_PASSWORD_RESET, templateWeeklyAnalytics: process.env.SENDGRID_TEMPLATE_WEEKLY_ANALYTICS, - templateIntegrationDone: process.env.SENDGRID_TEMPLATE_INTEGRATION_DONE + templateIntegrationDone: process.env.SENDGRID_TEMPLATE_INTEGRATION_DONE, } export const NETLIFY_CONFIG: NetlifyConfiguration = KUBE_MODE diff --git a/backend/src/database/models/integration.ts b/backend/src/database/models/integration.ts index 9698a19bac..cd0df5babc 100644 --- a/backend/src/database/models/integration.ts +++ b/backend/src/database/models/integration.ts @@ -42,8 +42,8 @@ export default (sequelize) => { }, }, emailSentAt: { - type: DataTypes.DATE - } + type: DataTypes.DATE, + }, }, { indexes: [ diff --git a/backend/src/database/repositories/integrationRepository.ts b/backend/src/database/repositories/integrationRepository.ts index c6f54f0d76..b964a8e302 100644 --- a/backend/src/database/repositories/integrationRepository.ts +++ b/backend/src/database/repositories/integrationRepository.ts @@ -31,7 +31,7 @@ class IntegrationRepository { 'settings', 'integrationIdentifier', 'importHash', - 'emailSentAt' + 'emailSentAt', ]), tenantId: tenant.id, @@ -79,7 +79,7 @@ class IntegrationRepository { 'settings', 'integrationIdentifier', 'importHash', - 'emailSentAt' + 'emailSentAt', ]), updatedById: currentUser.id, diff --git a/backend/src/i18n/en.ts b/backend/src/i18n/en.ts index 4576d14bd1..1d45457990 100644 --- a/backend/src/i18n/en.ts +++ b/backend/src/i18n/en.ts @@ -166,9 +166,9 @@ const en = { reddit: 'Reddit', discord: 'Discord', slack: 'Slack', - hackernews: 'Hacker News' - } - } + hackernews: 'Hacker News', + }, + }, }, } diff --git a/backend/src/serverless/integrations/services/integrationProcessor.ts b/backend/src/serverless/integrations/services/integrationProcessor.ts index 68430e5334..4713cb3978 100644 --- a/backend/src/serverless/integrations/services/integrationProcessor.ts +++ b/backend/src/serverless/integrations/services/integrationProcessor.ts @@ -28,8 +28,8 @@ import { GithubIntegrationService } from './integrations/githubIntegrationServic import { LoggingBase } from '../../../services/loggingBase' import { API_CONFIG } from '../../../config' import EmailSender from '../../../services/emailSender' -import UserRepository from "../../../database/repositories/userRepository" -import {i18n} from "../../../i18n" +import UserRepository from '../../../database/repositories/userRepository' +import { i18n } from '../../../i18n' const MAX_STREAM_RETRIES = 5 @@ -463,7 +463,7 @@ export class IntegrationProcessor extends LoggingBase { for (const user of tenantUsers) { await new EmailSender(EmailSender.TEMPLATES.INTEGRATION_DONE, { integrationName: i18n('en', `entities.integration.name.${integration.platform}`), - link: API_CONFIG.frontendUrl + link: API_CONFIG.frontendUrl, }).sendTo(user.email) } } diff --git a/backend/src/services/emailSender.ts b/backend/src/services/emailSender.ts index 690080a33e..9c7315b8c3 100644 --- a/backend/src/services/emailSender.ts +++ b/backend/src/services/emailSender.ts @@ -28,7 +28,7 @@ export default class EmailSender extends LoggingBase { INVITATION: SENDGRID_CONFIG.templateInvitation, PASSWORD_RESET: SENDGRID_CONFIG.templatePasswordReset, WEEKLY_ANALYTICS: SENDGRID_CONFIG.templateWeeklyAnalytics, - INTEGRATION_DONE: SENDGRID_CONFIG.templateIntegrationDone + INTEGRATION_DONE: SENDGRID_CONFIG.templateIntegrationDone, } } From fbca9d853cf232acca6a4d9f2ca0a9058698873b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Bal=C3=A7a?= Date: Wed, 14 Dec 2022 10:46:50 +0000 Subject: [PATCH 4/4] Tweak integrations in progress alert copy --- frontend/src/modules/layout/components/layout.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/modules/layout/components/layout.vue b/frontend/src/modules/layout/components/layout.vue index 5c1ef96c23..f7c6cff3e3 100644 --- a/frontend/src/modules/layout/components/layout.vue +++ b/frontend/src/modules/layout/components/layout.vue @@ -62,8 +62,8 @@ }} getting set up. - This might take a few minutes, we'll send you - an email once it's done. + Sit back and relax. We will send you an email + when it’s done.