The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add (temporary?) performance logic stuff
Tim Wilson2d7ff5db9b19
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 124e99b4d4..ec19afdb9d 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@@ -1,8 +1,10 @@import { mutatePrefix } from "@/lib/swr/mutate";import useWorkspace from "@/lib/swr/use-workspace";-import { BountyProps } from "@/lib/types";+import { BountyPerformanceLogic, BountyProps } from "@/lib/types";import {+ bountyPerformanceLogicSchema,createBountySchema,+ PERFORMANCE_CURRENCY_ACTIVITIES,SUBMISSION_REQUIREMENTS,} from "@/lib/zod/schemas/bounties";import { BountyLogic } from "@/ui/partners/bounties/bounty-logic";@@ -25,7 +27,7 @@ import {SmartDateTimePicker,Switch,} from "@dub/ui";-import { cn } from "@dub/utils";+import { cn, currencyFormatter } from "@dub/utils";import { Dispatch, SetStateAction, useEffect, useMemo, useState } from "react";import {Controller,@@ -84,6 +86,7 @@ function BountySheetContent({ setIsOpen }: BountySheetProps) {operator: "gte",value: undefined,},+ groupIds: null,},});@@ -93,6 +96,7 @@ function BountySheetContent({ setIsOpen }: BountySheetProps) {setValue,control,register,+ setError,formState: { errors },} = form;@@ -149,6 +153,42 @@ function BountySheetContent({ setIsOpen }: BountySheetProps) {return;}+ data.rewardAmount = data.rewardAmount * 100;++ if (data.type === "performance") {+ let performanceLogic: BountyPerformanceLogic | null = null;+ if (data.performanceLogic) {+ try {+ const isCurrency = PERFORMANCE_CURRENCY_ACTIVITIES.includes(+ data.performanceLogic.activity,+ );++ performanceLogic = bountyPerformanceLogicSchema.parse({+ ...data.performanceLogic,+ value: isCurrency+ ? data.performanceLogic.value * 100+ : data.performanceLogic.value,+ });++ data.name =+ `Earn ${currencyFormatter(data.rewardAmount / 100)} after generating ` ++ `${isCurrency ? `${currencyFormatter(performanceLogic.value)} in` : performanceLogic.value} ` ++ performanceLogic.activity;+ } catch (error) {+ console.error(error);+ setError("root.performanceLogic", {+ message: "Invalid performance logic",+ });+ toast.error(+ "Invalid performance logic. Please fix the errors and try again.",+ );+ return;+ }++ data.performanceLogic = performanceLogic;+ }+ }+await makeRequest("/api/bounties", {method: "POST",body: data,diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex ed4ce72443..a13fad679b 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -24,6 +24,7 @@ import {} from "./folder/constants";import { WEBHOOK_TRIGGER_DESCRIPTIONS } from "./webhook/constants";import {+ bountyPerformanceLogicSchema,BountySchema,BountySchemaExtended,BountySubmissionSchema,@@ -515,6 +516,10 @@ export type GroupProps = z.infer<typeof GroupSchema>;export type GroupExtendedProps = z.infer<typeof GroupSchemaExtended>;+export type BountyPerformanceLogic = z.infer<+ typeof bountyPerformanceLogicSchema+>;+export type BountyProps = z.infer<typeof BountySchema>;export type BountyExtendedProps = z.infer<typeof BountySchemaExtended>;diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.tsindex d5f514ef9b..99314a4330 100644--- a/apps/web/lib/zod/schemas/bounties.ts+++ b/apps/web/lib/zod/schemas/bounties.ts@@ -27,6 +27,12 @@ export const PERFORMANCE_CURRENCY_ACTIVITIES = ["revenue",];+export const bountyPerformanceLogicSchema = z.object({+ activity: z.enum(PERFORMANCE_ACTIVITIES),+ operator: z.enum(["gte"]).default("gte"),+ value: z.number().min(0, "Logic value must be at least 0"),+});+export const createBountySchema = z.object({name: z.string()@@ -47,13 +53,7 @@ export const createBountySchema = z.object({.min(0).max(2).nullish(),- performanceLogic: z- .object({- activity: z.enum(PERFORMANCE_ACTIVITIES),- operator: z.enum(["gte"]).default("gte"),- value: z.number().min(0, "Logic value must be at least 0"),- })- .nullish(),+ performanceLogic: bountyPerformanceLogicSchema.nullish(),groupIds: z.array(z.string()).nullable(),});