The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add "enum" type to RewardConditionEntityAttribute, hide customer source if not REFERRAL_ENABLED_PROGRAM_IDS (#3506)
Steven Tey6bef2c6987da
diff --git a/apps/web/lib/zod/schemas/rewards.ts b/apps/web/lib/zod/schemas/rewards.tsindex 88260d7ed5..3b1cdd8490 100644--- a/apps/web/lib/zod/schemas/rewards.ts+++ b/apps/web/lib/zod/schemas/rewards.ts@@ -20,7 +20,7 @@ export const COMMISSION_TYPES = [export type RewardConditionEntityAttribute = {id: string;label: string;- type: "string" | "number" | "currency";+ type: "string" | "enum" | "number" | "currency";options?: {id: string;label: string;@@ -40,7 +40,7 @@ const PARTNER_ENTITY: RewardConditionEntity = {{id: "country",label: "Country",- type: "string",+ type: "enum",},{id: "totalClicks",@@ -77,7 +77,7 @@ const CUSTOMER_ENTITY: RewardConditionEntity = {{id: "country",label: "Country",- type: "string",+ type: "enum",},],};@@ -205,6 +205,9 @@ export const CONDITION_OPERATORS = [export const STRING_CONDITION_OPERATORS: (typeof CONDITION_OPERATORS)[number][] =["equals_to", "not_equals", "starts_with", "ends_with", "in", "not_in"];+export const ENUM_CONDITION_OPERATORS: (typeof CONDITION_OPERATORS)[number][] =+ ["equals_to", "not_equals", "in", "not_in"];+export const NUMBER_CONDITION_OPERATORS: (typeof CONDITION_OPERATORS)[number][] =["equals_to",diff --git a/apps/web/ui/partners/rewards/rewards-logic.tsx b/apps/web/ui/partners/rewards/rewards-logic.tsxindex b549ec04ac..99ef9dcb8f 100644--- a/apps/web/ui/partners/rewards/rewards-logic.tsx+++ b/apps/web/ui/partners/rewards/rewards-logic.tsx@@ -9,6 +9,7 @@ import { RECURRING_MAX_DURATIONS } from "@/lib/zod/schemas/misc";import {CONDITION_OPERATOR_LABELS,CONDITION_OPERATORS,+ ENUM_CONDITION_OPERATORS,NUMBER_CONDITION_OPERATORS,REWARD_CONDITIONS,RewardConditionEntityAttribute,@@ -391,10 +392,17 @@ function ConditionLogic({},)}- items={entity.attributes.map((attribute) => ({- text: attribute.label,- value: attribute.id,- }))}+ items={entity.attributes+ .filter(+ (attribute) =>+ attribute.id !== "source" ||+ (program &&+ REFERRAL_ENABLED_PROGRAM_IDS.includes(program.id)),+ )+ .map((attribute) => ({+ text: attribute.label,+ value: attribute.id,+ }))}/></InlineBadgePopover>{" "}{isCustomerSourceCondition ? (@@ -437,7 +445,9 @@ function ConditionLogic({}items={(["number", "currency"].includes(attributeType)? NUMBER_CONDITION_OPERATORS- : STRING_CONDITION_OPERATORS+ : attributeType === "enum"+ ? ENUM_CONDITION_OPERATORS+ : STRING_CONDITION_OPERATORS).map((operator) => ({text: CONDITION_OPERATOR_LABELS[operator],value: operator,@@ -462,10 +472,7 @@ function ConditionLogic({)}>{/* Country selection */}- {condition.attribute === "country" &&- !["starts_with", "ends_with"].includes(- condition.operator,- ) ? (+ {condition.attribute === "country" ? (// Country selector<InlineBadgePopoverMenusearch@@ -503,10 +510,7 @@ function ConditionLogic({});}}/>- ) : attribute?.options &&- !["starts_with", "ends_with"].includes(- condition.operator,- ) ? (+ ) : attribute?.options ? (// Select option selector<InlineBadgePopoverMenusearch={attribute.options.length > 4}@@ -514,20 +518,10 @@ function ConditionLogic({(condition.value as string[] | undefined) ??(isArrayValue ? [] : undefined)}- items={attribute.options- .filter(- (attribute) =>- isCustomerSourceCondition &&- (attribute.id !== "submitted" ||- (program &&- REFERRAL_ENABLED_PROGRAM_IDS.includes(- program.id,- ))),- )- .map(({ id, label }) => ({- text: label,- value: id,- }))}+ items={attribute.options.map(({ id, label }) => ({+ text: label,+ value: id,+ }))}onSelect={(value) => {setValue(conditionKey, {...condition,