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.

Disclose partner email notifications in confirmation flows (#4080)

Pedro Ladeirae6250ae33f60
diff --git a/apps/web/lib/swr/use-partners-count.ts b/apps/web/lib/swr/use-partners-count.ts
index 37e9af8935..5d347baea5 100644
--- a/apps/web/lib/swr/use-partners-count.ts
+++ b/apps/web/lib/swr/use-partners-count.ts
@@ -33,7 +33,11 @@ export default function usePartnersCount<T>({
},
);
- const { data: partnersCount, error } = useSWR<PartnersCount>(
+ const {
+ data: partnersCount,
+ error,
+ isValidating,
+ } = useSWR<PartnersCount>(
enabled !== false && defaultProgramId
? `/api/partners/count${queryString}`
: null,
@@ -47,5 +51,6 @@ export default function usePartnersCount<T>({
partnersCount: partnersCount as T,
error,
loading: enabled !== false && !error && partnersCount === undefined,
+ isValidating,
};
}
diff --git a/apps/web/ui/modals/ban-partner-modal.tsx b/apps/web/ui/modals/ban-partner-modal.tsx
index 653c74bfb1..3256a50c45 100644
--- a/apps/web/ui/modals/ban-partner-modal.tsx
+++ b/apps/web/ui/modals/ban-partner-modal.tsx
@@ -22,6 +22,7 @@ import {
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import * as z from "zod/v4";
+import { PartnerEmailNotificationTooltipHelper } from "../shared/partner-email-notification-tooltip-helper";
type BanPartnerFormData = z.infer<typeof banPartnerSchema> & {
confirm: string;
@@ -115,9 +116,10 @@ function BanPartnerModal({
</div>
<p className="text-sm text-neutral-600">
- This will permanently ban the partner, disable all their active
- links, and cancel all pending payouts. This action is not
- reversible.
+ This will disable all their active links, cancel all pending
+ payouts, and{" "}
+ <PartnerEmailNotificationTooltipHelper text="notify them via email" />
+ . You can unban them later if needed.
</p>
<div>
diff --git a/apps/web/ui/modals/bulk-ban-partners-modal.tsx b/apps/web/ui/modals/bulk-ban-partners-modal.tsx
index f59cee2029..b3b42de3f5 100644
--- a/apps/web/ui/modals/bulk-ban-partners-modal.tsx
+++ b/apps/web/ui/modals/bulk-ban-partners-modal.tsx
@@ -20,6 +20,7 @@ import {
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import * as z from "zod/v4";
+import { PartnerEmailNotificationTooltipHelper } from "../shared/partner-email-notification-tooltip-helper";
type BulkBanPartnersFormData = z.infer<typeof bulkBanPartnersSchema> & {
confirm: string;
@@ -199,9 +200,10 @@ function BulkBanPartnersModal({
</div>
<p className="text-sm text-neutral-600">
- This will permanently ban the {partnerWord}, disable all their
- active links, and cancel all pending payouts. This action is not
- reversible.
+ This will disable all their active links, cancel all pending
+ payouts, and{" "}
+ <PartnerEmailNotificationTooltipHelper text="notify them via email" />
+ . You can unban them later if needed.
</p>
<div>
diff --git a/apps/web/ui/modals/bulk-deactivate-partners-modal.tsx b/apps/web/ui/modals/bulk-deactivate-partners-modal.tsx
index 34c258474d..a11343a533 100644
--- a/apps/web/ui/modals/bulk-deactivate-partners-modal.tsx
+++ b/apps/web/ui/modals/bulk-deactivate-partners-modal.tsx
@@ -14,6 +14,7 @@ import {
} from "react";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
+import { PartnerEmailNotificationTooltipHelper } from "../shared/partner-email-notification-tooltip-helper";
type BulkDeactivatePartnersFormData = {
confirm: string;
@@ -146,9 +147,10 @@ function BulkDeactivatePartnersModal({
</div>
<p className="text-sm text-neutral-600">
- This will deactivate the {partnerWord} and disable all their active
- links. Their commissions and payouts will remain intact. You can
- reactivate them later if needed.
+ All active links for {partners.length === 1 ? "this" : "these"}{" "}
+ {partnerWord} will be disabled and they will be{" "}
+ <PartnerEmailNotificationTooltipHelper />. Their commissions and
+ payouts will remain intact. You can reactivate them later if needed.
</p>
<div>
diff --git a/apps/web/ui/modals/bulk-reject-partners-modal.tsx b/apps/web/ui/modals/bulk-reject-partners-modal.tsx
index a707f89b1e..f3ea5be86c 100644
--- a/apps/web/ui/modals/bulk-reject-partners-modal.tsx
+++ b/apps/web/ui/modals/bulk-reject-partners-modal.tsx
@@ -14,6 +14,7 @@ import {
useState,
} from "react";
import { toast } from "sonner";
+import { PartnerEmailNotificationTooltipHelper } from "../shared/partner-email-notification-tooltip-helper";
function BulkRejectPartnersModal({
showBulkRejectPartnersModal,
@@ -73,7 +74,7 @@ function BulkRejectPartnersModal({
{pluralize("this application", partners.length, {
plural: "these applications",
})}
- ?
+ ? They will be <PartnerEmailNotificationTooltipHelper />.
</p>
</div>
diff --git a/apps/web/ui/modals/change-group-modal.tsx b/apps/web/ui/modals/change-group-modal.tsx
index 0fa0cd724c..369f436188 100644
--- a/apps/web/ui/modals/change-group-modal.tsx
+++ b/apps/web/ui/modals/change-group-modal.tsx
@@ -5,7 +5,7 @@ import useWorkspace from "@/lib/swr/use-workspace";
import { EnrolledPartnerExtendedProps } from "@/lib/types";
import { PartnerAvatar } from "@/ui/partners/partner-avatar";
import { Button, InfoTooltip, Modal, Switch } from "@dub/ui";
-import { cn } from "@dub/utils";
+import { cn, pluralize } from "@dub/utils";
import {
Dispatch,
SetStateAction,
@@ -90,6 +90,7 @@ function ChangeGroupModal({
]);
const isSinglePartner = partners.length === 1;
+ const partnerWord = pluralize("partner", partners.length);
return (
<Modal
@@ -140,6 +141,12 @@ function ChangeGroupModal({
)}
</div>
+ <p className="text-sm text-neutral-600">
+ This will change the group for the{" "}
+ {isSinglePartner ? partnerWord : `selected ${partnerWord}`} and notify
+ them by email.
+ </p>
+
<div>
<label className="block text-sm font-medium text-neutral-900">
New group
diff --git a/apps/web/ui/modals/confirm-approve-bounty-submission-modal.tsx b/apps/web/ui/modals/confirm-approve-bounty-submission-modal.tsx
index e5a090629b..2d7cb9c5bf 100644
--- a/apps/web/ui/modals/confirm-approve-bounty-submission-modal.tsx
+++ b/apps/web/ui/modals/confirm-approve-bounty-submission-modal.tsx
@@ -89,7 +89,7 @@ function ConfirmApproveBountySubmissionModal({
<span className="font-semibold text-neutral-900">
{submission.partner.name}
</span>
- .
+ and notify them by email.
</p>
</div>
diff --git a/apps/web/ui/modals/confirm-reward-change-modal.tsx b/apps/web/ui/modals/confirm-reward-change-modal.tsx
new file mode 100644
index 0000000000..0a8f5a8d5a
--- /dev/null
+++ b/apps/web/ui/modals/confirm-reward-change-modal.tsx
@@ -0,0 +1,172 @@
+"use client";
+
+import { RewardProps } from "@/lib/types";
+import { ProgramRewardDescription } from "@/ui/partners/program-reward-description";
+import { REWARD_EVENT_DESCRIPTIONS } from "@/ui/partners/rewards/reward-event-descriptions";
+import { Button, Modal } from "@dub/ui";
+import { pluralize } from "@dub/utils";
+import { EventType } from "@prisma/client";
+import { useState } from "react";
+import { PartnerEmailNotificationTooltipHelper } from "../shared/partner-email-notification-tooltip-helper";
+
+export type RewardChangeAction = "created" | "updated" | "deleted";
+
+const TITLES: Record<RewardChangeAction, string> = {
+ created: "Create reward",
+ updated: "Update reward",
+ deleted: "Delete reward",
+};
+
+const CONFIRM_TEXT: Record<RewardChangeAction, string> = {
+ created: "Create reward",
+ updated: "Update reward",
+ deleted: "Delete reward",
+};
+
+type ConfirmRewardChangeModalProps = {
+ showModal: boolean;
+ setShowModal: (show: boolean) => void;
+ action: RewardChangeAction;
+ event: EventType;
+ reward: Pick<
+ RewardProps,
+ | "description"
+ | "event"
+ | "maxDuration"
+ | "modifiers"
+ | "tooltipDescription"
+ | "type"
+ | "amountInCents"
+ | "amountInPercentage"
+ | "config"
+ | "spendLimitAmount"
+ | "spendLimitInterval"
+ >;
+ partnerCount?: number;
+ onConfirm: () => Promise<void>;
+ isPending?: boolean;
+};
+
+export function ConfirmRewardChangeModal({
+ showModal,
+ setShowModal,
+ action,
+ event,
+ reward,
+ partnerCount,
+ onConfirm,
+ isPending = false,
+}: ConfirmRewardChangeModalProps) {
+ const [isLoading, setIsLoading] = useState(false);
+ const { icon: Icon, title } = REWARD_EVENT_DESCRIPTIONS[event];
+
+ const change = {
+ created: "added to",
+ updated: "updated for",
+ deleted: "removed from",
+ }[action];
+
+ const handleConfirm = async () => {
+ setIsLoading(true);
+ try {
+ await onConfirm();
+ setShowModal(false);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ return (
+ <Modal
+ showModal={showModal}
+ setShowModal={setShowModal}
+ className="max-w-md"
+ >
+ <div className="px-5 py-4 text-left">
+ <h3 className="text-content-emphasis text-base font-semibold">
+ {TITLES[action]}
+ </h3>
+ <p className="text-content-subtle mt-1 text-sm">
+ The reward below will be {change} the group
+ {partnerCount && partnerCount > 0 ? (
+ <>
+ , and {partnerCount} {pluralize("partner", partnerCount)} will be{" "}
+ <PartnerEmailNotificationTooltipHelper />
+ </>
+ ) : (
+ ""
+ )}
+ .
+ </p>
+
+ <div className="mt-4 rounded-lg border border-neutral-200 bg-neutral-100 p-3">
+ <div className="flex items-center gap-3">
+ <div className="flex size-10 shrink-0 items-center justify-center rounded-md border border-neutral-200 bg-white">
+ <Icon className="size-4 text-neutral-800" />
+ </div>
+ <div className="min-w-0 flex-1 space-y-0.5 py-0.5">
+ <p className="text-sm font-medium text-neutral-900">{title}</p>
+ <div className="text-sm text-neutral-600">
+ <ProgramRewardDescription reward={reward} />
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div className="border-border-subtle flex items-center justify-end gap-2 border-t px-5 py-4">
+ <Button
+ variant="secondary"
+ className="h-8 w-fit px-3"
+ text="Cancel"
+ onClick={() => setShowModal(false)}
+ disabled={isPending || isLoading}
+ />
+ <Button
+ variant={action === "deleted" ? "danger" : "primary"}
+ className="h-8 w-fit px-3"
+ text={CONFIRM_TEXT[action]}
+ loading={isPending || isLoading}
+ onClick={handleConfirm}
+ />
+ </div>
+ </Modal>
+ );
+}
+
+export function useConfirmRewardChangeModal() {
+ const [state, setState] = useState<{
+ action: RewardChangeAction;
+ event: EventType;
+ reward: ConfirmRewardChangeModalProps["reward"];
+ onConfirm: () => Promise<void>;
+ isPending?: boolean;
+ partnerCount?: number;
+ } | null>(null);
+
+ return {
+ openConfirmRewardChangeModal: (options: {
+ action: RewardChangeAction;
+ event: EventType;
+ reward: ConfirmRewardChangeModalProps["reward"];
+ partnerCount?: number;
+ onConfirm: () => Promise<void>;
+ isPending?: boolean;
+ }) => setState(options),
+ closeConfirmRewardChangeModal: () => setState(null),
+ ConfirmRewardChangeModal: state ? (
+ <ConfirmRewardChangeModal
+ showModal
+ setShowModal={(show) => {
+ if (!show) setState(null);
+ }}
+ action={state.action}
+ event={state.event}
+ reward={state.reward}
+ partnerCount={state.partnerCount}
+ onConfirm={state.onConfirm}
+ isPending={state.isPending}
+ />
+ ) : null,
+ };
+}
diff --git a/apps/web/ui/modals/deactivate-partner-modal.tsx b/apps/web/ui/modals/deactivate-partner-modal.tsx
index 59e7dd43f6..4101048033 100644
--- a/apps/web/ui/modals/deactivate-partner-modal.tsx
+++ b/apps/web/ui/modals/deactivate-partner-modal.tsx
@@ -15,6 +15,7 @@ import {
} from "react";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
+import { PartnerEmailNotificationTooltipHelper } from "../shared/partner-email-notification-tooltip-helper";
type DeactivatePartnerFormData = {
confirm: string;
@@ -98,9 +99,9 @@ function DeactivatePartnerModal({
</div>
<p className="text-sm text-neutral-600">
- This will deactivate the partner and disable all their active links.
- Their commissions and payouts will remain intact. You can reactivate
- them later if needed.
+ All active links for this partner will be disabled and they will be{" "}
+ <PartnerEmailNotificationTooltipHelper />. Their commissions and
+ payouts will remain intact. You can reactivate them later if needed.
</p>
<div>
diff --git a/apps/web/ui/modals/delete-group-modal.tsx b/apps/web/ui/modals/delete-group-modal.tsx
index 253b7c36e4..d1db323376 100644
--- a/apps/web/ui/modals/delete-group-modal.tsx
+++ b/apps/web/ui/modals/delete-group-modal.tsx
@@ -7,6 +7,7 @@ import { Users } from "lucide-react";
import { FormEvent, useCallback, useMemo, useState } from "react";
import { toast } from "sonner";
import { GroupColorCircle } from "../partners/groups/group-color-circle";
+import { PartnerEmailNotificationTooltipHelper } from "../shared/partner-email-notification-tooltip-helper";
interface DeleteGroupModalProps {
group: Pick<GroupExtendedProps, "id" | "name" | "color" | "totalPartners">;
@@ -82,6 +83,11 @@ const DeleteGroupModal = ({
discount updated to the <strong>Default</strong> group
settings.
</li>
+ <li>
+ Partners in this group will be{" "}
+ <PartnerEmailNotificationTooltipHelper /> about the
+ change.
+ </li>
</>
) : null}
</ul>
diff --git a/apps/web/ui/partners/bounties/reject-bounty-submission-modal.tsx b/apps/web/ui/partners/bounties/reject-bounty-submission-modal.tsx
index a344f49079..e0b9fd58ed 100644
--- a/apps/web/ui/partners/bounties/reject-bounty-submission-modal.tsx
+++ b/apps/web/ui/partners/bounties/reject-bounty-submission-modal.tsx
@@ -122,6 +122,9 @@ const RejectBountySubmissionModal = ({
)}
</select>
</div>
+ <p className="mt-1.5 text-xs text-neutral-500">
+ Included in rejection email
+ </p>
</div>
<div>
@@ -158,6 +161,9 @@ const RejectBountySubmissionModal = ({
placeholder="Provide additional context for the rejection..."
/>
</div>
+ <p className="mt-1.5 text-xs text-neutral-500">
+ Included in rejection email
+ </p>
</div>
</div>
diff --git a/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx b/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx
index 9b57c4bde1..6a8f3bd639 100644
--- a/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx
+++ b/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx
@@ -9,6 +9,7 @@ import { handleMoneyInputChange, handleMoneyKeyDown } from "@/lib/form-utils";
import { ReferralRewardConfig } from "@/lib/partner-referrals/types";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
import useGroup from "@/lib/swr/use-group";
+import usePartnersCount from "@/lib/swr/use-partners-count";
import useProgram from "@/lib/swr/use-program";
import useWorkspace from "@/lib/swr/use-workspace";
import { RewardConditionsArray, RewardProps } from "@/lib/types";
@@ -56,6 +57,7 @@ import { toast } from "sonner";
import { mutate } from "swr";
import { v4 as uuid } from "uuid";
import * as z from "zod/v4";
+import { useConfirmRewardChangeModal } from "../../modals/confirm-reward-change-modal";
import {
InlineBadgePopover,
InlineBadgePopoverContext,
@@ -203,6 +205,16 @@ function RewardSheetContent({
defaultRewardValues,
}: RewardSheetProps) {
const { group, mutateGroup } = useGroup();
+ const { partnersCount, loading, isValidating } = usePartnersCount<
+ number | undefined
+ >({
+ groupId: group?.id,
+ status: "approved",
+ });
+ const partnerCountForConfirm =
+ group?.id && !loading && !isValidating ? partnersCount : undefined;
+ const { openConfirmRewardChangeModal, ConfirmRewardChangeModal } =
+ useConfirmRewardChangeModal();
const {
id: workspaceId,
slug: workspaceSlug,
@@ -400,398 +412,421 @@ function RewardSheetContent({
return;
}
- if (!reward) {
- await createReward({
- ...payload,
- groupId: group.id,
- });
- } else {
- await updateReward({
- ...payload,
- rewardId: reward.id,
- });
- }
+ openConfirmRewardChangeModal({
+ action: reward ? "updated" : "created",
+ event,
+ reward: payload!,
+ partnerCount: partnerCountForConfirm,
+ isPending: isCreating || isUpdating,
+ onConfirm: async () => {
+ if (!reward) {
+ await createReward({
+ ...payload!,
+ groupId: group.id,
+ });
+ } else {
+ await updateReward({
+ ...payload!,
+ rewardId: reward.id,
+ });
+ }
+ },
+ });
};
- const onDelete = async () => {
+ const onDelete = () => {
if (!workspaceId || !defaultProgramId || !reward) {
return;
}
- if (!window.confirm("Are you sure you want to delete this reward?")) {
- return;
- }
-
- await deleteReward({
- workspaceId,
- rewardId: reward.id,
+ openConfirmRewardChangeModal({
+ action: "deleted",
+ event: reward.event,
+ reward,
+ partnerCount: partnerCountForConfirm,
+ isPending: isDeleting,
+ onConfirm: async () => {
+ await deleteReward({
+ workspaceId,
+ rewardId: reward.id,
+ });
+ },
});
};
return (
- <FormProvider {...form}>
- <form
- ref={formRef}
- onSubmit={handleSubmit(onSubmit)}
- className="flex h-full flex-col"
- >
- <div className="flex h-16 items-center justify-between border-b border-neutral-200 px-6 py-4">
- <Sheet.Title className="text-lg font-semibold">
- {reward ? "Edit" : "Create"} {selectedEvent} reward
- </Sheet.Title>
- <Sheet.Close asChild>
- <Button
- variant="outline"
- icon={<X className="size-5" />}
- className="h-auto w-fit p-1"
- />
- </Sheet.Close>
- </div>
+ <>
+ {ConfirmRewardChangeModal}
+ <FormProvider {...form}>
+ <form
+ ref={formRef}
+ onSubmit={handleSubmit(onSubmit)}
+ className="flex h-full flex-col"
+ >
+ <div className="flex h-16 items-center justify-between border-b border-neutral-200 px-6 py-4">
+ <Sheet.Title className="text-lg font-semibold">
+ {reward ? "Edit" : "Create"} {selectedEvent} reward
+ </Sheet.Title>
+ <Sheet.Close asChild>
+ <Button
+ variant="outline"
+ icon={<X className="size-5" />}
+ className="h-auto w-fit p-1"
+ />
+ </Sheet.Close>
+ </div>
- <div className="flex flex-1 flex-col overflow-y-auto p-6">
- {!reward && <RewardHelperBlock event={event} />}
- <RewardSheetCard
- title={
- <div className="w-full">
- <div className="flex min-w-0 items-center justify-between">
- <div className="flex min-w-0 items-center gap-2.5">
- <RewardIconSquare icon={MoneyBills2} />
- {selectedEvent === "referral" ? (
- <PartnerReferralRewardBuilder />
- ) : (
- <span className="leading-relaxed">
- Pay{" "}
- {selectedEvent === "sale" && (
- <>
- a{" "}
- <InlineBadgePopover text={capitalize(type)}>
- <InlineBadgePopoverMenu
- selectedValue={type}
- onSelect={(value) =>
- setValue("type", value as RewardStructure, {
- shouldDirty: true,
- })
- }
- items={REWARD_TYPES}
- />
- </InlineBadgePopover>{" "}
- {type === "percentage" && "of "}
- </>
- )}
- <InlineBadgePopover
- text={
- amount != null && !isNaN(amount)
- ? constructRewardAmount({
- type,
- maxDuration,
- amountInCents:
- type === "flat" ? amount * 100 : undefined,
- amountInPercentage:
- type === "percentage" ? amount : undefined,
- })
- : "amount"
- }
- invalid={amount == null || isNaN(amount)}
- >
- <AmountInput />
- </InlineBadgePopover>{" "}
- per {selectedEvent}
- {selectedEvent === "sale" && (
- <>
- {" "}
- <InlineBadgePopover
- text={
- maxDuration === 0
- ? "one time"
- : maxDuration === Infinity
- ? "for the customer's lifetime"
- : `for ${maxDuration} ${pluralize("month", Number(maxDuration))}`
- }
- >
- <DurationPopoverContent
- value={Number(maxDuration)}
- onChange={(value) =>
- setValue("maxDuration", value, {
- shouldDirty: true,
+ <div className="flex flex-1 flex-col overflow-y-auto p-6">
+ {!reward && <RewardHelperBlock event={event} />}
+ <RewardSheetCard
+ title={
+ <div className="w-full">
+ <div className="flex min-w-0 items-center justify-between">
+ <div className="flex min-w-0 items-center gap-2.5">
+ <RewardIconSquare icon={MoneyBills2} />
+ {selectedEvent === "referral" ? (
+ <PartnerReferralRewardBuilder />
+ ) : (
+ <span className="leading-relaxed">
+ Pay{" "}
+ {selectedEvent === "sale" && (
+ <>
+ a{" "}
+ <InlineBadgePopover text={capitalize(type)}>
+ <InlineBadgePopoverMenu
+ selectedValue={type}
+ onSelect={(value) =>
+ setValue("type", value as RewardStructure, {
+ shouldDirty: true,
+ })
+ }
+ items={REWARD_TYPES}
+ />
+ </InlineBadgePopover>{" "}
+ {type === "percentage" && "of "}
+ </>
+ )}
+ <InlineBadgePopover
+ text={
+ amount != null && !isNaN(amount)
+ ? constructRewardAmount({
+ type,
+ maxDuration,
+ amountInCents:
+ type === "flat"
+ ? amount * 100
+ : undefined,
+ amountInPercentage:
+ type === "percentage"
+ ? amount
+ : undefined,
})
+ : "amount"
+ }
+ invalid={amount == null || isNaN(amount)}
+ >
+ <AmountInput />
+ </InlineBadgePopover>{" "}
+ per {selectedEvent}
+ {selectedEvent === "sale" && (
+ <>
+ {" "}
+ <InlineBadgePopover
+ text={
+ maxDuration === 0
+ ? "one time"
+ : maxDuration === Infinity
+ ? "for the customer's lifetime"
+ : `for ${maxDuration} ${pluralize("month", Number(maxDuration))}`
}
- presetDurations={RECURRING_MAX_DURATIONS.filter(
- (v) => v !== 0 && v !== 1, // filter out one-time and 1-month intervals (we only use 1-month for discounts)
- )}
- />
- </InlineBadgePopover>
- </>
- )}
- {modifiers?.length ? (
- <> for all other {selectedEvent}s</>
- ) : null}
- {canSetRewardSpendLimit ? (
- <>
- {", "}with{" "}
- <InlineBadgePopover
- text={
- spendLimitEnabled
- ? "a spend limit of"
- : "no spend limit"
- }
- >
- <InlineBadgePopoverMenu
- selectedValue={
- spendLimitEnabled ? "limit" : "none"
- }
- onSelect={(value) => {
- if (value === "none") {
- setValue("spendLimitAmount", null, {
- shouldDirty: true,
- });
- setValue("spendLimitInterval", null, {
+ >
+ <DurationPopoverContent
+ value={Number(maxDuration)}
+ onChange={(value) =>
+ setValue("maxDuration", value, {
shouldDirty: true,
- });
- } else {
- setValue(
- "spendLimitInterval",
- spendLimitInterval ?? "allTime",
- {
- shouldDirty: true,
- },
- );
- }
- }}
- items={[
- { text: "no spend limit", value: "none" },
- {
- text: "a spend limit of",
- value: "limit",
- },
- ]}
- />
- </InlineBadgePopover>{" "}
- {spendLimitEnabled ? (
- <>
- <InlineBadgePopover
- text={
- spendLimitAmount != null &&
- !isNaN(spendLimitAmount)
- ? currencyFormatter(
- spendLimitAmount * 100,
- {
- trailingZeroDisplay:
- "stripIfInteger",
- },
- )
- : "amount"
- }
- invalid={
- spendLimitAmount == null ||
- isNaN(spendLimitAmount)
+ })
}
- >
- <SpendLimitAmountInput />
- </InlineBadgePopover>{" "}
- <InlineBadgePopover
- text={
- spendLimitInterval === "allTime"
- ? "all-time"
- : `per ${spendLimitInterval}`
+ presetDurations={RECURRING_MAX_DURATIONS.filter(
+ (v) => v !== 0 && v !== 1, // filter out one-time and 1-month intervals (we only use 1-month for discounts)
+ )}
+ />
+ </InlineBadgePopover>
+ </>
+ )}
+ {modifiers?.length ? (
+ <> for all other {selectedEvent}s</>
+ ) : null}
+ {canSetRewardSpendLimit ? (
+ <>
+ {", "}with{" "}
+ <InlineBadgePopover
+ text={
+ spendLimitEnabled
+ ? "a spend limit of"
+ : "no spend limit"
+ }
+ >
+ <InlineBadgePopoverMenu
+ selectedValue={
+ spendLimitEnabled ? "limit" : "none"
}
- >
- <InlineBadgePopoverMenu
- selectedValue={
- spendLimitInterval ?? "allTime"
- }
- onSelect={(value) =>
+ onSelect={(value) => {
+ if (value === "none") {
+ setValue("spendLimitAmount", null, {
+ shouldDirty: true,
+ });
+ setValue("spendLimitInterval", null, {
+ shouldDirty: true,
+ });
+ } else {
setValue(
"spendLimitInterval",
- value as any,
+ spendLimitInterval ?? "allTime",
{
shouldDirty: true,
},
- )
+ );
+ }
+ }}
+ items={[
+ { text: "no spend limit", value: "none" },
+ {
+ text: "a spend limit of",
+ value: "limit",
+ },
+ ]}
+ />
+ </InlineBadgePopover>{" "}
+ {spendLimitEnabled ? (
+ <>
+ <InlineBadgePopover
+ text={
+ spendLimitAmount != null &&
+ !isNaN(spendLimitAmount)
+ ? currencyFormatter(
+ spendLimitAmount * 100,
+ {
+ trailingZeroDisplay:
+ "stripIfInteger",
+ },
+ )
+ : "amount"
}
- items={[
- { text: "all-time", value: "allTime" },
- { text: "per day", value: "day" },
- { text: "per week", value: "week" },
- { text: "per month", value: "month" },
- ]}
- />
- </InlineBadgePopover>
- </>
- ) : null}
- </>
- ) : null}
- </span>
- )}
+ invalid={
+ spendLimitAmount == null ||
+ isNaN(spendLimitAmount)
+ }
+ >
+ <SpendLimitAmountInput />
+ </InlineBadgePopover>{" "}
+ <InlineBadgePopover
+ text={
+ spendLimitInterval === "allTime"
+ ? "all-time"
+ : `per ${spendLimitInterval}`
+ }
+ >
+ <InlineBadgePopoverMenu
+ selectedValue={
+ spendLimitInterval ?? "allTime"
+ }
+ onSelect={(value) =>
+ setValue(
+ "spendLimitInterval",
+ value as any,
+ {
+ shouldDirty: true,
+ },
+ )
+ }
+ items={[
+ { text: "all-time", value: "allTime" },
+ { text: "per day", value: "day" },
+ { text: "per week", value: "week" },
+ { text: "per month", value: "month" },
+ ]}
+ />
+ </InlineBadgePopover>
+ </>
+ ) : null}
+ </>
+ ) : null}
+ </span>
+ )}
+ </div>
+ <Tooltip
+ content={"Add a custom reward description"}
+ disabled={description !== null}
+ >
+ <div className="shrink-0">
+ <Button
+ variant="secondary"
+ className={cn(
+ "size-7 p-0",
+ description !== null && "text-blue-600",
+ )}
+ icon={<Pen2 className="size-3.5" />}
+ onClick={() =>
+ setValue(
+ "description",
+ description === null ? "" : null,
+ { shouldDirty: true },
+ )
+ }
+ />
+ </div>
+ </Tooltip>
</div>
- <Tooltip
- content={"Add a custom reward description"}
- disabled={description !== null}
+ <motion.div
+ initial={false}
+ transition={{ ease: "easeInOut", duration: 0.2 }}
+ animate={{
+ height: description !== null ? "auto" : 0,
+ opacity: description !== null ? 1 : 0,
+ }}
+ className="-mx-2.5 overflow-hidden"
>
- <div className="shrink-0">
- <Button
- variant="secondary"
- className={cn(
- "size-7 p-0",
- description !== null && "text-blue-600",
- )}
- icon={<Pen2 className="size-3.5" />}
- onClick={() =>
- setValue(
- "description",
- description === null ? "" : null,
- { shouldDirty: true },
- )
- }
- />
- </div>
- </Tooltip>
- </div>
- <motion.div
- initial={false}
- transition={{ ease: "easeInOut", duration: 0.2 }}
- animate={{
- height: description !== null ? "auto" : 0,
- opacity: description !== null ? 1 : 0,
- }}
- className="-mx-2.5 overflow-hidden"
- >
- <div className="pt-2.5">
- <div className="border-border-subtle flex min-w-0 items-center gap-2.5 border-t px-2.5 pt-2.5">
- <RewardIconSquare icon={Gift} />
- <span className="min-w-0 grow leading-relaxed">
- Shown as{" "}
- <InlineBadgePopover
- text={description || "Reward description"}
- invalid={!description}
- >
- <InlineBadgePopoverInput
- value={description ?? ""}
- onChange={(e) =>
- setValue(
- "description",
- (e.target as HTMLInputElement).value,
- {
+ <div className="pt-2.5">
+ <div className="border-border-subtle flex min-w-0 items-center gap-2.5 border-t px-2.5 pt-2.5">
+ <RewardIconSquare icon={Gift} />
+ <span className="min-w-0 grow leading-relaxed">
+ Shown as{" "}
+ <InlineBadgePopover
+ text={description || "Reward description"}
+ invalid={!description}
+ >
+ <InlineBadgePopoverInput
+ value={description ?? ""}
+ onChange={(e) =>
+ setValue(
+ "description",
+ (e.target as HTMLInputElement).value,
+ {
+ shouldDirty: true,
+ },
+ )
+ }
+ className="sm:w-80"
+ maxLength={REWARD_DESCRIPTION_MAX_LENGTH}
+ />
+ </InlineBadgePopover>{" "}
+ with the tooltip{" "}
+ <InlineBadgePopover
+ text={tooltipDescription || "Reward tooltip"}
+ showOptional={!tooltipDescription}
+ buttonClassName="min-w-0 max-w-full"
+ contentClassName="truncate"
+ >
+ <InlineBadgePopoverRichTextArea
+ value={tooltipDescription ?? ""}
+ onChange={(value) =>
+ setValue("tooltipDescription", value, {
shouldDirty: true,
- },
- )
- }
- className="sm:w-80"
- maxLength={REWARD_DESCRIPTION_MAX_LENGTH}
- />
- </InlineBadgePopover>{" "}
- with the tooltip{" "}
- <InlineBadgePopover
- text={tooltipDescription || "Reward tooltip"}
- showOptional={!tooltipDescription}
- buttonClassName="min-w-0 max-w-full"
- contentClassName="truncate"
- >
- <InlineBadgePopoverRichTextArea
- value={tooltipDescription ?? ""}
- onChange={(value) =>
- setValue("tooltipDescription", value, {
- shouldDirty: true,
- })
- }
- className="sm:w-80"
- maxLength={REWARD_TOOLTIP_DESCRIPTION_MAX_LENGTH}
- />
- </InlineBadgePopover>
- </span>
- <Button
- variant="outline"
- className="size-6 shrink-0 p-0"
- icon={<X className="size-3" strokeWidth={2} />}
- onClick={() => {
- setValue("description", null, { shouldDirty: true });
- setValue("tooltipDescription", null, {
- shouldDirty: true,
- });
- }}
- />
+ })
+ }
+ className="sm:w-80"
+ maxLength={REWARD_TOOLTIP_DESCRIPTION_MAX_LENGTH}
+ />
+ </InlineBadgePopover>
+ </span>
+ <Button
+ variant="outline"
+ className="size-6 shrink-0 p-0"
+ icon={<X className="size-3" strokeWidth={2} />}
+ onClick={() => {
+ setValue("description", null, {
+ shouldDirty: true,
+ });
+ setValue("tooltipDescription", null, {
+ shouldDirty: true,
+ });
+ }}
+ />
+ </div>
</div>
- </div>
- </motion.div>
- </div>
- }
- content={
- selectedEvent === "referral" ? null : (
- <RewardsLogic isDefaultReward={false} />
- )
- }
- />
-
- <VerticalLine />
- <RewardPreviewCard />
-
- {group && (
- <>
- <VerticalLine />
- <RewardDiscountPartnersCard groupId={group.id} />
- </>
- )}
- </div>
+ </motion.div>
+ </div>
+ }
+ content={
+ selectedEvent === "referral" ? null : (
+ <RewardsLogic isDefaultReward={false} />
+ )
+ }
+ />
+
+ <VerticalLine />
+ <RewardPreviewCard />
+
+ {group && (
+ <>
+ <VerticalLine />
+ <RewardDiscountPartnersCard groupId={group.id} />
+ </>
+ )}
+ </div>
+
+ <div className="flex items-center justify-between border-t border-neutral-200 p-5">
+ <div>
+ {reward && (
+ <Button
+ type="button"
+ variant="outline"
+ text="Remove reward"
+ className="h-9 w-fit"
+ onClick={onDelete}
+ loading={isDeleting}
+ disabled={isCreating || isUpdating}
+ />
+ )}
+ </div>
- <div className="flex items-center justify-between border-t border-neutral-200 p-5">
- <div>
- {reward && (
+ <div className="flex items-center gap-2">
<Button
type="button"
- variant="outline"
- text="Remove reward"
+ variant="secondary"
+ onClick={() => setIsOpen(false)}
+ text="Cancel"
className="h-9 w-fit"
- onClick={onDelete}
- loading={isDeleting}
- disabled={isCreating || isUpdating}
+ disabled={isCreating || isUpdating || isDeleting}
/>
- )}
- </div>
-
- <div className="flex items-center gap-2">
- <Button
- type="button"
- variant="secondary"
- onClick={() => setIsOpen(false)}
- text="Cancel"
- className="h-9 w-fit"
- disabled={isCreating || isUpdating || isDeleting}
- />
- <Button
- type="submit"
- variant="primary"
- text={reward ? "Update reward" : "Create reward"}
- className="h-9 w-fit"
- loading={isCreating || isUpdating}
- disabled={
- amount == null ||
- hasIncompleteMainSpendLimit ||
- isDeleting ||
- isCreating ||
- isUpdating
- }
- disabledTooltip={
- showReferralUpsell ? (
- <TooltipContent
- title="Referral rewards are only available on the Advanced plan and above."
- cta="Upgrade to Advanced"
- href={`/${workspaceSlug}/upgrade?plan=advanced&showPartnersUpgradeModal=true`}
- target="_blank"
- />
- ) : showAdvancedUpsell ? (
- <TooltipContent
- title="[Advanced reward structures](https://dub.co/help/article/partner-rewards#adding-reward-conditions) are only available on the Advanced plan and above."
- cta="Upgrade to Advanced"
- href={`/${workspaceSlug}/upgrade?plan=advanced&showPartnersUpgradeModal=true`}
- target="_blank"
- />
- ) : undefined
- }
- />
+ <Button
+ type="submit"
+ variant="primary"
+ text={reward ? "Update reward" : "Create reward"}
+ className="h-9 w-fit"
+ loading={isCreating || isUpdating}
+ disabled={
+ amount == null ||
+ hasIncompleteMainSpendLimit ||
+ isDeleting ||
+ isCreating ||
+ isUpdating
+ }
+ disabledTooltip={
+ showReferralUpsell ? (
+ <TooltipContent
+ title="Referral rewards are only available on the Advanced plan and above."
+ cta="Upgrade to Advanced"
+ href={`/${workspaceSlug}/upgrade?plan=advanced&showPartnersUpgradeModal=true`}
+ target="_blank"
+ />
+ ) : showAdvancedUpsell ? (
+ <TooltipContent
+ title="[Advanced reward structures](https://dub.co/help/article/partner-rewards#adding-reward-conditions) are only available on the Advanced plan and above."
+ cta="Upgrade to Advanced"
+ href={`/${workspaceSlug}/upgrade?plan=advanced&showPartnersUpgradeModal=true`}
+ target="_blank"
+ />
+ ) : undefined
+ }
+ />
+ </div>
</div>
- </div>
- </form>
- </FormProvider>
+ </form>
+ </FormProvider>
+ </>
);
}
diff --git a/apps/web/ui/shared/partner-email-notification-tooltip-helper.tsx b/apps/web/ui/shared/partner-email-notification-tooltip-helper.tsx
new file mode 100644
index 0000000000..11219ad20e
--- /dev/null
+++ b/apps/web/ui/shared/partner-email-notification-tooltip-helper.tsx
@@ -0,0 +1,15 @@
+import { Tooltip } from "@dub/ui";
+
+export const PartnerEmailNotificationTooltipHelper = ({
+ text = "notified via email",
+}: {
+ text?: string;
+}) => {
+ return (
+ <Tooltip content="Only partners who have previously created an account on [partners.dub.co](https://partners.dub.co) will receive an email notification.">
+ <span className="cursor-help underline decoration-dotted underline-offset-2">
+ {text}
+ </span>
+ </Tooltip>
+ );
+};