From 423fbd6dd436d65431b62dfb04756c3280cedb54 Mon Sep 17 00:00:00 2001 From: Kelani Tolulope Date: Tue, 4 Jul 2023 14:18:10 +0100 Subject: [PATCH] Add nylas improvements to prefill the composer and mailbox components with record values on the record page --- .../PageBlocks/Nylas/Components/Composer.vue | 23 +++ .../PageBlocks/Nylas/Components/Mailbox.vue | 15 ++ .../components/PageBlocks/Nylas/NylasBase.vue | 38 +++++ .../PageBlocks/Nylas/NylasConfigurator.vue | 134 ++++++++++++++++++ lib/js/src/compose/types/page-block/nylas.ts | 16 +++ locale/en/corteza-webapp-compose/block.yaml | 7 + 6 files changed, 233 insertions(+) diff --git a/client/web/compose/src/components/PageBlocks/Nylas/Components/Composer.vue b/client/web/compose/src/components/PageBlocks/Nylas/Components/Composer.vue index dab46f49c..cf1ba6bd8 100644 --- a/client/web/compose/src/components/PageBlocks/Nylas/Components/Composer.vue +++ b/client/web/compose/src/components/PageBlocks/Nylas/Components/Composer.vue @@ -1,8 +1,10 @@ @@ -12,5 +14,26 @@ import '@nylas/components-composer' export default { extends: base, + + props: { + prefillValues: { + type: Object, + default: () => ({}), + }, + }, + + watch: { + prefillValues: { + deep: true, + immediate: true, + handler (value) { + this.$nextTick(() => { + const el = this.$refs.composer + // Set initial Values + el.value = value + }) + }, + }, + }, } diff --git a/client/web/compose/src/components/PageBlocks/Nylas/Components/Mailbox.vue b/client/web/compose/src/components/PageBlocks/Nylas/Components/Mailbox.vue index f9d68ad92..ea3b17b2a 100644 --- a/client/web/compose/src/components/PageBlocks/Nylas/Components/Mailbox.vue +++ b/client/web/compose/src/components/PageBlocks/Nylas/Components/Mailbox.vue @@ -2,6 +2,7 @@ @@ -12,5 +13,19 @@ import '@nylas/components-mailbox' export default { extends: base, + + props: { + prefillValues: { + type: Object, + default: () => ({}), + }, + }, + + computed: { + queryString () { + const { queryString = [] } = this.prefillValues + return `from=${queryString}` + }, + }, } diff --git a/client/web/compose/src/components/PageBlocks/Nylas/NylasBase.vue b/client/web/compose/src/components/PageBlocks/Nylas/NylasBase.vue index 1c46de073..71613127d 100644 --- a/client/web/compose/src/components/PageBlocks/Nylas/NylasBase.vue +++ b/client/web/compose/src/components/PageBlocks/Nylas/NylasBase.vue @@ -37,6 +37,7 @@ v-else :component-i-d="options.componentID" :access-token="accessToken" + :prefill-values="prefillValues" /> @@ -62,6 +63,13 @@ export default { accessToken: '', tokenCheckInterval: undefined, + + prefillValues: { + to: [], + subject: '', + body: '', + queryString: '', + }, } }, @@ -97,11 +105,41 @@ export default { .finally(() => { this.processing = false }) + + this.processPrefillValues() }, }, }, methods: { + processPrefillValues () { + if (this.module) { + this.prefillValues = { + to: this.mapFieldToValue('to').map(v => ({ email: v })), + subject: this.mapFieldToValue('subject').join(','), + body: this.mapFieldToValue('body').join('
'), + queryString: this.mapFieldToValue('queryString').join(','), + } + } + }, + + mapFieldToValue (property) { + const ID = this.options.prefill[property] + + if (!ID) { + return [] + } + + const { name, isMulti } = this.module.fields.find(f => f.fieldID === ID) || {} + const value = this.record.values[name] + + if (!value) { + return [] + } + + return isMulti ? this.record.values[name] : [this.record.values[name]] + }, + checkNylasAccessToken () { return this.$SystemAPI.userListCredentials({ userID: this.$auth.user.userID }) .then(credentials => { diff --git a/client/web/compose/src/components/PageBlocks/Nylas/NylasConfigurator.vue b/client/web/compose/src/components/PageBlocks/Nylas/NylasConfigurator.vue index 63f926646..e6df113e1 100644 --- a/client/web/compose/src/components/PageBlocks/Nylas/NylasConfigurator.vue +++ b/client/web/compose/src/components/PageBlocks/Nylas/NylasConfigurator.vue @@ -16,9 +16,114 @@ v-model="options.componentID" /> + + + diff --git a/lib/js/src/compose/types/page-block/nylas.ts b/lib/js/src/compose/types/page-block/nylas.ts index 649d36e21..62d69da78 100644 --- a/lib/js/src/compose/types/page-block/nylas.ts +++ b/lib/js/src/compose/types/page-block/nylas.ts @@ -7,12 +7,26 @@ interface Options { kind: string, componentID: string; magnifyOption: string; + prefill: Prefill; +} + +interface Prefill { + to: string; + subject: string; + body: string; + queryString: string; } const defaults: Readonly = Object.freeze({ kind: 'Composer', // Default kind of nylas component componentID: '', magnifyOption: '', + prefill: { + to: '', + subject: '', + body: '', + queryString: '' + } }) export class PageBlockNylas extends PageBlock { @@ -29,6 +43,8 @@ export class PageBlockNylas extends PageBlock { if (!o) return Apply(this.options, o, String, 'kind', 'componentID', 'magnifyOption') + + this.options.prefill = { ...defaults.prefill, ...o.prefill } } } diff --git a/locale/en/corteza-webapp-compose/block.yaml b/locale/en/corteza-webapp-compose/block.yaml index de0d90709..4d2eaf86a 100644 --- a/locale/en/corteza-webapp-compose/block.yaml +++ b/locale/en/corteza-webapp-compose/block.yaml @@ -729,6 +729,13 @@ nylas: label: Office365/Google kind: Component kind componentID: Component ID + prefill: + title: Prefill values + selectField: Select field + body: Body + subject: Subject + queryString: Query string + to: To kinds: agenda: Agenda composer: Composer