feat(medusa,types): create promotion flows (#7029)
* chore: create promotion phase * chore: fix specs + minor ui changes * chore: minor fixes * chore: added changeset * address pr reviews * chore: fix spec * Update packages/admin-next/dashboard/src/v2-routes/promotions/common/edit-rules/edit-rules.tsx Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com> * chore: fix specs --------- Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com>
This commit is contained in:
co-authored by
Frane Polić
parent
b61dcb84c9
commit
93ef94cad3
@@ -39,22 +39,24 @@ export const GET = async (
|
||||
if (dasherizedRuleType === RuleType.RULES) {
|
||||
promotionRules.push(...(promotion?.rules || []))
|
||||
} else if (dasherizedRuleType === RuleType.TARGET_RULES) {
|
||||
promotionRules.push(...(promotion.application_method?.target_rules || []))
|
||||
promotionRules.push(...(promotion?.application_method?.target_rules || []))
|
||||
} else if (dasherizedRuleType === RuleType.BUY_RULES) {
|
||||
promotionRules.push(...(promotion.application_method?.buy_rules || []))
|
||||
promotionRules.push(...(promotion?.application_method?.buy_rules || []))
|
||||
}
|
||||
|
||||
const transformedRules: AdminGetPromotionRulesRes = []
|
||||
const disguisedRules = ruleAttributes.filter((attr) => !!attr.disguised)
|
||||
const requiredRules = ruleAttributes.filter((attr) => !!attr.required)
|
||||
|
||||
for (const disguisedRule of disguisedRules) {
|
||||
const value = promotion.application_method?.[disguisedRule.id]
|
||||
const values = [{ label: value, value }]
|
||||
const value = promotion?.application_method?.[disguisedRule.id]
|
||||
const values = value ? [{ label: value, value }] : []
|
||||
|
||||
transformedRules.push({
|
||||
id: undefined,
|
||||
attribute: disguisedRule.id,
|
||||
attribute_label: disguisedRule.label,
|
||||
field_type: disguisedRule.field_type,
|
||||
operator: RuleOperator.EQ,
|
||||
operator_label: operatorsMap[RuleOperator.EQ].label,
|
||||
values,
|
||||
@@ -102,6 +104,7 @@ export const GET = async (
|
||||
transformedRules.push({
|
||||
...promotionRule,
|
||||
attribute_label: currentRuleAttribute.label,
|
||||
field_type: currentRuleAttribute.field_type,
|
||||
operator_label:
|
||||
operatorsMap[promotionRule.operator]?.label || promotionRule.operator,
|
||||
disguised: false,
|
||||
@@ -109,6 +112,24 @@ export const GET = async (
|
||||
})
|
||||
}
|
||||
|
||||
if (requiredRules.length && !transformedRules.length) {
|
||||
for (const requiredRule of requiredRules) {
|
||||
transformedRules.push({
|
||||
id: undefined,
|
||||
attribute: requiredRule.value,
|
||||
attribute_label: requiredRule.label,
|
||||
operator: RuleOperator.EQ,
|
||||
field_type: requiredRule.field_type,
|
||||
operator_label: operatorsMap[RuleOperator.EQ].label,
|
||||
values: [],
|
||||
disguised: true,
|
||||
required: true,
|
||||
})
|
||||
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
rules: transformedRules,
|
||||
})
|
||||
|
||||
@@ -6,7 +6,7 @@ export const ruleQueryConfigurations = {
|
||||
},
|
||||
currency: {
|
||||
entryPoint: "currency",
|
||||
labelAttr: "name",
|
||||
labelAttr: "code",
|
||||
valueAttr: "code",
|
||||
},
|
||||
customer_group: {
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
import { z } from "zod"
|
||||
import {
|
||||
createFindParams,
|
||||
createOperatorMap,
|
||||
createSelectParams,
|
||||
} from "../../utils/validators"
|
||||
import {
|
||||
ApplicationMethodAllocation,
|
||||
ApplicationMethodTargetType,
|
||||
@@ -12,6 +6,12 @@ import {
|
||||
PromotionRuleOperator,
|
||||
PromotionType,
|
||||
} from "@medusajs/utils"
|
||||
import { z } from "zod"
|
||||
import {
|
||||
createFindParams,
|
||||
createOperatorMap,
|
||||
createSelectParams,
|
||||
} from "../../utils/validators"
|
||||
|
||||
export type AdminGetPromotionParamsType = z.infer<
|
||||
typeof AdminGetPromotionParams
|
||||
@@ -89,7 +89,7 @@ export type AdminCreateApplicationMethodType = z.infer<
|
||||
export const AdminCreateApplicationMethod = z
|
||||
.object({
|
||||
description: z.string().optional(),
|
||||
value: z.string(),
|
||||
value: z.number(),
|
||||
max_quantity: z.number().optional(),
|
||||
type: z.nativeEnum(ApplicationMethodType),
|
||||
target_type: z.nativeEnum(ApplicationMethodTargetType),
|
||||
|
||||
Reference in New Issue
Block a user