The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Refactor bounty attribute labels and name generation
Kiran K2015e68254e3
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsxindex 938cd202b6..8b60b4ad04 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsx@@ -12,11 +12,7 @@ import { BountyCard, BountyCardSkeleton } from "./bounty-card";export function BountiesPageClient() {const { programSlug } = useParams();- const {- data: bounties,- isLoading,- error,- } = useSWR<BountyWithPartnerDataProps[]>(+ const { data: bounties, isLoading } = useSWR<BountyWithPartnerDataProps[]>(`/api/partner-profile/programs/${programSlug}/bounties`,fetcher,{@@ -45,6 +41,7 @@ export function BountiesPageClient() {<ahref="https://dub.co/help/article/bounties"target="_blank"+ rel="noopener noreferrer"className="hover:text-content-default underline sm:whitespace-nowrap">Learn more about bountiesdiff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsxindex a351b4102a..b986d9c16e 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx@@ -1,15 +1,13 @@"use client";import { approveBountySubmissionAction } from "@/lib/actions/partners/approve-bounty-submission";-import {- WORKFLOW_TRIGGER_ATTRIBUTE_LABELS,- isCurrencyAttribute,-} from "@/lib/api/workflows/utils";+import { isCurrencyAttribute } from "@/lib/api/workflows/utils";import { mutatePrefix } from "@/lib/swr/mutate";import useBounty from "@/lib/swr/use-bounty";import useGroups from "@/lib/swr/use-groups";import useWorkspace from "@/lib/swr/use-workspace";import { BountySubmissionProps } from "@/lib/types";+import { WORKFLOW_ATTRIBUTE_LABELS } from "@/lib/zod/schemas/workflows";import { useConfirmModal } from "@/ui/modals/confirm-modal";import { GroupColorCircle } from "@/ui/partners/groups/group-color-circle";import { PartnerRowItem } from "@/ui/partners/partner-row-item";@@ -143,7 +141,7 @@ export function BountySubmissionsTable() {: "leads";const metricColumnLabel = performanceCondition?.attribute- ? WORKFLOW_TRIGGER_ATTRIBUTE_LABELS[performanceCondition.attribute]+ ? WORKFLOW_ATTRIBUTE_LABELS[performanceCondition.attribute]: "Progress";const { table, ...tableProps } = useTable({diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsxindex c5be2f6dc8..15a353e08d 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx@@ -7,11 +7,11 @@ import {BountySubmissionRequirement,} from "@/lib/types";import { createBountySchema } from "@/lib/zod/schemas/bounties";+import { workflowConditionSchema } from "@/lib/zod/schemas/workflows";import {- WORKFLOW_ATTRIBUTE_LABELS,- workflowConditionSchema,-} from "@/lib/zod/schemas/workflows";-import { BountyLogic } from "@/ui/partners/bounties/bounty-logic";+ BountyLogic,+ generateBountyName,+} from "@/ui/partners/bounties/bounty-logic";import { GroupsMultiSelect } from "@/ui/partners/groups/groups-multi-select";import {ProgramSheetAccordion,@@ -32,7 +32,7 @@ import {Switch,useRouterStuff,} from "@dub/ui";-import { cn, currencyFormatter } from "@dub/utils";+import { cn } from "@dub/utils";import { Dispatch, SetStateAction, useEffect, useMemo, useState } from "react";import {Controller,@@ -216,11 +216,10 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {data.performanceCondition = condition;- // Generate a name- data.name =- `Earn ${currencyFormatter(data.rewardAmount / 100)} after generating ` +- `${isCurrency ? `${currencyFormatter(condition.value / 100)} in` : condition.value} ` +- WORKFLOW_ATTRIBUTE_LABELS[condition.attribute];+ data.name = generateBountyName({+ rewardAmount: data.rewardAmount,+ condition,+ });} else if (type === "submission") {data.performanceCondition = null;}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsxindex 1d59fee483..966e2532dd 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx@@ -44,6 +44,7 @@ export function BountyList() {<ahref="https://dub.co/help/article/bounties"target="_blank"+ rel="noopener noreferrer"className="hover:text-content-default underline sm:whitespace-nowrap">Learn more about bountiesdiff --git a/apps/web/lib/api/workflows/utils.ts b/apps/web/lib/api/workflows/utils.tsindex a08093c984..61741b354e 100644--- a/apps/web/lib/api/workflows/utils.ts+++ b/apps/web/lib/api/workflows/utils.ts@@ -1,11 +1,4 @@import { WorkflowConditionAttribute } from "@/lib/types";-export const WORKFLOW_TRIGGER_ATTRIBUTE_LABELS = {- totalLeads: "Leads",- totalConversions: "Conversions",- totalSaleAmount: "Revenue",- totalCommission: "Commissions",-} as const;-export const isCurrencyAttribute = (activity: WorkflowConditionAttribute) =>activity === "totalCommission" || activity === "totalSaleAmount";diff --git a/apps/web/lib/zod/schemas/workflows.ts b/apps/web/lib/zod/schemas/workflows.tsindex d3c820bb5f..02e12e1d51 100644--- a/apps/web/lib/zod/schemas/workflows.ts+++ b/apps/web/lib/zod/schemas/workflows.ts@@ -17,10 +17,10 @@ export const WORKFLOW_ATTRIBUTE_LABELS: Record<WorkflowConditionAttribute,string> = {- totalLeads: "total leads",- totalConversions: "total conversions",- totalSaleAmount: "total sale amount",- totalCommission: "total commission",+ totalLeads: "Leads",+ totalConversions: "Conversions",+ totalSaleAmount: "Revenue",+ totalCommission: "Commissions",} as const;export const WORKFLOW_ATTRIBUTE_TRIGGER_MAP: Record<diff --git a/apps/web/ui/partners/bounties/bounty-logic.tsx b/apps/web/ui/partners/bounties/bounty-logic.tsxindex 30c8db95cf..a1fc1c0d3f 100644--- a/apps/web/ui/partners/bounties/bounty-logic.tsx+++ b/apps/web/ui/partners/bounties/bounty-logic.tsx@@ -1,9 +1,7 @@import { isCurrencyAttribute } from "@/lib/api/workflows/utils";import { handleMoneyInputChange, handleMoneyKeyDown } from "@/lib/form-utils";-import {- WORKFLOW_ATTRIBUTES,- WORKFLOW_ATTRIBUTE_LABELS,-} from "@/lib/zod/schemas/workflows";+import { WorkflowCondition, WorkflowConditionAttribute } from "@/lib/types";+import { WORKFLOW_ATTRIBUTES } from "@/lib/zod/schemas/workflows";import {InlineBadgePopover,InlineBadgePopoverContext,@@ -15,6 +13,30 @@ import { useAddEditBountyForm } from "app/app.dub.co/(dashboard)/[slug]/(ee)/proimport { useContext } from "react";import { Controller } from "react-hook-form";+const WORKFLOW_ATTRIBUTE_LABELS: Record<WorkflowConditionAttribute, string> = {+ totalLeads: "total leads",+ totalConversions: "total conversions",+ totalSaleAmount: "total sale amount",+ totalCommission: "total commission",+} as const;++export const generateBountyName = ({+ rewardAmount,+ condition,+}: {+ rewardAmount: number;+ condition: WorkflowCondition;+}) => {+ const isCurrency = isCurrencyAttribute(condition.attribute);+ const rewardAmountFormatted = currencyFormatter(rewardAmount / 100);+ const attributeLabel = WORKFLOW_ATTRIBUTE_LABELS[condition.attribute];+ const valueFormatted = isCurrency+ ? `${currencyFormatter(condition.value / 100)} in`+ : `${condition.value}`;++ return `Earn ${rewardAmountFormatted} after generating ${valueFormatted} ${attributeLabel}`;+};+export function BountyLogic({ className }: { className?: string }) {const { control, watch } = useAddEditBountyForm();diff --git a/apps/web/ui/partners/bounties/bounty-performance.tsx b/apps/web/ui/partners/bounties/bounty-performance.tsxindex 60ed743ec0..a835e5eefa 100644--- a/apps/web/ui/partners/bounties/bounty-performance.tsx+++ b/apps/web/ui/partners/bounties/bounty-performance.tsx@@ -1,8 +1,6 @@-import {- WORKFLOW_TRIGGER_ATTRIBUTE_LABELS,- isCurrencyAttribute,-} from "@/lib/api/workflows/utils";+import { isCurrencyAttribute } from "@/lib/api/workflows/utils";import { BountyWithPartnerDataProps } from "@/lib/types";+import { WORKFLOW_ATTRIBUTE_LABELS } from "@/lib/zod/schemas/workflows";import { currencyFormatter, nFormatter } from "@dub/utils";export function BountyPerformance({@@ -36,9 +34,7 @@ export function BountyPerformance({: nFormatter(target);const metricLabel =- WORKFLOW_TRIGGER_ATTRIBUTE_LABELS[- performanceCondition.attribute- ].toLowerCase();+ WORKFLOW_ATTRIBUTE_LABELS[performanceCondition.attribute].toLowerCase();return (<div className="flex flex-col gap-2">