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:
Riqwan Thamir
2024-05-10 10:39:01 +02:00
committed by GitHub
parent ea872cbda9
commit 6ec5ded6c8
13 changed files with 374 additions and 24 deletions

View File

@@ -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,
})
}
}
)

View File

@@ -51,6 +51,11 @@ export interface PromotionDTO {
*/
rules?: PromotionRuleDTO[]
/**
* The associated campaign.
*/
campaign_id?: string | null
/**
* The associated campaign.
*/