Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add reward modifiers tooltip

Tim Wilson668be9fc4dd9
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
index 1db66d8869..79766303e3 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
@@ -70,6 +70,7 @@ export function ProgramCustomerPageClient() {
<ProgramRewardList
rewards={programEnrollment?.rewards}
className="gap-2 border-none p-3"
+ showModifiers={false}
/>
</div>
}
diff --git a/apps/web/lib/partners/approve-partner-enrollment.ts b/apps/web/lib/partners/approve-partner-enrollment.ts
index 38383f7a40..a475738f2e 100644
--- a/apps/web/lib/partners/approve-partner-enrollment.ts
+++ b/apps/web/lib/partners/approve-partner-enrollment.ts
@@ -184,6 +184,7 @@ export async function approvePartnerEnrollment({
},
rewardDescription: ProgramRewardDescription({
reward: rewards.find((r) => r.event === "sale"),
+ showModifiers: false,
}),
}),
})),
diff --git a/apps/web/lib/partners/bulk-approve-partners.ts b/apps/web/lib/partners/bulk-approve-partners.ts
index 599cb52b97..7b17faff7f 100644
--- a/apps/web/lib/partners/bulk-approve-partners.ts
+++ b/apps/web/lib/partners/bulk-approve-partners.ts
@@ -84,6 +84,7 @@ export async function bulkApprovePartners({
reward:
sortRewardsByEventOrder(rewards.filter((r) => r.default))[0] ||
rewards[0],
+ showModifiers: false,
}),
}),
}));
diff --git a/apps/web/lib/zod/schemas/rewards.ts b/apps/web/lib/zod/schemas/rewards.ts
index 11bd4e113a..3ba8f17bfe 100644
--- a/apps/web/lib/zod/schemas/rewards.ts
+++ b/apps/web/lib/zod/schemas/rewards.ts
@@ -33,6 +33,15 @@ export const CONDITION_OPERATORS = [
"not_in",
] as const;
+export const CONDITION_OPERATOR_LABELS = {
+ equals_to: "is",
+ not_equals: "is not",
+ starts_with: "starts with",
+ ends_with: "ends with",
+ in: "is one of",
+ not_in: "is not one of",
+} as const;
+
export const rewardConditionSchema = z.object({
entity: z.enum(CONDITION_ENTITIES),
attribute: z.enum(CONDITION_ATTRIBUTES),
diff --git a/apps/web/ui/partners/program-reward-description.tsx b/apps/web/ui/partners/program-reward-description.tsx
index fa0e8dbb66..18213e8583 100644
--- a/apps/web/ui/partners/program-reward-description.tsx
+++ b/apps/web/ui/partners/program-reward-description.tsx
@@ -1,12 +1,14 @@
import { constructRewardAmount } from "@/lib/api/sales/construct-reward-amount";
import { DiscountProps, RewardProps } from "@/lib/types";
import { cn } from "@dub/utils";
+import { ProgramRewardModifiersTooltip } from "./program-reward-modifiers-tooltip";
export function ProgramRewardDescription({
reward,
discount,
amountClassName,
periodClassName,
+ showModifiers = true,
}: {
reward?: Pick<
RewardProps,
@@ -15,6 +17,7 @@ export function ProgramRewardDescription({
discount?: DiscountProps | null;
amountClassName?: string;
periodClassName?: string;
+ showModifiers?: boolean;
}) {
return (
<>
@@ -59,6 +62,13 @@ export function ProgramRewardDescription({
</strong>
</>
) : null}
+ {/* Modifiers */}
+ {showModifiers && !!reward.modifiers?.length && (
+ <>
+ {" "}
+ <ProgramRewardModifiersTooltip reward={reward} />
+ </>
+ )}
</>
)
: null}
diff --git a/apps/web/ui/partners/program-reward-list.tsx b/apps/web/ui/partners/program-reward-list.tsx
index 5e8344451f..8c19573ba6 100644
--- a/apps/web/ui/partners/program-reward-list.tsx
+++ b/apps/web/ui/partners/program-reward-list.tsx
@@ -4,15 +4,18 @@ import { Gift, Icon } from "@dub/ui";
import { cn } from "@dub/utils";
import { PropsWithChildren } from "react";
import { REWARD_EVENTS } from "./constants";
+import { ProgramRewardModifiersTooltip } from "./program-reward-modifiers-tooltip";
export function ProgramRewardList({
rewards,
discount,
className,
+ showModifiers = true,
}: {
rewards: RewardProps[];
discount?: DiscountProps | null;
className?: string;
+ showModifiers?: boolean;
}) {
const sortedFilteredRewards = rewards.filter((r) => r.amount >= 0);
@@ -62,6 +65,12 @@ export function ProgramRewardList({
</strong>
</>
) : null}
+ {showModifiers && !!reward.modifiers?.length && (
+ <>
+ {" "}
+ <ProgramRewardModifiersTooltip reward={reward} />
+ </>
+ )}
</>
)}
</Item>
diff --git a/apps/web/ui/partners/program-reward-modifiers-tooltip.tsx b/apps/web/ui/partners/program-reward-modifiers-tooltip.tsx
new file mode 100644
index 0000000000..c676a103b9
--- /dev/null
+++ b/apps/web/ui/partners/program-reward-modifiers-tooltip.tsx
@@ -0,0 +1,91 @@
+import { constructRewardAmount } from "@/lib/api/sales/construct-reward-amount";
+import { RewardProps } from "@/lib/types";
+import {
+ CONDITION_OPERATOR_LABELS,
+ rewardConditionsArraySchema,
+} from "@/lib/zod/schemas/rewards";
+import { ArrowTurnRight2, InfoTooltip } from "@dub/ui";
+import { capitalize, cn, pluralize, truncate } from "@dub/utils";
+import { Fragment } from "react";
+import { z } from "zod";
+
+export function ProgramRewardModifiersTooltip({
+ reward,
+}: {
+ reward?: Pick<
+ RewardProps,
+ "amount" | "type" | "event" | "maxDuration" | "modifiers"
+ > | null;
+}) {
+ if (!reward?.modifiers?.length) return null;
+
+ return (
+ <div className="inline-block align-text-top">
+ <InfoTooltip
+ content={
+ <div
+ className={cn(
+ "block max-w-xs text-pretty p-3 text-left text-xs font-medium text-neutral-600",
+ )}
+ >
+ <strong className="font-semibold">
+ <span className="text-content-default">
+ {constructRewardAmount({
+ amount: reward.amount,
+ type: reward.type,
+ })}
+ </span>{" "}
+ per {reward.event}
+ {reward.event === "sale" && (
+ <>
+ {" "}
+ {reward.maxDuration === 0
+ ? "one time"
+ : reward.maxDuration === Infinity ||
+ reward.maxDuration === null
+ ? "for the customer's lifetime"
+ : `for ${reward.maxDuration} ${pluralize("month", Number(reward.maxDuration))}`}
+ </>
+ )}
+ </strong>
+ {(
+ reward.modifiers as z.infer<typeof rewardConditionsArraySchema>
+ ).map(({ amount, operator, conditions }) => (
+ <Fragment key={amount}>
+ <div className="mt-1 flex items-start gap-1.5">
+ <ArrowTurnRight2 className="mt-0.5 size-3 shrink-0" />
+ <div className="min-w-0">
+ <strong className="text-content-default font-semibold">
+ {constructRewardAmount({
+ amount,
+ type: reward.type,
+ })}
+ </strong>
+ <ul className="overflow-hidden pl-1 text-xs text-neutral-600">
+ {conditions.map((condition, idx) => (
+ <li key={idx} className="flex items-center gap-1">
+ <span className="shrink-0 text-lg leading-none">
+ &bull;
+ </span>
+ <span className="min-w-0 truncate">
+ {idx === 0
+ ? "If"
+ : capitalize(operator.toLowerCase())}
+ {` ${condition.entity}`}
+ {` ${condition.attribute}`}
+ {` ${CONDITION_OPERATOR_LABELS[condition.operator]}`}
+ {` ${condition.value && truncate(Array.isArray(condition.value) ? condition.value.join(", ") : condition.value.toString(), 16)}`}
+ </span>
+ </li>
+ ))}
+ </ul>
+ </div>
+ </div>
+ </Fragment>
+ ))}
+ </div>
+ }
+ />
+ </div>
+ );
+}
diff --git a/apps/web/ui/partners/rewards/rewards-logic.tsx b/apps/web/ui/partners/rewards/rewards-logic.tsx
index cd5bc0b59d..d837701c35 100644
--- a/apps/web/ui/partners/rewards/rewards-logic.tsx
+++ b/apps/web/ui/partners/rewards/rewards-logic.tsx
@@ -7,6 +7,7 @@ import useWorkspace from "@/lib/swr/use-workspace";
import {
CONDITION_ATTRIBUTES,
CONDITION_CUSTOMER_ATTRIBUTES,
+ CONDITION_OPERATOR_LABELS,
CONDITION_OPERATORS,
CONDITION_SALE_ATTRIBUTES,
} from "@/lib/zod/schemas/rewards";
@@ -203,15 +204,6 @@ const ATTRIBUTE_LABELS = {
productId: "Product ID",
};
-const OPERATOR_LABELS = {
- equals_to: "is",
- not_equals: "is not",
- starts_with: "starts with",
- ends_with: "ends with",
- in: "is one of",
- not_in: "is not one of",
-} as const;
-
const formatValue = (
value: string | number | string[] | number[] | undefined,
) => {
@@ -325,7 +317,7 @@ function ConditionLogic({
<InlineBadgePopover
text={
condition.operator
- ? OPERATOR_LABELS[condition.operator]
+ ? CONDITION_OPERATOR_LABELS[condition.operator]
: "Condition"
}
invalid={!condition.operator}
@@ -353,7 +345,7 @@ function ConditionLogic({
)
}
items={CONDITION_OPERATORS.map((operator) => ({
- text: OPERATOR_LABELS[operator],
+ text: CONDITION_OPERATOR_LABELS[operator],
value: operator,
}))}
/>