Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form autoresponder #1555

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions blocks/forms/formHelper.js
Original file line number Diff line number Diff line change
@@ -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'];

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':
Expand Down Expand Up @@ -215,6 +214,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,
};
}
Expand Down
29 changes: 4 additions & 25 deletions blocks/forms/forms.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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));
}