Using Same Industry for Product Search and Campaign Target Group
How can we copy Industry user enters on "Let's target the right talent" form to be used on Target Group of Campaign Form on Target Group step of Order Journey?
User already enters (or may not enter as it is optional) a Industry on Let's target the right talent
form which is the search-recommend-products
(formerly called onboarding) step for searching products, however that does not necessarily mean that the user will be using the same industry for the target group for the campaign they will order therefore we don't want to make that opinion on behalf of the end user, but you can programmatically copy the Industry entered in the search form to the campaign's target group as such:
const selectedIndustryIds = window.hapi.product.state.jobIndustriesIdsSelected.value
const copyIndustryFromSearchToTargetGroup = (industryIds) => {
const industries = window.hapi.product.state.jobIndustries.value
const industriesToCopy = []
industryIds.forEach(id => {
const industry = industries.find(_industry => _industry.id === id)
if (industry) {
industriesToCopy.push(industry)
}
})
window.hapi.campaign.state.campaignForm = window.hapiUtils.mergeDeepOverwriteArrays(
window.hapi.campaign.state.campaignForm.value,
{
targetGroup: {
industry: industriesToCopy
}
}
)
}
copyIndustryFromSearchToTargetGroup(selectedIndustryIds)
In most cases you would want to run the above code every time user changes the Job Function in the search-recommend-products
step. You can do that as such:
window.hapi.product.state.jobIndustriesIdsSelected.onChange((industryIds) => {
copyIndustryFromSearchToTargetGroup(industryIds)
})