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

initial commit #1606

Open
wants to merge 3 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
3 changes: 3 additions & 0 deletions blocks/forms/formHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export const formMapping = [
{ type: 'inquiry', id: 'bbca06dd-57d2-433b-a8c1-d5cd18b4ce28' },
// { type: 'share-story', id: 'a1086f3a-ed6e-47d1-9694-17f8c0a28612' },
{ type: 'share-story', id: '5d062792-bb0b-4f11-bc26-f3d3422ae4ec' },
{ type: 'promo', id: '014f34d1-570e-49d9-b1a6-c630c5ef609f' },
{ type: 'ebook-promo', id: 'b83700e4-f00b-4b92-9124-fab2968f60b5' },
{ type: 'app-note-promo', id: 'ed0daf7c-99c6-4fd8-aa32-13d4e053fa64' },
];

export function getFormId(type) {
Expand Down
13 changes: 10 additions & 3 deletions blocks/forms/forms.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/* stylelint-disable no-descending-specificity */
:root {
--input-color: #5f696b;
--border-color: #bebebe;
}

/* stylelint-disable no-descending-specificity */
.forms.block .no-type-msg {
list-style: none;
padding: 0;
margin: 0;
text-align: left;
}

.hs-form .hs-dependent-field,
.hs-form .hs-form-field {
line-height: 1.4em;
Expand Down Expand Up @@ -257,8 +264,8 @@ main form fieldset[class*="form-columns"] .input {
order: 1;
}

.hubspot-form form div:has(> .hs-richtext > .privacy),
.hubspot-form form fieldset:has(> .hs-richtext > .privacy) {
.hubspot-form form div:has(> .hs-richtext .privacy),
.hubspot-form form fieldset:has(> .hs-richtext .privacy) {
order: 2;
}

Expand Down
21 changes: 14 additions & 7 deletions blocks/forms/forms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable import/no-cycle */
import { button, div, h3 } from '../../scripts/dom-helpers.js';
import {
button, div, h3, li, p, ul,
} from '../../scripts/dom-helpers.js';
import { loadCSS, toClassName } from '../../scripts/lib-franklin.js';
import { loadScript } from '../../scripts/scripts.js';
import { loadScript, toTitleCase } from '../../scripts/scripts.js';
import {
createSalesforceForm, extractFormData, formMapping, getFormFieldValues,
getFormId, updateFormFields,
Expand All @@ -28,7 +30,7 @@ export function createHubSpotForm(formConfig, target, type = '') {
const submitButton = button({
type: 'submit',
class: 'button primary',
}, submitInput.value || 'Submit');
}, formConfig.cta || submitInput.value || 'Submit');
submitInput.replaceWith(submitButton);
}
}
Expand All @@ -37,7 +39,6 @@ export function createHubSpotForm(formConfig, target, type = '') {
onFormSubmit: (hubspotForm) => {
createSalesforceForm(hubspotForm, formConfig);
if (type === 'newsletter' || type === 'lab-notes') {
console.log('Form submitted');
// eslint-disable-next-line no-undef, quote-props
dataLayer.push({ 'event': 'new_subscriber' });
}
Expand All @@ -60,9 +61,9 @@ export default async function decorate(block, index) {
const formConfig = await extractFormData(block);
const formHeading = formConfig.heading || '';
const target = toClassName(formHeading) || `hubspot-form-${index}`;
const blockClasses = block.classList.value;
const blockClasses = block.classList.value.split(' ');
const formTypes = formMapping.map((item) => item.type);
const formType = formTypes.filter((type) => blockClasses.includes(type))[0];
const formType = formTypes.find((type) => blockClasses.find((cls) => cls === type));

const form = div(
h3(formHeading),
Expand All @@ -74,5 +75,11 @@ export default async function decorate(block, index) {

block.innerHTML = '';
block.appendChild(form);
loadHubSpotScript(createHubSpotForm.bind(null, formConfig, target, formType));
if (formType) {
loadHubSpotScript(createHubSpotForm.bind(null, formConfig, target, formType));
} else {
const formTypeList = ul({ class: 'no-type-msg' }, p('Please add one of the following type to the block:'));
formMapping.map((item) => formTypeList.appendChild(li(toTitleCase(item.type))));
block.appendChild(formTypeList);
}
}
10 changes: 10 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1350,4 +1350,14 @@ export async function getCountryCode() {
return data.country_code;
}

/**
* Converts any string to Title Case.
*
* @param {string} str - The input string.
* @returns {string} The formatted string in Title Case.
*/
export function toTitleCase(str) {
return str.toLowerCase().replace(/(?:^|\s|[_-])\w/g, (match) => match.toUpperCase());
}

loadPage();
Loading