Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

update ProgramSheetAccordion

Steven Teyc27feab465a8
diff --git a/apps/web/ui/partners/add-edit-reward-sheet.tsx b/apps/web/ui/partners/add-edit-reward-sheet.tsx
index b3caf650f3..b5fcf737bd 100644
--- a/apps/web/ui/partners/add-edit-reward-sheet.tsx
+++ b/apps/web/ui/partners/add-edit-reward-sheet.tsx
@@ -324,49 +324,126 @@ function RewardSheetContent({
</Sheet.Close>
</div>
- <div className="flex-1 overflow-y-auto">
- <div className="space-y-0 p-6">
- <ProgramSheetAccordion
- type="multiple"
- defaultValue={defaultAccordionValues}
- >
- {isDefault && !hasDefaultReward && (
- <ProgramSheetAccordionItem value="reward-type">
- <ProgramSheetAccordionTrigger>
- Reward Type
- </ProgramSheetAccordionTrigger>
- <ProgramSheetAccordionContent>
+ <div className="flex-1 overflow-y-auto p-6">
+ <ProgramSheetAccordion
+ type="multiple"
+ defaultValue={defaultAccordionValues}
+ >
+ {isDefault && !hasDefaultReward && (
+ <ProgramSheetAccordionItem value="reward-type">
+ <ProgramSheetAccordionTrigger>
+ Reward Type
+ </ProgramSheetAccordionTrigger>
+ <ProgramSheetAccordionContent>
+ <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>
+ </ProgramSheetAccordionContent>
+ </ProgramSheetAccordionItem>
+ )}
+
+ {!isDefault && (
+ <ProgramSheetAccordionItem value="partner-eligibility">
+ <ProgramSheetAccordionTrigger>
+ Partner Eligibility
+ </ProgramSheetAccordionTrigger>
+ <ProgramSheetAccordionContent>
+ <div className="space-y-4">
<div className="grid grid-cols-1 gap-3 lg:grid-cols-2">
- {DEFAULT_REWARD_TYPES.map((rewardType) => {
- const isSelected = selectedEvent === rewardType.key;
+ {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={rewardType.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={rewardType.label}
+ value={partnerType.label}
className="hidden"
checked={isSelected}
+ disabled={isDisabled}
onChange={(e) => {
if (e.target.checked) {
- setValue("event", rewardType.key);
- setValue("type", "flat");
+ setSelectedPartnerType(partnerType.key);
+
+ if (partnerType.key === "all") {
+ setValue("partnerIds", null);
+ }
}
}}
/>
<div className="flex grow flex-col text-sm">
<span className="font-medium">
- {rewardType.label}
+ {partnerType.label}
</span>
- <span>{rewardType.description}</span>
+ <span>{partnerType.description}</span>
</div>
<CircleCheckFill
className={cn(
@@ -377,298 +454,218 @@ function RewardSheetContent({
</label>
);
- return labelContent;
+ return isDisabled ? (
+ <Tooltip
+ key={partnerType.label}
+ content={tooltipContent}
+ >
+ {labelContent}
+ </Tooltip>
+ ) : (
+ labelContent
+ );
})}
</div>
- </ProgramSheetAccordionContent>
- </ProgramSheetAccordionItem>
- )}
-
- {!isDefault && (
- <ProgramSheetAccordionItem value="partner-eligibility">
- <ProgramSheetAccordionTrigger>
- Partner Eligibility
- </ProgramSheetAccordionTrigger>
- <ProgramSheetAccordionContent>
- <div className="space-y-4">
- <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>
- {selectedPartnerType === "specific" && program?.id && (
- <div className="pt-4">
- <RewardPartnersTable
- partnerIds={partnerIds || []}
- setPartnerIds={(value: string[]) => {
- setValue("partnerIds", value);
- }}
- rewardPartners={rewardPartners || []}
- loading={isLoadingRewardPartners}
- />
- </div>
- )}
- </div>
- </ProgramSheetAccordionContent>
- </ProgramSheetAccordionItem>
- )}
-
- {selectedEvent === "sale" && (
- <ProgramSheetAccordionItem value="commission-structure">
- <ProgramSheetAccordionTrigger>
- Commission Structure
- </ProgramSheetAccordionTrigger>
- <ProgramSheetAccordionContent>
- <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",
- }}
- >
- <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>
- </AnimatedSizeContainer>
+ {selectedPartnerType === "specific" && program?.id && (
+ <div className="pt-4">
+ <RewardPartnersTable
+ partnerIds={partnerIds || []}
+ setPartnerIds={(value: string[]) => {
+ setValue("partnerIds", value);
+ }}
+ rewardPartners={rewardPartners || []}
+ loading={isLoadingRewardPartners}
+ />
</div>
- </div>
- </ProgramSheetAccordionContent>
- </ProgramSheetAccordionItem>
- )}
+ )}
+ </div>
+ </ProgramSheetAccordionContent>
+ </ProgramSheetAccordionItem>
+ )}
- <ProgramSheetAccordionItem value="payout-amount">
+ {selectedEvent === "sale" && (
+ <ProgramSheetAccordionItem value="commission-structure">
<ProgramSheetAccordionTrigger>
- Payout Amount
+ Commission Structure
</ProgramSheetAccordionTrigger>
<ProgramSheetAccordionContent>
<div className="space-y-4">
<p className="text-sm text-neutral-600">
- Set how much the affiliate will get rewarded
+ 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>
- {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 })}
+ <div
+ className={cn(
+ "transition-opacity duration-200",
+ commissionStructure === "recurring"
+ ? "h-auto"
+ : "h-0 opacity-0",
+ )}
+ aria-hidden={commissionStructure !== "recurring"}
+ {...{
+ inert: commissionStructure !== "recurring",
+ }}
>
- <option value="flat">Flat</option>
- <option value="percentage">Percentage</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>
+ </ProgramSheetAccordionContent>
+ </ProgramSheetAccordionItem>
+ )}
+ <ProgramSheetAccordionItem value="payout-amount">
+ <ProgramSheetAccordionTrigger>
+ Payout Amount
+ </ProgramSheetAccordionTrigger>
+ <ProgramSheetAccordionContent>
+ <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="amount"
+ htmlFor="type"
className="text-sm font-medium text-neutral-800"
>
- Amount{" "}
- {selectedEvent !== "sale" ? `per ${selectedEvent}` : ""}
+ Payout model
</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>
+ <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>
+ )}
+
+ <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>
- </ProgramSheetAccordionContent>
- </ProgramSheetAccordionItem>
- </ProgramSheetAccordion>
- </div>
+ </div>
+ </ProgramSheetAccordionContent>
+ </ProgramSheetAccordionItem>
+ </ProgramSheetAccordion>
</div>
<div className="flex items-center justify-between border-t border-neutral-200 p-5">
diff --git a/apps/web/ui/partners/program-sheet-accordion.tsx b/apps/web/ui/partners/program-sheet-accordion.tsx
index 6d860a6ebc..e59fdce6c4 100644
--- a/apps/web/ui/partners/program-sheet-accordion.tsx
+++ b/apps/web/ui/partners/program-sheet-accordion.tsx
@@ -8,7 +8,6 @@ import {
AnimatedSizeContainer,
} from "@dub/ui";
import { cn } from "@dub/utils";
-import { ChevronDown } from "lucide-react";
import * as React from "react";
// Program sheet specific accordion that completely overrides base styles
@@ -44,17 +43,14 @@ const ProgramSheetAccordionTrigger = React.forwardRef<
ref={ref}
className={cn(
// Completely custom trigger styling - force small text on all screen sizes, hide default icon
- "border-b border-neutral-200 bg-neutral-50 px-4 py-3 text-sm font-semibold text-neutral-800 transition-all hover:bg-neutral-100 data-[state=closed]:border-b-0 sm:text-sm [&>svg]:hidden",
+ "flex items-center justify-between border-b border-neutral-200 bg-neutral-50 px-4 py-3 text-sm font-semibold text-neutral-800",
+ "transition-all hover:bg-neutral-100 data-[state=closed]:border-b-0 sm:text-sm",
+ "[&>svg]:size-4 [&>svg]:text-neutral-400 [&[data-state=open]>svg]:rotate-180",
className,
)}
{...props}
>
- <div className="flex w-full items-center justify-between">
- <span>{children}</span>
- <div className="text-neutral-400 transition-transform duration-200 ease-out group-data-[state=open]:rotate-180">
- <ChevronDown className="h-4 w-4" />
- </div>
- </div>
+ <span>{children}</span>
</AccordionTrigger>
));
ProgramSheetAccordionTrigger.displayName = "ProgramSheetAccordionTrigger";