The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
address coderabbit feedback
Steven Tey5bc748f997f2
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/add-edit-bounty-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/add-edit-bounty-sheet.tsxindex ba93ba3ec4..54e937e638 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/add-edit-bounty-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/add-edit-bounty-sheet.tsx@@ -42,10 +42,9 @@ import {} from "@dub/ui";import { cn } from "@dub/utils";import { BountySubmissionFrequency } from "@prisma/client";-import { Dispatch, SetStateAction, useMemo, useState } from "react";+import { Dispatch, SetStateAction, useState } from "react";import { Controller, FormProvider } from "react-hook-form";import { BountyCriteria } from "./bounty-criteria";-import { BountyTypeUI } from "./bounty-form-context";import { useAddEditBountyForm } from "./use-add-edit-bounty-form";interface BountySheetProps {@@ -96,11 +95,8 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {type,bountyTypeUI,handleBountyTypeUIChange,- name,control,register,- setValue,- watch,errors,isDirty,validationError,@@ -114,19 +110,6 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {const showBountySocialMetricsUpsell =bountyTypeUI === "socialMetrics" && !canUseBountySocialMetrics;- const bountyTypeOptions = useMemo(- () =>- BOUNTY_TYPES.map((option) =>- option.key === "socialMetrics" && !canUseBountySocialMetrics- ? {- ...option,- description: `${option.description} (Advanced plan required)`,- }- : option,- ),- [canUseBountySocialMetrics],- );-return (<form onSubmit={onSubmit} className="flex h-full flex-col"><div className="sticky top-0 z-10 border-b border-neutral-200 bg-white">@@ -164,11 +147,9 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {Choose the type of bounty you want to create</p><CardSelector- options={bountyTypeOptions}+ options={BOUNTY_TYPES}value={bountyTypeUI}- onChange={(value: BountyTypeUI) =>- handleBountyTypeUIChange(value)- }+ onChange={handleBountyTypeUIChange}name="bounty-type"gridCols="3"/>@@ -560,7 +541,11 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {text={bounty ? "Update bounty" : "Create bounty"}className="h-9 w-fit"loading={isSubmitting}- disabled={Boolean(validationError) || (bounty && !isDirty)}+ disabled={+ Boolean(validationError) ||+ (bounty && !isDirty) ||+ showBountySocialMetricsUpsell+ }disabledTooltip={showBountySocialMetricsUpsell ? (<TooltipContentdiff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/use-add-edit-bounty-form.ts b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/use-add-edit-bounty-form.tsindex 386dc1d5c1..013e8ecc8f 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/use-add-edit-bounty-form.ts+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/use-add-edit-bounty-form.ts@@ -11,7 +11,10 @@ import { mutatePrefix } from "@/lib/swr/mutate";import { useApiMutation } from "@/lib/swr/use-api-mutation";import useWorkspace from "@/lib/swr/use-workspace";import { BountyProps } from "@/lib/types";-import { bountyPerformanceConditionSchema } from "@/lib/zod/schemas/bounties";+import {+ bountyPerformanceConditionSchema,+ bountySocialContentRequirementsSchema,+} from "@/lib/zod/schemas/bounties";import { formatDate } from "@dub/utils";import { BountySubmissionFrequency } from "@prisma/client";import { Dispatch, SetStateAction, useEffect, useMemo, useState } from "react";@@ -30,6 +33,20 @@ const ACCORDION_ITEMS = ["groups",];+const DEFAULT_SOCIAL_METRICS_CRITERIA = {+ platform: "youtube",+ metric: "views",+} as const;++const resolveSocialMetricsCriteria = (+ existing?: NonNullable<+ CreateBountyInputExtended["submissionRequirements"]+ >["socialMetrics"],+) => ({+ ...DEFAULT_SOCIAL_METRICS_CRITERIA,+ ...existing,+});+const isEmpty = (value: unknown) =>value === undefined || value === null || value === "";@@ -333,12 +350,13 @@ export function useAddEditBountyForm({setValue("submissionRequirements",{- socialMetrics:+ socialMetrics: resolveSocialMetricsCriteria(currentSubmissionRequirements &&- typeof currentSubmissionRequirements === "object" &&- "socialMetrics" in currentSubmissionRequirements+ typeof currentSubmissionRequirements === "object" &&+ currentSubmissionRequirements.socialMetrics? currentSubmissionRequirements.socialMetrics: undefined,+ ),},{ shouldDirty: true },);@@ -419,11 +437,7 @@ export function useAddEditBountyForm({}if ((rewardType ?? "flat") === "custom") {- const isSocialMetrics =- submissionRequirements &&- typeof submissionRequirements === "object" &&- "socialMetrics" in submissionRequirements;- if (!isSocialMetrics) {+ if (bountyTypeUI !== "socialMetrics") {if (!rewardDescription?.trim()) {return "Reward description is required for custom rewards.";}@@ -432,6 +446,27 @@ export function useAddEditBountyForm({}}}++ if (bountyTypeUI === "socialMetrics") {+ const socialMetrics = submissionRequirements?.socialMetrics;++ if (!socialMetrics) {+ return "Social metrics criteria are required.";+ }++ const parsed =+ bountySocialContentRequirementsSchema.safeParse(socialMetrics);++ if (!parsed.success) {+ return (+ parsed.error.issues[0]?.message ?? "Invalid social metrics criteria."+ );+ }++ if (!socialMetrics.minCount || socialMetrics.minCount <= 0) {+ return "Minimum metric count must be greater than 0.";+ }+ }}if (type === "performance") {