feat(promotion,dashboard,types,utils,medusa): Add statuses to promotions (#10950)
what: - adds a status column to promotion table - introduce active promotion query - scope revert, register and compute actions to active promotions - admin to create and update promotion with statuses RESOLVES CMRC-845 RESOLVES CMRC-846 RESOLVES CMRC-847 RESOLVES CMRC-848 RESOLVES CMRC-849 RESOLVES CMRC-850
This commit is contained in:
@@ -1,10 +1,28 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { i18n } from "../components/utilities/i18n"
|
||||
|
||||
export enum PromotionStatus {
|
||||
SCHEDULED = "SCHEDULED",
|
||||
EXPIRED = "EXPIRED",
|
||||
ACTIVE = "ACTIVE",
|
||||
DISABLED = "DISABLED",
|
||||
INACTIVE = "INACTIVE",
|
||||
DRAFT = "DRAFT",
|
||||
}
|
||||
|
||||
export type StatusColors = "grey" | "orange" | "green" | "red" | "grey"
|
||||
export type StatusMap = Record<string, [StatusColors, string]>
|
||||
export const promotionStatusMap: StatusMap = {
|
||||
[PromotionStatus.ACTIVE]: ["green", i18n.t("statuses.active")],
|
||||
[PromotionStatus.INACTIVE]: ["red", i18n.t("statuses.inactive")],
|
||||
[PromotionStatus.DRAFT]: ["grey", i18n.t("statuses.draft")],
|
||||
[PromotionStatus.SCHEDULED]: [
|
||||
"orange",
|
||||
`${i18n.t("promotions.fields.campaign")} ${i18n.t("statuses.scheduled").toLowerCase()}`,
|
||||
],
|
||||
[PromotionStatus.EXPIRED]: [
|
||||
"red",
|
||||
`${i18n.t("promotions.fields.campaign")} ${i18n.t("statuses.expired").toLowerCase()}`,
|
||||
],
|
||||
}
|
||||
|
||||
export const getPromotionStatus = (promotion: HttpTypes.AdminPromotion) => {
|
||||
@@ -12,11 +30,11 @@ export const getPromotionStatus = (promotion: HttpTypes.AdminPromotion) => {
|
||||
const campaign = promotion.campaign
|
||||
|
||||
if (!campaign) {
|
||||
return PromotionStatus.ACTIVE
|
||||
return promotionStatusMap[promotion.status!.toUpperCase()]
|
||||
}
|
||||
|
||||
if (new Date(campaign.starts_at!) > date) {
|
||||
return PromotionStatus.SCHEDULED
|
||||
if (campaign.starts_at && new Date(campaign.starts_at!) > date) {
|
||||
return promotionStatusMap[PromotionStatus.SCHEDULED]
|
||||
}
|
||||
|
||||
const campaignBudget = campaign.budget
|
||||
@@ -24,8 +42,8 @@ export const getPromotionStatus = (promotion: HttpTypes.AdminPromotion) => {
|
||||
campaignBudget && campaignBudget.used! > campaignBudget.limit!
|
||||
|
||||
if ((campaign.ends_at && new Date(campaign.ends_at) < date) || overBudget) {
|
||||
return PromotionStatus.EXPIRED
|
||||
return promotionStatusMap[PromotionStatus.EXPIRED]
|
||||
}
|
||||
|
||||
return PromotionStatus.ACTIVE
|
||||
return promotionStatusMap[promotion.status!.toUpperCase()]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user