From 66655b27a15307d1bf54c54c230941114bae1a65 Mon Sep 17 00:00:00 2001 From: bluedeepart Date: Wed, 27 Nov 2024 17:21:58 +0530 Subject: [PATCH 1/6] initla commit --- blocks/forms/formHelper.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blocks/forms/formHelper.js b/blocks/forms/formHelper.js index c508e4238..7eb86cbc6 100644 --- a/blocks/forms/formHelper.js +++ b/blocks/forms/formHelper.js @@ -2,7 +2,7 @@ import { input } from '../../scripts/dom-helpers.js'; import { getCookie } from '../../scripts/scripts.js'; /* Helper functions */ -export const RESOURCEKEYS = ['heading', 'region', 'portalId', 'formId', 'redirectUrl', 'productFamily', 'productPrimaryApplication', 'cmp']; +export const RESOURCEKEYS = ['heading', 'region', 'portalId', 'formId', 'redirectUrl', 'productFamily', 'productPrimaryApplication', 'cmp', 'jobTitle', 'website', 'productImage']; export function getDefaultForKey(key) { switch (key) { @@ -215,6 +215,7 @@ export function getFormFieldValues(formConfig) { requested_qdc_discussion__c: formConfig.qdc, research_area: formConfig.researchArea, return_url: formConfig.redirectUrl || thankyouUrl, + jobtitle: formConfig.jobTitle, website: formConfig.website, }; } From 4c6c68328b97e4a70adf2b4c3c999374fd380c3a Mon Sep 17 00:00:00 2001 From: bluedeepart Date: Wed, 27 Nov 2024 21:01:05 +0530 Subject: [PATCH 2/6] get value from href --- blocks/forms/formHelper.js | 27 +++++++++++++-------------- blocks/forms/forms.js | 29 ++++------------------------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/blocks/forms/formHelper.js b/blocks/forms/formHelper.js index 7eb86cbc6..7601b2c27 100644 --- a/blocks/forms/formHelper.js +++ b/blocks/forms/formHelper.js @@ -1,22 +1,21 @@ import { input } from '../../scripts/dom-helpers.js'; +import { toCamelCase } from '../../scripts/lib-franklin.js'; import { getCookie } from '../../scripts/scripts.js'; -/* Helper functions */ -export const RESOURCEKEYS = ['heading', 'region', 'portalId', 'formId', 'redirectUrl', 'productFamily', 'productPrimaryApplication', 'cmp', 'jobTitle', 'website', 'productImage']; - -export function getDefaultForKey(key) { - switch (key) { - case 'heading': - return ''; - case 'region': - return 'na1'; - case 'portalId': - return '20222769 '; - default: - return ''; - } +// extract data from table +export async function extractFormData(block) { + const blockData = {}; + [...block.children].forEach((row) => { + const key = toCamelCase(row.children[0].textContent.trim().toLowerCase()); + const valueContainer = row.children[1]; + const link = valueContainer.querySelector('a'); + const value = link ? link.href : valueContainer.textContent.trim(); + blockData[key] = value; + }); + return blockData; } +// get form id export function getFormId(type) { switch (type) { case 'app-note': diff --git a/blocks/forms/forms.js b/blocks/forms/forms.js index 68ef68065..396f8ac12 100644 --- a/blocks/forms/forms.js +++ b/blocks/forms/forms.js @@ -1,34 +1,12 @@ import { a, button, div, h3, label, } from '../../scripts/dom-helpers.js'; -import { loadCSS, toCamelCase, toClassName } from '../../scripts/lib-franklin.js'; +import { loadCSS, toClassName } from '../../scripts/lib-franklin.js'; import { loadScript } from '../../scripts/scripts.js'; import { - createSalesforceForm, - getDefaultForKey, - getFormFieldValues, - getFormId, - RESOURCEKEYS, - updateFormFields, + createSalesforceForm, extractFormData, getFormFieldValues, getFormId, updateFormFields, } from './formHelper.js'; -/* extract data from table */ -async function extractFormData(block) { - const blockData = {}; - [...block.children].forEach((row) => { - const key = toCamelCase(row.children[0].textContent.trim().toLowerCase()); - const value = row.children[1].textContent.trim(); - blockData[key] = value; - }); - - RESOURCEKEYS.forEach((key) => { - if (!blockData[key]) { - blockData[key] = getDefaultForKey(key); - } - }); - return blockData; -} - /* create hubspot form */ export function createHubSpotForm(formConfig, target, type = '') { try { @@ -104,6 +82,7 @@ export default async function decorate(block, index) { }), ); - block.replaceWith(form); + block.innerHTML = ''; + block.appendChild(form); loadHubSpotScript(createHubSpotForm.bind(null, formConfig, target, pageType)); } From 7adcd7f3ff28dfc494e9ed0654e82ae70c0d8ca1 Mon Sep 17 00:00:00 2001 From: bluedeepart Date: Thu, 28 Nov 2024 11:06:20 +0530 Subject: [PATCH 3/6] updated fields name --- blocks/forms/formHelper.js | 6 +++--- blocks/forms/forms.js | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/blocks/forms/formHelper.js b/blocks/forms/formHelper.js index 7601b2c27..ad0f6a0e1 100644 --- a/blocks/forms/formHelper.js +++ b/blocks/forms/formHelper.js @@ -207,15 +207,15 @@ export function getFormFieldValues(formConfig) { product_bundle: formConfig.productBundle, product_bundle_image: formConfig.productBundleImage, product_family__c: formConfig.productFamily, - product_image: formConfig.productImage, + product_image: formConfig.productImage || formConfig.resourceImageUrl, product_primary_application__c: formConfig.productPrimaryApplication, product_selection__c: formConfig.productSelection, qdc: formConfig.qdc, requested_qdc_discussion__c: formConfig.qdc, research_area: formConfig.researchArea, return_url: formConfig.redirectUrl || thankyouUrl, - jobtitle: formConfig.jobTitle, - website: formConfig.website, + jobtitle: formConfig.jobTitle || formConfig.title, + website: formConfig.website || formConfig.resourceUrl, }; } diff --git a/blocks/forms/forms.js b/blocks/forms/forms.js index 396f8ac12..633f013ba 100644 --- a/blocks/forms/forms.js +++ b/blocks/forms/forms.js @@ -68,6 +68,7 @@ export function loadHubSpotScript(callback) { export default async function decorate(block, index) { const formConfig = await extractFormData(block); + console.log(formConfig); const formHeading = formConfig.heading || ''; const target = toClassName(formHeading) || `hubspot-form-${index}`; const blockClasses = block.classList.value; From dad6d22e64832cf6feaf278fe7d12534abccecc3 Mon Sep 17 00:00:00 2001 From: bluedeepart Date: Thu, 28 Nov 2024 11:07:18 +0530 Subject: [PATCH 4/6] lint fixed --- blocks/forms/forms.js | 1 - 1 file changed, 1 deletion(-) diff --git a/blocks/forms/forms.js b/blocks/forms/forms.js index 633f013ba..396f8ac12 100644 --- a/blocks/forms/forms.js +++ b/blocks/forms/forms.js @@ -68,7 +68,6 @@ export function loadHubSpotScript(callback) { export default async function decorate(block, index) { const formConfig = await extractFormData(block); - console.log(formConfig); const formHeading = formConfig.heading || ''; const target = toClassName(formHeading) || `hubspot-form-${index}`; const blockClasses = block.classList.value; From 7af5420d863dc4971f2f9d097d74d9cf946c583a Mon Sep 17 00:00:00 2001 From: bluedeepart Date: Thu, 28 Nov 2024 11:10:53 +0530 Subject: [PATCH 5/6] added test form --- blocks/forms/formHelper.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blocks/forms/formHelper.js b/blocks/forms/formHelper.js index ad0f6a0e1..484e78cff 100644 --- a/blocks/forms/formHelper.js +++ b/blocks/forms/formHelper.js @@ -19,7 +19,8 @@ export async function extractFormData(block) { export function getFormId(type) { switch (type) { case 'app-note': - return '46645e42-ae08-4d49-9338-e09efb4c4035'; + // return '46645e42-ae08-4d49-9338-e09efb4c4035'; // app note master form + return 'd6f54803-6515-4313-a7bd-025dfa5cbb5f '; // test form case 'scientific-poster': return '342c229a-9e0d-4f52-b4c4-07f067d39c31'; case 'ebook': From 94892729bf56193adf68994367d9a77c340fb255 Mon Sep 17 00:00:00 2001 From: bluedeepart Date: Thu, 28 Nov 2024 12:36:58 +0530 Subject: [PATCH 6/6] added resource thumb image --- blocks/forms/formHelper.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/blocks/forms/formHelper.js b/blocks/forms/formHelper.js index 484e78cff..8c887450d 100644 --- a/blocks/forms/formHelper.js +++ b/blocks/forms/formHelper.js @@ -9,7 +9,15 @@ export async function extractFormData(block) { const key = toCamelCase(row.children[0].textContent.trim().toLowerCase()); const valueContainer = row.children[1]; const link = valueContainer.querySelector('a'); - const value = link ? link.href : valueContainer.textContent.trim(); + const image = valueContainer.querySelector('img'); + let value; + if (link) { + value = link.href; + } else if (image) { + value = image.src; + } else { + value = valueContainer.textContent.trim(); + } blockData[key] = value; }); return blockData;