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 program-reward-modifiers-tooltip.tsx

Kiran K86b5a428cb88
diff --git a/apps/web/ui/partners/program-reward-modifiers-tooltip.tsx b/apps/web/ui/partners/program-reward-modifiers-tooltip.tsx
index 25c6b96d2e..2e0cbb6f16 100644
--- a/apps/web/ui/partners/program-reward-modifiers-tooltip.tsx
+++ b/apps/web/ui/partners/program-reward-modifiers-tooltip.tsx
@@ -4,95 +4,109 @@ import {
CONDITION_OPERATOR_LABELS,
rewardConditionsArraySchema,
} from "@/lib/zod/schemas/rewards";
-import { ArrowTurnRight2, InfoTooltip } from "@dub/ui";
-import { capitalize, cn, pluralize, truncate } from "@dub/utils";
-import { RewardStructure } from "@prisma/client";
-import { Fragment } from "react";
+import { InfoTooltip } from "@dub/ui";
+import { pluralize } from "@dub/utils";
import { z } from "zod";
export function ProgramRewardModifiersTooltip({
reward,
}: {
- reward?: Pick<
- RewardProps,
- "amount" | "type" | "event" | "maxDuration" | "modifiers"
- > | null;
+ reward?: RewardProps | null;
}) {
- if (!reward?.modifiers?.length) return null;
+ if (!reward?.modifiers?.length) {
+ return null;
+ }
return (
<div className="inline-block align-text-top">
<InfoTooltip
content={
- <div
- className={cn(
- "block max-w-xs text-pretty p-3 text-left text-xs font-medium text-neutral-600",
- )}
- >
- <strong className="font-semibold">
- <span className="text-content-default">
- {constructRewardAmount({
- reward,
- })}
- </span>{" "}
- per {reward.event}
- {reward.event === "sale" && (
- <>
- {" "}
- {reward.maxDuration === 0
- ? "one time"
- : reward.maxDuration === Infinity ||
- reward.maxDuration === null
- ? "for the customer's lifetime"
- : `for ${reward.maxDuration} ${pluralize("month", Number(reward.maxDuration))}`}
- </>
- )}
- </strong>
-
+ <div className="max-w-xs space-y-2 p-3">
+ <RewardItem reward={reward} />
{(
reward.modifiers as z.infer<typeof rewardConditionsArraySchema>
- ).map(
- ({ amount, type, operator, conditions, maxDuration }, idx) => (
- <Fragment key={idx}>
- <div className="mt-1 flex items-start gap-1.5">
- <ArrowTurnRight2 className="mt-0.5 size-3 shrink-0" />
- <div className="min-w-0">
- <strong className="text-content-default font-semibold">
- {constructRewardAmount({
- reward: {
- amount,
- type: type as RewardStructure,
- maxDuration,
- modifiers: undefined,
- },
- })}
- </strong>
- <ul className="overflow-hidden pl-1 text-xs text-neutral-600">
- {conditions.map((condition, idx) => (
- <li key={idx} className="flex items-center gap-1">
- <span className="shrink-0 text-lg leading-none">
- &bull;
- </span>
- <span className="min-w-0 truncate">
- {idx === 0
- ? "If"
- : capitalize(operator.toLowerCase())}
- {` ${condition.entity}`}
- {` ${condition.attribute}`}
- {` ${CONDITION_OPERATOR_LABELS[condition.operator]}`}
- {` ${condition.value && truncate(Array.isArray(condition.value) ? condition.value.join(", ") : condition.value.toString(), 16)}`}
- </span>
- </li>
- ))}
- </ul>
- </div>
- </div>
- </Fragment>
- ),
- )}
+ ).map((modifier, idx) => (
+ <div key={idx} className="space-y-2">
+ <span className="flex w-full items-center justify-center rounded bg-neutral-100 px-2 py-1 text-xs font-semibold text-neutral-600">
+ OR
+ </span>
+
+ <RewardItem
+ reward={{
+ event: reward.event,
+ amount: modifier.amount,
+ type:
+ modifier.type === undefined ? reward.type : modifier.type, // fallback to primary
+ maxDuration:
+ modifier.maxDuration === undefined
+ ? reward.maxDuration
+ : modifier.maxDuration, // fallback to primary
+ }}
+ conditions={modifier.conditions}
+ />
+ </div>
+ ))}
</div>
}
/>
</div>
);
}
+
+const RewardItem = ({
+ reward,
+ conditions,
+}: {
+ reward: Pick<RewardProps, "amount" | "type" | "event" | "maxDuration">;
+ conditions?: z.infer<
+ typeof rewardConditionsArraySchema
+ >[number]["conditions"];
+}) => {
+ const rewardAmount = constructRewardAmount({
+ reward: {
+ ...reward,
+ modifiers: undefined,
+ },
+ });
+
+ const durationText =
+ reward.maxDuration === null
+ ? "for the customer's lifetime"
+ : reward.maxDuration === 0
+ ? "one time"
+ : reward.maxDuration && reward.maxDuration % 12 === 0
+ ? `for ${reward.maxDuration / 12} ${pluralize(
+ "year",
+ reward.maxDuration / 12,
+ )}`
+ : reward.maxDuration
+ ? `for ${reward.maxDuration} months`
+ : "";
+
+ return (
+ <div>
+ <div className="text-content-default text-xs font-semibold">
+ {rewardAmount} per {reward.event} {durationText}
+ </div>
+
+ {conditions && conditions.length > 0 && (
+ <ul className="ml-1 space-y-0.5 text-sm font-medium text-neutral-600">
+ {conditions.map((condition, idx) => (
+ <li key={idx} className="flex items-start gap-1">
+ <span className="mt-0.5 text-lg leading-none">•</span>
+ <span className="min-w-0">
+ {idx === 0 ? "If" : "Or"} {condition.entity}{" "}
+ {condition.attribute}{" "}
+ {CONDITION_OPERATOR_LABELS[condition.operator]}{" "}
+ {condition.value &&
+ (Array.isArray(condition.value)
+ ? condition.value.join(", ")
+ : condition.value.toString())}
+ </span>
+ </li>
+ ))}
+ </ul>
+ )}
+ </div>
+ );
+};