The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
wip
Kiran K62066a011a19
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/route.tsnew file mode 100644index 0000000000..a142bab755--- /dev/null+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts@@ -0,0 +1,17 @@+import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";+import { withWorkspace } from "@/lib/auth";+import { NextResponse } from "next/server";++// PATCH /api/bounties/[bountyId] - update a bounty+export const PATCH = withWorkspace(async ({ workspace, searchParams }) => {+ const programId = getDefaultProgramIdOrThrow(workspace);++ return NextResponse.json({});+});++// DELETE /api/bounties/[bountyId] - delete a bounty+export const DELETE = withWorkspace(async ({ workspace, searchParams }) => {+ const programId = getDefaultProgramIdOrThrow(workspace);++ return NextResponse.json({});+});diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.tsnew file mode 100644index 0000000000..bca2df24fc--- /dev/null+++ b/apps/web/app/(ee)/api/bounties/route.ts@@ -0,0 +1,17 @@+import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";+import { withWorkspace } from "@/lib/auth";+import { NextResponse } from "next/server";++// GET /api/bounties - get all bounties for a program+export const GET = withWorkspace(async ({ workspace, searchParams }) => {+ const programId = getDefaultProgramIdOrThrow(workspace);++ return NextResponse.json({});+});++// POST /api/bounties - create a bounty+export const POST = withWorkspace(async ({ workspace, searchParams }) => {+ const programId = getDefaultProgramIdOrThrow(workspace);++ return NextResponse.json({});+});diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/create-bounty-button.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/create-bounty-button.tsxnew file mode 100644index 0000000000..ffcb467f6d--- /dev/null+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/create-bounty-button.tsx@@ -0,0 +1,26 @@+"use client";++import { Button, useKeyboardShortcut } from "@dub/ui";+import { useCreateBountySheet } from "./create-bounty-sheet";++export function CreateBountyButton() {+ const { createBountySheet, setIsOpen: setShowCreateBountySheet } =+ useCreateBountySheet({+ nested: false,+ partnerId: "",+ });++ useKeyboardShortcut("c", () => setShowCreateBountySheet(true));++ return (+ <>+ {createBountySheet}+ <Button+ type="button"+ onClick={() => setShowCreateBountySheet(true)}+ text="Create bounty"+ shortcut="C"+ />+ </>+ );+}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/create-bounty-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/create-bounty-sheet.tsxnew file mode 100644index 0000000000..48e36e2354--- /dev/null+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/create-bounty-sheet.tsx@@ -0,0 +1,170 @@+import useWorkspace from "@/lib/swr/use-workspace";+import { createBountySchema } from "@/lib/zod/schemas/bounties";+import {+ ProgramSheetAccordion,+ ProgramSheetAccordionContent,+ ProgramSheetAccordionItem,+ ProgramSheetAccordionTrigger,+} from "@/ui/partners/program-sheet-accordion";+import { X } from "@/ui/shared/icons";+import { Button, CardSelector, CardSelectorOption, Sheet } from "@dub/ui";+import { Dispatch, SetStateAction, useMemo, useState } from "react";+import { useForm } from "react-hook-form";+import { toast } from "sonner";+import { z } from "zod";++interface CreateBountySheetProps {+ setIsOpen: Dispatch<SetStateAction<boolean>>;+ partnerId?: string;+}++type FormData = z.infer<typeof createBountySchema>;++const BOUNTY_TYPES: CardSelectorOption[] = [+ {+ key: "performance",+ label: "Performance-based",+ description: "Reward for reaching milestones",+ },+ {+ key: "submission",+ label: "Submission",+ description: "Reward for task completion",+ },+];++function CreateBountySheetContent({+ setIsOpen,+ partnerId: initialPartnerId,+}: CreateBountySheetProps) {+ const { id: workspaceId, defaultProgramId } = useWorkspace();++ const [openAccordions, setOpenAccordions] = useState<string[]>([+ "partner-and-type",+ ]);++ const {+ register,+ handleSubmit,+ watch,+ setValue,+ formState: { errors },+ control,+ } = useForm<FormData>({+ defaultValues: {+ type: "performance",+ },+ });++ const onSubmit = async (data: FormData) => {+ if (!workspaceId || !defaultProgramId) {+ toast.error("Please fill all required fields.");+ return;+ }+ };++ const shouldDisableSubmit = useMemo(() => {+ //+ }, []);++ return (+ <form onSubmit={handleSubmit(onSubmit)} className="flex h-full flex-col">+ <div className="sticky top-0 z-10 border-b border-neutral-200 bg-white">+ <div className="flex h-16 items-center justify-between px-6 py-4">+ <Sheet.Title className="text-lg font-semibold">+ Create bounty+ </Sheet.Title>+ <Sheet.Close asChild>+ <Button+ variant="outline"+ icon={<X className="size-5" />}+ className="h-auto w-fit p-1"+ />+ </Sheet.Close>+ </div>+ </div>++ <div className="flex-1 overflow-y-auto">+ <div className="p-6">+ <ProgramSheetAccordion+ type="multiple"+ value={openAccordions}+ onValueChange={setOpenAccordions}+ className="space-y-6"+ >+ <ProgramSheetAccordionItem value="partner-and-type">+ <ProgramSheetAccordionTrigger>+ Bounty type+ </ProgramSheetAccordionTrigger>+ <ProgramSheetAccordionContent>+ <div className="space-y-4">+ <p className="text-sm text-neutral-600">+ Set how the bounty will be completed+ </p>+ <CardSelector+ options={BOUNTY_TYPES}+ value={watch("type")}+ onChange={(value: FormData["type"]) =>+ setValue("type", value)+ }+ name="bounty-type"+ />+ </div>+ </ProgramSheetAccordionContent>+ </ProgramSheetAccordionItem>+ </ProgramSheetAccordion>+ </div>+ </div>++ <div className="sticky bottom-0 z-10 border-t border-neutral-200 bg-white">+ <div className="flex items-center justify-end gap-2 p-5">+ <Button+ type="button"+ variant="secondary"+ onClick={() => setIsOpen(false)}+ text="Cancel"+ className="w-fit"+ // disabled={isPending}+ />++ <Button+ type="submit"+ variant="primary"+ text="Create bounty"+ className="w-fit"+ // loading={isPending}+ // disabled={shouldDisableSubmit}+ />+ </div>+ </div>+ </form>+ );+}++export function CreateBountySheet({+ isOpen,+ nested,+ ...rest+}: CreateBountySheetProps & {+ isOpen: boolean;+ nested?: boolean;+}) {+ return (+ <Sheet open={isOpen} onOpenChange={rest.setIsOpen} nested={nested}>+ <CreateBountySheetContent {...rest} />+ </Sheet>+ );+}++export function useCreateBountySheet(+ props: { nested?: boolean } & Omit<CreateBountySheetProps, "setIsOpen">,+) {+ const [isOpen, setIsOpen] = useState(false);++ return {+ createBountySheet: (+ <CreateBountySheet setIsOpen={setIsOpen} isOpen={isOpen} {...props} />+ ),+ setIsOpen,+ };+}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/page.tsxnew file mode 100644index 0000000000..f95d6ce366--- /dev/null+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/page.tsx@@ -0,0 +1,24 @@+"use client";++import { PageContent } from "@/ui/layout/page-content";+import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";+import { CommissionTable } from "../commissions/commission-table";+import { CreateBountyButton } from "./create-bounty-button";++export default function ProgramCommissions() {+ return (+ <PageContent+ title="Bounties"+ titleInfo={{+ title:+ "Learn how partner commissions work on Dub, and how to create manual commissions or clawbacks.",+ href: "https://dub.co/help/article/partner-commissions-clawbacks",+ }}+ controls={<CreateBountyButton />}+ >+ <PageWidthWrapper>+ <CommissionTable />+ </PageWidthWrapper>+ </PageContent>+ );+}diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.tsnew file mode 100644index 0000000000..b4a9d33772--- /dev/null+++ b/apps/web/lib/zod/schemas/bounties.ts@@ -0,0 +1,10 @@+import { BountyType } from "@dub/prisma/client";+import { z } from "zod";+import { parseDateSchema } from "./utils";++export const createBountySchema = z.object({+ type: z.nativeEnum(BountyType),+ startsAt: parseDateSchema,+ endsAt: parseDateSchema.nullish(),+ rewardAmount: z.number().min(0),+});diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsxindex c81e8ef152..76a39939c3 100644--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx@@ -31,6 +31,7 @@ import {Users6,Webhook,} from "@dub/ui/icons";+import { Trophy } from "lucide-react";import { Session } from "next-auth";import { useSession } from "next-auth/react";import { useParams, usePathname } from "next/navigation";@@ -243,6 +244,17 @@ const NAV_AREAS: SidebarNavAreas<SidebarNavData> = {},],},+ {+ name: "Engagement",+ items: [+ {+ name: "Bounties",+ icon: Trophy,+ href: `/${slug}/program/bounties`,+ badge: "New",+ },+ ],+ },{name: "Configuration",items: [diff --git a/packages/prisma/schema/bounty.prisma b/packages/prisma/schema/bounty.prismaindex 448ac474bc..b31e9977fa 100644--- a/packages/prisma/schema/bounty.prisma+++ b/packages/prisma/schema/bounty.prisma@@ -21,8 +21,8 @@ model Bounty {name String?description String? @db.Texttype BountyType- startAt DateTime- endAt DateTime?+ startsAt DateTime+ endsAt DateTime?rewardAmount Int @default(0)submissionRequirements Json?createdAt DateTime @default(now())diff --git a/packages/ui/src/card-selector.tsx b/packages/ui/src/card-selector.tsxnew file mode 100644index 0000000000..ccd9fbee2b--- /dev/null+++ b/packages/ui/src/card-selector.tsx@@ -0,0 +1,114 @@+"use client";++import { cn } from "@dub/utils";+import { ReactNode } from "react";+import { AnimatedSizeContainer } from "./animated-size-container";+import { CircleCheckFill } from "./icons";++export interface CardSelectorOption {+ key: string;+ label: string;+ description: string;+ icon?: ReactNode;+}++export interface CardSelectorProps {+ options: CardSelectorOption[];+ value?: string;+ onChange?: (value: string) => void;+ className?: string;+ gridCols?: "1" | "2" | "3";+ name?: string;+ disabled?: boolean;+ animated?: boolean;+}++export function CardSelector({+ options,+ value,+ onChange,+ className,+ gridCols = "2",+ name,+ disabled = false,+ animated = true,+}: CardSelectorProps) {+ const gridClass = {+ "1": "grid-cols-1",+ "2": "grid-cols-1 lg:grid-cols-2",+ "3": "grid-cols-1 md:grid-cols-2 lg:grid-cols-3",+ }[gridCols];++ const content = (+ <div className={cn("grid gap-3", gridClass)}>+ {options.map(({ key, label, description, icon }) => {+ const isSelected = value === key;++ return (+ <label+ key={key}+ className={cn(+ "relative flex w-full cursor-pointer items-start gap-3 rounded-md border border-neutral-200 bg-white p-3 text-neutral-600 hover:bg-neutral-50",+ "transition-all duration-150",+ isSelected &&+ "border-black bg-neutral-50 text-neutral-900 ring-1 ring-black",+ disabled && "cursor-not-allowed opacity-50",+ className+ )}+ >+ <input+ type="radio"+ name={name}+ value={key}+ className="hidden"+ checked={isSelected}+ disabled={disabled}+ onChange={(e) => {+ if (e.target.checked && onChange) {+ onChange(key);+ }+ }}+ />++ {icon && (+ <div className="flex-shrink-0 pt-0.5">+ {icon}+ </div>+ )}++ <div className="flex grow flex-col">+ <span className="text-sm font-semibold text-neutral-900">+ {label}+ </span>+ <span className="text-xs text-neutral-600">+ {description}+ </span>+ </div>++ <CircleCheckFill+ className={cn(+ "-mr-px -mt-px flex size-4 scale-75 items-center justify-center rounded-full opacity-0 transition-[transform,opacity] duration-150",+ isSelected && "scale-100 opacity-100",+ )}+ />+ </label>+ );+ })}+ </div>+ );++ if (!animated) {+ return content;+ }++ return (+ <div className="-m-1">+ <AnimatedSizeContainer+ height+ transition={{ ease: "easeInOut", duration: 0.2 }}+ >+ <div className="p-1">{content}</div>+ </AnimatedSizeContainer>+ </div>+ );+}diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsxindex 440510fd26..f18175dc21 100644--- a/packages/ui/src/index.tsx+++ b/packages/ui/src/index.tsx@@ -8,6 +8,7 @@ export * from "./avatar";export * from "./badge";export * from "./button";export * from "./card-list";+export * from "./card-selector";export * from "./carousel";export * from "./checkbox";export * from "./combobox";