The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Reward drawer grouping
Marcus Farrell0c6eef9ffa64
diff --git a/apps/web/ui/partners/add-edit-discount-sheet.tsx b/apps/web/ui/partners/add-edit-discount-sheet.tsxindex 197f0e4ad5..e7aa68e59e 100644--- a/apps/web/ui/partners/add-edit-discount-sheet.tsx+++ b/apps/web/ui/partners/add-edit-discount-sheet.tsx@@ -480,7 +480,14 @@ export function DiscountSheet({nested?: boolean;}) {return (- <Sheet open={isOpen} onOpenChange={rest.setIsOpen} nested={nested}>+ <Sheet+ open={isOpen}+ onOpenChange={rest.setIsOpen}+ nested={nested}+ contentProps={{+ className: "z-50"+ }}+ ><DiscountSheetContent {...rest} /></Sheet>);diff --git a/apps/web/ui/partners/add-edit-reward-sheet.tsx b/apps/web/ui/partners/add-edit-reward-sheet.tsxindex 683399554f..5a402c6ffc 100644--- a/apps/web/ui/partners/add-edit-reward-sheet.tsx+++ b/apps/web/ui/partners/add-edit-reward-sheet.tsx@@ -39,6 +39,12 @@ import {import { toast } from "sonner";import { mutate } from "swr";import { z } from "zod";+import {+ ProgramDrawerAccordion,+ ProgramDrawerAccordionContent,+ ProgramDrawerAccordionItem,+ ProgramDrawerAccordionTrigger,+} from "./program-drawer-accordion";import { RewardPartnersTable } from "./reward-partners-table";interface RewardSheetProps {@@ -274,6 +280,22 @@ function RewardSheetContent({const displayPartners = !isDefault && selectedPartnerType === "specific";const canDeleteReward = reward && program?.defaultRewardId !== reward.id;+ // Determine which accordions should be open by default+ const getDefaultAccordionValues = () => {+ const baseValues = ["reward-type", "commission-structure", "payout"];++ // Only include partner-eligibility if:+ // 1. No existing reward (new creation), OR+ // 2. Existing reward with specific partners selected+ const shouldOpenPartnerEligibility = !reward || (reward && (reward.partnersCount ?? 0) > 0);++ if (!isDefault && shouldOpenPartnerEligibility) {+ baseValues.push("partner-eligibility");+ }++ return baseValues;+ };+return (<><form@@ -296,317 +318,338 @@ function RewardSheetContent({</div><div className="flex-1 overflow-y-auto">- <div className="flex flex-col gap-8 p-6">- {isDefault && !hasDefaultReward && (- <div className="grid grid-cols-1 space-y-4">- <label className="text-sm font-medium text-neutral-800">- Reward type- </label>- <div className="grid grid-cols-1 gap-3 lg:grid-cols-2">- {DEFAULT_REWARD_TYPES.map((rewardType) => {- const isSelected = selectedEvent === rewardType.key;-- const labelContent = (- <label- key={rewardType.label}- className={cn(- "relative flex w-full cursor-pointer items-start gap-0.5 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",- )}- >- <input- type="radio"- value={rewardType.label}- className="hidden"- checked={isSelected}- onChange={(e) => {- if (e.target.checked) {- setValue("event", rewardType.key);- setValue("type", "flat");- }- }}- />- <div className="flex grow flex-col text-sm">- <span className="font-medium">- {rewardType.label}- </span>- <span>{rewardType.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>- );-- return labelContent;- })}- </div>- </div>- )}+ <div className="p-6 space-y-0">+ <ProgramDrawerAccordion type="multiple" defaultValue={getDefaultAccordionValues()}>+ {isDefault && !hasDefaultReward && (+ <ProgramDrawerAccordionItem value="reward-type">+ <ProgramDrawerAccordionTrigger>+ Reward Type+ </ProgramDrawerAccordionTrigger>+ <ProgramDrawerAccordionContent>+ <div className="grid grid-cols-1 gap-3 lg:grid-cols-2">+ {DEFAULT_REWARD_TYPES.map((rewardType) => {+ const isSelected = selectedEvent === rewardType.key;++ const labelContent = (+ <label+ key={rewardType.label}+ className={cn(+ "relative flex w-full cursor-pointer items-start gap-0.5 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",+ )}+ >+ <input+ type="radio"+ value={rewardType.label}+ className="hidden"+ checked={isSelected}+ onChange={(e) => {+ if (e.target.checked) {+ setValue("event", rewardType.key);+ setValue("type", "flat");+ }+ }}+ />+ <div className="flex grow flex-col text-sm">+ <span className="font-medium">+ {rewardType.label}+ </span>+ <span>{rewardType.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>+ );- {!isDefault && (- <div className="grid grid-cols-1 gap-3 lg:grid-cols-2">- {PARTNER_TYPES.map((partnerType) => {- const isSelected = selectedPartnerType === partnerType.key;-- const isDisabled =- (partnerType.key === "all" &&- ((selectedEvent === "click" &&- hasProgramWideClickReward) ||- (selectedEvent === "lead" &&- hasProgramWideLeadReward) ||- (selectedEvent === "sale" &&- hasProgramWideSaleReward))) ||- !!reward;-- const tooltipContent = isDisabled- ? reward- ? "Partner type cannot be changed for existing rewards"- : `You can only have one program-wide ${selectedEvent} reward.`- : undefined;-- const labelContent = (- <label- key={partnerType.label}- className={cn(- "relative flex w-full cursor-pointer items-start gap-0.5 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",- (isDisabled || !!reward) &&- "cursor-not-allowed opacity-60 hover:bg-white",- )}- >- <input- type="radio"- value={partnerType.label}- className="hidden"- checked={isSelected}- disabled={isDisabled}- onChange={(e) => {- if (e.target.checked) {- setSelectedPartnerType(partnerType.key);-- if (partnerType.key === "all") {- setValue("partnerIds", null);- }- }- }}- />- <div className="flex grow flex-col text-sm">- <span className="font-medium">{partnerType.label}</span>- <span>{partnerType.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>- );-- return isDisabled ? (- <Tooltip key={partnerType.label} content={tooltipContent}>- {labelContent}- </Tooltip>- ) : (- labelContent- );- })}- </div>- )}+ return labelContent;+ })}+ </div>+ </ProgramDrawerAccordionContent>+ </ProgramDrawerAccordionItem>+ )}- {selectedEvent === "sale" && (- <div className="grid grid-cols-1 space-y-4">- <div>- <label className="text-sm font-medium text-neutral-800">- Commission structure- </label>- <p className="text-sm text-neutral-600">- Set how the affiliate will get rewarded- </p>- </div>- <div className="-m-1">- <AnimatedSizeContainer- height- transition={{ ease: "easeInOut", duration: 0.2 }}- >- <div className="flex flex-col gap-4 p-1">+ {!isDefault && (+ <ProgramDrawerAccordionItem value="partner-eligibility">+ <ProgramDrawerAccordionTrigger>+ Partner Eligibility+ </ProgramDrawerAccordionTrigger>+ <ProgramDrawerAccordionContent>+ <div className="space-y-4"><div className="grid grid-cols-1 gap-3 lg:grid-cols-2">- {COMMISSION_TYPES.map(- ({ label, description, value }) => {- const isSelected = value === commissionStructure;-- return (- <label- key={label}+ {PARTNER_TYPES.map((partnerType) => {+ const isSelected = selectedPartnerType === partnerType.key;++ const isDisabled =+ (partnerType.key === "all" &&+ ((selectedEvent === "click" &&+ hasProgramWideClickReward) ||+ (selectedEvent === "lead" &&+ hasProgramWideLeadReward) ||+ (selectedEvent === "sale" &&+ hasProgramWideSaleReward))) ||+ !!reward;++ const tooltipContent = isDisabled+ ? reward+ ? "Partner type cannot be changed for existing rewards"+ : `You can only have one program-wide ${selectedEvent} reward.`+ : undefined;++ const labelContent = (+ <label+ key={partnerType.label}+ className={cn(+ "relative flex w-full cursor-pointer items-start gap-0.5 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",+ (isDisabled || !!reward) &&+ "cursor-not-allowed opacity-60 hover:bg-white",+ )}+ >+ <input+ type="radio"+ value={partnerType.label}+ className="hidden"+ checked={isSelected}+ disabled={isDisabled}+ onChange={(e) => {+ if (e.target.checked) {+ setSelectedPartnerType(partnerType.key);++ if (partnerType.key === "all") {+ setValue("partnerIds", null);+ }+ }+ }}+ />+ <div className="flex grow flex-col text-sm">+ <span className="font-medium">{partnerType.label}</span>+ <span>{partnerType.description}</span>+ </div>+ <CircleCheckFillclassName={cn(- "relative flex w-full cursor-pointer items-start gap-0.5 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",+ "-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",)}- >- <input- type="radio"- value={value}- className="hidden"- checked={isSelected}- onChange={(e) => {- if (e.target.checked) {- setCommissionStructure(value);- setValue(- "maxDuration",- value === "recurring"- ? reward?.maxDuration || Infinity- : 0,- );- }- }}- />- <div className="flex grow flex-col text-sm">- <span className="font-medium">{label}</span>- <span>{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>- );- },- )}+ />+ </label>+ );++ return isDisabled ? (+ <Tooltip key={partnerType.label} content={tooltipContent}>+ {labelContent}+ </Tooltip>+ ) : (+ labelContent+ );+ })}</div>- <div- className={cn(- "transition-opacity duration-200",- commissionStructure === "recurring"- ? "h-auto"- : "h-0 opacity-0",- )}- aria-hidden={commissionStructure !== "recurring"}- {...{- inert: commissionStructure !== "recurring",- }}- >- <div>- <label- htmlFor="duration"- className="text-sm font-medium text-neutral-800"- >- Duration- </label>- <div className="relative mt-2 rounded-md shadow-sm">- <select- className="block w-full rounded-md border-neutral-300 text-neutral-900 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"- {...register("maxDuration", {- valueAsNumber: true,- })}+ {selectedPartnerType === "specific" && program?.id && (+ <div className="pt-4">+ <RewardPartnersTable+ partnerIds={partnerIds || []}+ setPartnerIds={(value: string[]) => {+ setValue("partnerIds", value);+ }}+ rewardPartners={rewardPartners || []}+ loading={isLoadingRewardPartners}+ />+ </div>+ )}+ </div>+ </ProgramDrawerAccordionContent>+ </ProgramDrawerAccordionItem>+ )}++ {selectedEvent === "sale" && (+ <ProgramDrawerAccordionItem value="commission-structure">+ <ProgramDrawerAccordionTrigger>+ Commission Structure+ </ProgramDrawerAccordionTrigger>+ <ProgramDrawerAccordionContent>+ <div className="space-y-4">+ <p className="text-sm text-neutral-600">+ Set how the affiliate will get rewarded+ </p>+ <div className="-m-1">+ <AnimatedSizeContainer+ height+ transition={{ ease: "easeInOut", duration: 0.2 }}+ >+ <div className="flex flex-col gap-4 p-1">+ <div className="grid grid-cols-1 gap-3 lg:grid-cols-2">+ {COMMISSION_TYPES.map(+ ({ label, description, value }) => {+ const isSelected = value === commissionStructure;++ return (+ <label+ key={label}+ className={cn(+ "relative flex w-full cursor-pointer items-start gap-0.5 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",+ )}+ >+ <input+ type="radio"+ value={value}+ className="hidden"+ checked={isSelected}+ onChange={(e) => {+ if (e.target.checked) {+ setCommissionStructure(value);+ setValue(+ "maxDuration",+ value === "recurring"+ ? reward?.maxDuration || Infinity+ : 0,+ );+ }+ }}+ />+ <div className="flex grow flex-col text-sm">+ <span className="font-medium">{label}</span>+ <span>{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>++ <div+ className={cn(+ "transition-opacity duration-200",+ commissionStructure === "recurring"+ ? "h-auto"+ : "h-0 opacity-0",+ )}+ aria-hidden={commissionStructure !== "recurring"}+ {...{+ inert: commissionStructure !== "recurring",+ }}>- {RECURRING_MAX_DURATIONS.filter(- (v) => v !== 0,- ).map((v) => (- <option value={v} key={v}>- {v} {pluralize("month", Number(v))}- </option>- ))}- <option value={Infinity}>Lifetime</option>- </select>+ <div>+ <label+ htmlFor="duration"+ className="text-sm font-medium text-neutral-800"+ >+ Duration+ </label>+ <div className="relative mt-2 rounded-md shadow-sm">+ <select+ className="block w-full rounded-md border-neutral-300 text-neutral-900 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"+ {...register("maxDuration", {+ valueAsNumber: true,+ })}+ >+ {RECURRING_MAX_DURATIONS.filter(+ (v) => v !== 0,+ ).map((v) => (+ <option value={v} key={v}>+ {v} {pluralize("month", Number(v))}+ </option>+ ))}+ <option value={Infinity}>Lifetime</option>+ </select>+ </div>+ </div>+ </div></div>- </div>+ </AnimatedSizeContainer></div></div>- </AnimatedSizeContainer>- </div>- </div>- )}+ </ProgramDrawerAccordionContent>+ </ProgramDrawerAccordionItem>+ )}- <div className="grid grid-cols-1 space-y-4">- <div>- <label className="text-sm font-medium text-neutral-800">+ <ProgramDrawerAccordionItem value="payout">+ <ProgramDrawerAccordionTrigger>Payout- </label>- <p className="text-sm text-neutral-600">- Set how much the affiliate will get rewarded- </p>- </div>+ </ProgramDrawerAccordionTrigger>+ <ProgramDrawerAccordionContent>+ <div className="space-y-4">+ <p className="text-sm text-neutral-600">+ Set how much the affiliate will get rewarded+ </p>++ {selectedEvent === "sale" && (+ <div>+ <label+ htmlFor="type"+ className="text-sm font-medium text-neutral-800"+ >+ Payout model+ </label>+ <div className="relative mt-2 rounded-md shadow-sm">+ <select+ className="block w-full rounded-md border-neutral-300 text-neutral-900 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"+ {...register("type", { required: true })}+ >+ <option value="flat">Flat</option>+ <option value="percentage">Percentage</option>+ </select>+ </div>+ </div>+ )}- {selectedEvent === "sale" && (- <div>- <label- htmlFor="type"- className="text-sm font-medium text-neutral-800"- >- Payout model- </label>- <div className="relative mt-2 rounded-md shadow-sm">- <select- className="block w-full rounded-md border-neutral-300 text-neutral-900 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"- {...register("type", { required: true })}- >- <option value="flat">Flat</option>- <option value="percentage">Percentage</option>- </select>+ <div>+ <label+ htmlFor="amount"+ className="text-sm font-medium text-neutral-800"+ >+ Amount{" "}+ {selectedEvent !== "sale" ? `per ${selectedEvent}` : ""}+ </label>+ <div className="relative mt-2 rounded-md shadow-sm">+ {type === "flat" && (+ <span className="absolute inset-y-0 left-0 flex items-center pl-3 text-sm text-neutral-400">+ $+ </span>+ )}+ <input+ className={cn(+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",+ errors.amount &&+ "border-red-600 focus:border-red-500 focus:ring-red-600",+ type === "flat" ? "pl-6 pr-12" : "pr-7",+ )}+ {...register("amount", {+ required: true,+ valueAsNumber: true,+ min: 0,+ max: type === "flat" ? 1000 : 100,+ onChange: handleMoneyInputChange,+ })}+ onKeyDown={handleMoneyKeyDown}+ />+ <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-sm text-neutral-400">+ {type === "flat" ? "USD" : "%"}+ </span>+ </div>+ </div></div>- </div>- )}+ </ProgramDrawerAccordionContent>+ </ProgramDrawerAccordionItem>- <div>- <label- htmlFor="amount"- className="text-sm font-medium text-neutral-800"- >- Amount{" "}- {selectedEvent !== "sale" ? `per ${selectedEvent}` : ""}- </label>- <div className="relative mt-2 rounded-md shadow-sm">- {type === "flat" && (- <span className="absolute inset-y-0 left-0 flex items-center pl-3 text-sm text-neutral-400">- $- </span>- )}- <input- className={cn(- "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",- errors.amount &&- "border-red-600 focus:border-red-500 focus:ring-red-600",- type === "flat" ? "pl-6 pr-12" : "pr-7",- )}- {...register("amount", {- required: true,- valueAsNumber: true,- min: 0,- max: type === "flat" ? 1000 : 100,- onChange: handleMoneyInputChange,- })}- onKeyDown={handleMoneyKeyDown}- />- <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-sm text-neutral-400">- {type === "flat" ? "USD" : "%"}- </span>- </div>- </div>- </div>- {displayPartners && program?.id && (- <RewardPartnersTable- partnerIds={partnerIds || []}- setPartnerIds={(value: string[]) => {- setValue("partnerIds", value);- }}- rewardPartners={rewardPartners || []}- loading={isLoadingRewardPartners}- />- )}+ </ProgramDrawerAccordion></div></div>@@ -753,7 +796,14 @@ export function RewardSheet({nested?: boolean;}) {return (- <Sheet open={isOpen} onOpenChange={rest.setIsOpen} nested={nested}>+ <Sheet+ open={isOpen}+ onOpenChange={rest.setIsOpen}+ nested={nested}+ contentProps={{+ className: "z-50"+ }}+ ><RewardSheetContent {...rest} /></Sheet>);diff --git a/apps/web/ui/partners/program-drawer-accordion.tsx b/apps/web/ui/partners/program-drawer-accordion.tsxnew file mode 100644index 0000000000..3134799d5d--- /dev/null+++ b/apps/web/ui/partners/program-drawer-accordion.tsx@@ -0,0 +1,81 @@+"use client";++import { cn } from "@dub/utils";+import {+ Accordion,+ AccordionContent,+ AccordionItem,+ AccordionTrigger,+} from "@dub/ui";+import { ChevronDown } from "lucide-react";+import * as React from "react";++// Program drawer specific accordion that completely overrides base styles+const ProgramDrawerAccordion = React.forwardRef<+ React.ElementRef<typeof Accordion>,+ React.ComponentPropsWithoutRef<typeof Accordion>+>((props, ref) => (+ <Accordion ref={ref} {...props} />+));+ProgramDrawerAccordion.displayName = "ProgramDrawerAccordion";++const ProgramDrawerAccordionItem = React.forwardRef<+ React.ElementRef<typeof AccordionItem>,+ React.ComponentPropsWithoutRef<typeof AccordionItem>+>(({ className, ...props }, ref) => (+ <div+ className={cn(+ // Completely custom card styling - not extending AccordionItem+ "border border-neutral-200 rounded-lg mb-3 bg-white overflow-hidden last:mb-0",+ className,+ )}+ >+ <AccordionItem+ ref={ref}+ className="border-none py-0 m-0"+ {...props}+ />+ </div>+));+ProgramDrawerAccordionItem.displayName = "ProgramDrawerAccordionItem";++const ProgramDrawerAccordionTrigger = React.forwardRef<+ React.ElementRef<typeof AccordionTrigger>,+ React.ComponentPropsWithoutRef<typeof AccordionTrigger> & {+ children: React.ReactNode;+ }+>(({ className, children, ...props }, ref) => (+ <AccordionTrigger+ ref={ref}+ className={cn(+ // Completely custom trigger styling - force small text on all screen sizes+ "px-4 py-3 text-sm sm:text-sm font-semibold text-neutral-800 bg-neutral-50 hover:bg-neutral-100 border-b border-neutral-200 data-[state=closed]:border-b-0 transition-all [&>svg]:h-4 [&>svg]:w-4 [&>svg]:text-neutral-400",+ className,+ )}+ variant="chevron"+ {...props}+ >+ {children}+ </AccordionTrigger>+));+ProgramDrawerAccordionTrigger.displayName = "ProgramDrawerAccordionTrigger";++const ProgramDrawerAccordionContent = React.forwardRef<+ React.ElementRef<typeof AccordionContent>,+ React.ComponentPropsWithoutRef<typeof AccordionContent>+>(({ className, children, ...props }, ref) => (+ <AccordionContent+ ref={ref}+ className={cn(+ // Override default chunky animations with smooth transitions+ "px-4 py-4 bg-white overflow-hidden transition-all duration-500 ease-in-out data-[state=closed]:animate-none data-[state=open]:animate-none",+ className,+ )}+ {...props}+ >+ {children}+ </AccordionContent>+));+ProgramDrawerAccordionContent.displayName = "ProgramDrawerAccordionContent";++export { ProgramDrawerAccordion, ProgramDrawerAccordionContent, ProgramDrawerAccordionItem, ProgramDrawerAccordionTrigger };\ No newline at end of file