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.

add excludedPartnerIds

Kiran K86a6497be630
diff --git a/apps/web/lib/zod/schemas/rewards.ts b/apps/web/lib/zod/schemas/rewards.ts
index 1f198d04e4..e158c041d7 100644
--- a/apps/web/lib/zod/schemas/rewards.ts
+++ b/apps/web/lib/zod/schemas/rewards.ts
@@ -36,6 +36,7 @@ export const createOrUpdateRewardSchema = z.object({
maxAmount: z.number().nullish(),
isDefault: z.boolean(),
partnerIds: z.array(z.string()).nullish(),
+ excludedPartnerIds: z.array(z.string()).nullish(),
});
export const createRewardSchema = createOrUpdateRewardSchema.superRefine(
diff --git a/apps/web/ui/partners/add-edit-reward-sheet.tsx b/apps/web/ui/partners/add-edit-reward-sheet.tsx
index 4d7a572bda..f3afcc25c0 100644
--- a/apps/web/ui/partners/add-edit-reward-sheet.tsx
+++ b/apps/web/ui/partners/add-edit-reward-sheet.tsx
@@ -95,6 +95,7 @@ function RewardSheetContent({
maxAmount: reward?.maxAmount ? reward.maxAmount / 100 : null,
isDefault: isDefault || false,
partnerIds: null,
+ excludedPartnerIds: null,
},
});
@@ -106,10 +107,11 @@ function RewardSheetContent({
}
}, [reward]);
- const [amount, type, partnerIds = []] = watch([
+ const [amount, type, partnerIds = [], excludedPartnerIds = []] = watch([
"amount",
"type",
"partnerIds",
+ "excludedPartnerIds",
]);
const selectedEvent = watch("event");
@@ -187,7 +189,8 @@ function RewardSheetContent({
const payload = {
...data,
workspaceId,
- partnerIds,
+ partnerIds: isDefault ? null : partnerIds,
+ excludedPartnerIds: isDefault ? excludedPartnerIds : null,
amount: type === "flat" ? data.amount * 100 : data.amount,
maxDuration:
Infinity === Number(data.maxDuration) ? null : data.maxDuration,
@@ -260,24 +263,45 @@ function RewardSheetContent({
</div>
<div className="flex-1 overflow-y-auto p-6">
- <ProgramSheetAccordion type="multiple" value={defaultAccordionValues}>
- {!isDefault && (
+ <ProgramSheetAccordion
+ type="multiple"
+ defaultValue={defaultAccordionValues}
+ >
+ {!isDefault ? (
<ProgramSheetAccordionItem value="partner-eligibility">
<ProgramSheetAccordionTrigger>
Partner Eligibility
</ProgramSheetAccordionTrigger>
<ProgramSheetAccordionContent>
<div className="space-y-4">
- {!isDefault && (
- <RewardPartnersTable
- partnerIds={partnerIds || []}
- setPartnerIds={(value: string[]) => {
- setValue("partnerIds", value);
- }}
- rewardPartners={rewardPartners || []}
- loading={isLoadingRewardPartners}
- />
- )}
+ <RewardPartnersTable
+ partnerIds={partnerIds || []}
+ setPartnerIds={(value: string[]) => {
+ setValue("partnerIds", value);
+ }}
+ rewardPartners={rewardPartners || []}
+ loading={isLoadingRewardPartners}
+ mode="include"
+ />
+ </div>
+ </ProgramSheetAccordionContent>
+ </ProgramSheetAccordionItem>
+ ) : (
+ <ProgramSheetAccordionItem value="partner-eligibility">
+ <ProgramSheetAccordionTrigger>
+ Partner Eligibility
+ </ProgramSheetAccordionTrigger>
+ <ProgramSheetAccordionContent>
+ <div className="space-y-4">
+ <RewardPartnersTable
+ partnerIds={excludedPartnerIds || []}
+ setPartnerIds={(value: string[]) => {
+ setValue("excludedPartnerIds", value);
+ }}
+ rewardPartners={rewardPartners || []}
+ loading={isLoadingRewardPartners}
+ mode="exclude"
+ />
</div>
</ProgramSheetAccordionContent>
</ProgramSheetAccordionItem>
diff --git a/apps/web/ui/partners/reward-partners-table.tsx b/apps/web/ui/partners/reward-partners-table.tsx
index addc02ef0a..b7dbd05e0b 100644
--- a/apps/web/ui/partners/reward-partners-table.tsx
+++ b/apps/web/ui/partners/reward-partners-table.tsx
@@ -13,6 +13,8 @@ interface RewardPartnersTableProps {
partnerIds: string[];
setPartnerIds: (value: string[]) => void;
loading: boolean;
+ mode?: "include" | "exclude";
+ label?: string;
}
export function RewardPartnersTable({
@@ -20,6 +22,8 @@ export function RewardPartnersTable({
setPartnerIds,
rewardPartners,
loading,
+ mode = "include",
+ label = mode === "include" ? "Eligible partners" : "Non-eligible partners",
}: RewardPartnersTableProps) {
const [search, setSearch] = useState("");
const [debouncedSearch] = useDebounce(search, 500);
@@ -193,9 +197,7 @@ export function RewardPartnersTable({
return (
<div className="flex flex-col gap-3">
- <label className="text-sm font-medium text-neutral-800">
- Eligible partners
- </label>
+ <label className="text-sm font-medium text-neutral-800">{label}</label>
<Combobox
options={partnersOptions}