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 dropdown

Kiran Ka1a2e0933ce8
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/partners/use-partner-filters.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/partners/use-partner-filters.tsx
index b477e64c91..b52c8e369d 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/partners/use-partner-filters.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/partners/use-partner-filters.tsx
@@ -1,14 +1,18 @@
import usePartnersCount from "@/lib/swr/use-partners-count";
+import useRewards from "@/lib/swr/use-rewards";
import useWorkspace from "@/lib/swr/use-workspace";
+import { REWARD_EVENTS } from "@/lib/zod/schemas/rewards";
import { PartnerStatusBadges } from "@/ui/partners/partner-status-badges";
+import { formatRewardDescription } from "@/ui/partners/program-reward-description";
import { useRouterStuff } from "@dub/ui";
-import { CircleDotted, FlagWavy } from "@dub/ui/icons";
+import { CircleDotted, FlagWavy, Gift } from "@dub/ui/icons";
import { cn, COUNTRIES, nFormatter } from "@dub/utils";
import { useMemo } from "react";
export function usePartnerFilters(extraSearchParams: Record<string, string>) {
const { searchParamsObj, queryParams } = useRouterStuff();
const { id: workspaceId } = useWorkspace();
+ const { rewards } = useRewards();
const { partnersCount: countriesCount } = usePartnersCount<
{
@@ -76,8 +80,31 @@ export function usePartnerFilters(extraSearchParams: Record<string, string>) {
},
),
},
+ {
+ key: "reward",
+ icon: Gift,
+ label: "Reward",
+ // getOptionIcon: (reward: RewardProps) => {
+ // const Icon = REWARD_EVENTS[reward.event].icon;
+
+ // return <Icon className="size-4 bg-transparent" />;
+ // },
+ // getOptionLabel: (reward: RewardProps) =>
+ // formatRewardDescription({ reward }),
+ options:
+ rewards?.map((reward) => {
+ const Icon = REWARD_EVENTS[reward.event].icon;
+
+ return {
+ value: reward.id,
+ label: formatRewardDescription({ reward }),
+ icon: <Icon className="size-4 bg-transparent" />,
+ // right: reward.event,
+ };
+ }) ?? [],
+ },
],
- [countriesCount, statusCount],
+ [countriesCount, statusCount, rewards],
);
const activeFilters = useMemo(() => {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/settings/rewards/reward-settings.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/settings/rewards/reward-settings.tsx
index 94498f2975..037adafd8a 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/settings/rewards/reward-settings.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/settings/rewards/reward-settings.tsx
@@ -3,6 +3,7 @@
import useProgram from "@/lib/swr/use-program";
import useRewards from "@/lib/swr/use-rewards";
import type { RewardProps } from "@/lib/types";
+import { REWARD_EVENTS } from "@/lib/zod/schemas/rewards";
import { useRewardSheet } from "@/ui/partners/add-edit-reward-sheet";
import { ProgramRewardDescription } from "@/ui/partners/program-reward-description";
import { EventType } from "@dub/prisma/client";
@@ -13,35 +14,10 @@ import {
Popover,
useKeyboardShortcut,
} from "@dub/ui";
-import { CursorRays } from "@dub/ui/icons";
import { pluralize } from "@dub/utils";
-import { Gift, UserPlus } from "lucide-react";
+import { Gift } from "lucide-react";
import { useState } from "react";
-const events = {
- click: {
- icon: CursorRays,
- text: "Click reward",
- event: "click",
- shortcut: "C",
- eventName: "click",
- },
- lead: {
- icon: UserPlus,
- text: "Lead reward",
- event: "lead",
- shortcut: "L",
- eventName: "signup",
- },
- sale: {
- icon: MoneyBill,
- text: "Sale reward",
- event: "sale",
- shortcut: "S",
- eventName: "sale",
- },
-} as const;
-
export function RewardSettings() {
return (
<div className="flex flex-col gap-6">
@@ -164,7 +140,7 @@ const Reward = ({ reward }: { reward: RewardProps }) => {
reward,
});
- const Icon = events[reward.event].icon;
+ const Icon = REWARD_EVENTS[reward.event].icon;
return (
<>
@@ -208,11 +184,11 @@ const CreateRewardButton = () => {
});
useKeyboardShortcut(
- Object.values(events).map((type) => type.shortcut.toLowerCase()),
+ Object.values(REWARD_EVENTS).map((type) => type.shortcut.toLowerCase()),
(e) => {
setOpenPopover(false);
- const eventType = Object.values(events).find(
+ const eventType = Object.values(REWARD_EVENTS).find(
(type) => type.shortcut.toLowerCase() === e.key,
);
@@ -232,7 +208,7 @@ const CreateRewardButton = () => {
content={
<div className="w-full p-2 md:w-48">
<div className="grid gap-px">
- {Object.values(events).map((type) => (
+ {Object.values(REWARD_EVENTS).map((type) => (
<Button
key={type.event}
text={type.text}
diff --git a/apps/web/lib/zod/schemas/rewards.ts b/apps/web/lib/zod/schemas/rewards.ts
index 4f4fbfc0c2..e451eca5b7 100644
--- a/apps/web/lib/zod/schemas/rewards.ts
+++ b/apps/web/lib/zod/schemas/rewards.ts
@@ -1,4 +1,6 @@
import { CommissionType, EventType } from "@dub/prisma/client";
+import { CursorRays, MoneyBill } from "@dub/ui/icons";
+import { UserPlus } from "lucide-react";
import { z } from "zod";
import { getPaginationQuerySchema } from "./misc";
@@ -56,3 +58,27 @@ export const rewardPartnersQuerySchema = z
pageSize: 25,
}),
);
+
+export const REWARD_EVENTS = {
+ click: {
+ icon: CursorRays,
+ text: "Click reward",
+ event: "click",
+ shortcut: "C",
+ eventName: "click",
+ },
+ lead: {
+ icon: UserPlus,
+ text: "Lead reward",
+ event: "lead",
+ shortcut: "L",
+ eventName: "signup",
+ },
+ sale: {
+ icon: MoneyBill,
+ text: "Sale reward",
+ event: "sale",
+ shortcut: "S",
+ eventName: "sale",
+ },
+} as const;
diff --git a/apps/web/ui/partners/program-reward-description.tsx b/apps/web/ui/partners/program-reward-description.tsx
index 82219ce780..f88df16c6d 100644
--- a/apps/web/ui/partners/program-reward-description.tsx
+++ b/apps/web/ui/partners/program-reward-description.tsx
@@ -67,3 +67,30 @@ export function ProgramRewardDescription({
</>
);
}
+
+export function formatRewardDescription({
+ reward,
+}: {
+ reward?: RewardProps | null;
+}): string {
+ const parts: string[] = [];
+
+ if (reward && reward.amount > 0) {
+ let rewardText = `Earn ${constructRewardAmount({
+ amount: reward.amount,
+ type: reward.type,
+ })} for each ${reward.event}`;
+
+ if (reward.maxDuration === null) {
+ rewardText += ` for the customer's lifetime.`;
+ } else if (reward.maxDuration && reward.maxDuration > 1) {
+ rewardText += `, and again every month for ${reward.maxDuration} months.`;
+ } else {
+ rewardText += `.`;
+ }
+
+ parts.push(rewardText);
+ }
+
+ return parts.join(" ");
+}