Skip to content

Commit

Permalink
Reformat code as requested in managed-components#2 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manouchehri committed Apr 30, 2023
1 parent b9e0fda commit 1d0231f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ export const sendEvent =
keepalive: true,
mode: 'no-cors',
headers: {
'Cookie': `hubspotutk=${client.get('hubspotutk')}; hssc=${client.get('hssc')}; hstc=${client.get('hstc')}; hssrc=${client.get('hssrc')}`,
'referer': client.referer,
'user-agent': client.userAgent
}
Cookie: `hubspotutk=${client.get('hubspotutk')}; hssc=${client.get(
'hssc'
)}; hstc=${client.get('hstc')}; hssrc=${client.get('hssrc')}`,
referer: client.referer,
'user-agent': client.userAgent,
},
}
)
}
Expand All @@ -137,22 +139,22 @@ export const handleChatEvent =
export const handleFormEvent =
(manager: Manager, settings: ComponentSettings) => async (event: MCEvent) => {
const { accountId, regionPrefix } = settings
const formId = event.payload.formId;
const formId = event.payload.formId

const hs_context = {
hutk: event.client.get('hubspotutk'),
ipAddress: event.client.ip,
pageUrl: event.client.url,
pageName: event.client.title,
};
}

const requestBodyParams = [
`hs_context=${encodeURIComponent(JSON.stringify(hs_context))}`
];
`hs_context=${encodeURIComponent(JSON.stringify(hs_context))}`,
]

for(let key in event.payload) {
if(key === 'formId') continue;
requestBodyParams.push(`${key}=${encodeURIComponent(event.payload[key])}`);
for (const key in event.payload) {
if (key === 'formId') continue
requestBodyParams.push(`${key}=${encodeURIComponent(event.payload[key])}`)
}

manager.fetch(
Expand All @@ -162,8 +164,8 @@ export const handleFormEvent =
{
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
redirect: "manual",
body: requestBodyParams.join('&')
redirect: 'manual',
body: requestBodyParams.join('&'),
}
)
}
Expand Down

0 comments on commit 1d0231f

Please sign in to comment.