Campaign Edit Improvements
After a campaign has been ordered with a contract, there is a chance that the contract may have been deleted. In the case that a single contract was ordered, the basket seemed empty.
In that case, when copying the campaign, there is an alert that shows the message There were products/contracts ordered as part of this campaign which no longer exist and they have not been added to your basket.
In the case, when editing the campaign, the same case can happen however there was no alert being shown.
We have added code to show the same alert message when also editing the campaign.
Campaign Service editCampaign function
The business logic code within the widget has been moved to window.hapi to the editCampaign function. This means that when called, the logic to prepare the data for editing and opening the modal to edit the campaign runs.
As part of this change, the following arguments to the function with type CampaignServiceEditCampaignHandler have been added:
campaignId?: stringorderedProductId?: string | number
The first argument, which is the Campaign object, is not changed. If you don't have the campaign object then you can pass undefined for the first argument then pass a campaign ID as the second argument and HAPI Elements will fetch the campaign for you.
When either the campaign object is passed as undefined or the fetched campaign via the campaign ID is not found, an error will be thrown and a message will be shown in the console.
When the third argument of orderedProductId is passed, the widget will not open a modal to edit the campaign because there is only a single modal for the entire campaign to be edited; however there is widgets that are used inline by the ATSs which are:
- Save Buttons Bar for Edit Form only with Channel Posting Requirements
- Edit Form only with Channel Posting Requirements
Campaign State New Variables
The following variables have been added to the window.hapi.campaign.state and is managed by the editCampaign function:
campaignBeingEditedcampaignBeingEditedIsLoadingcampaignBeingEditedIsNotFoundcampaignBeingEditedIsEditingContractOrProductcampaignBeingEditedContractOrProductId
Campaign Validations New Validators
The following validators have been added to the window.hapi.campaign.validations object:
Basket getProducts function
To load latest real product data, HAPI Elements works with the meta concept where there is only the ID stored. The real data is fetched from backend via the getProducts function.
For the alert to show up, we needed to fetch the real product data from backend first, then display the alert thus we have added the following argument to the function: