feat(dashboard): add promotions to campaign UI (#7283)
* feat(core-flows,types,medusa): API to add promotions to campaign * chore: consolidate specs * chore: split workflows step into 2 * chore: fix tests * chore: fix specs * chore: add promotions to campaign UI * chore: fix bug wrt to not refreshing * chore: address review comments
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IPromotionModuleService, LinkWorkflowInput } from "@medusajs/types"
|
||||
import { StepResponse, WorkflowData, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const addOrRemoveCampaignPromotionsStepId =
|
||||
"add-or-remove-campaign-promotions"
|
||||
export const addOrRemoveCampaignPromotionsStep = createStep(
|
||||
addOrRemoveCampaignPromotionsStepId,
|
||||
async (input: WorkflowData<LinkWorkflowInput>, { container }) => {
|
||||
const {
|
||||
id: campaignId,
|
||||
add: promotionIdsToAdd = [],
|
||||
remove: promotionIdsToRemove = [],
|
||||
} = input
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
if (promotionIdsToAdd.length) {
|
||||
await promotionModule.addPromotionsToCampaign({
|
||||
id: campaignId,
|
||||
promotion_ids: promotionIdsToAdd,
|
||||
})
|
||||
}
|
||||
|
||||
if (promotionIdsToRemove.length) {
|
||||
await promotionModule.removePromotionsFromCampaign({
|
||||
id: campaignId,
|
||||
promotion_ids: promotionIdsToRemove,
|
||||
})
|
||||
}
|
||||
|
||||
return new StepResponse(null, input)
|
||||
},
|
||||
async (data, { container }) => {
|
||||
if (!data) {
|
||||
return
|
||||
}
|
||||
|
||||
const {
|
||||
id: campaignId,
|
||||
add: promotionIdsToRemove = [],
|
||||
remove: promotionIdsToAdd = [],
|
||||
} = data
|
||||
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
if (promotionIdsToAdd.length) {
|
||||
promotionModule.addPromotionsToCampaign({
|
||||
id: campaignId,
|
||||
promotion_ids: promotionIdsToAdd,
|
||||
})
|
||||
}
|
||||
|
||||
if (promotionIdsToRemove.length) {
|
||||
promotionModule.removePromotionsFromCampaign({
|
||||
id: campaignId,
|
||||
promotion_ids: promotionIdsToRemove,
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -51,6 +51,11 @@ export interface PromotionDTO {
|
||||
*/
|
||||
rules?: PromotionRuleDTO[]
|
||||
|
||||
/**
|
||||
* The associated campaign.
|
||||
*/
|
||||
campaign_id?: string | null
|
||||
|
||||
/**
|
||||
* The associated campaign.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user