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 preview rewards

Tim Wilsoned41b9d9da03
diff --git a/apps/web/ui/partners/design/previews/application-preview.tsx b/apps/web/ui/partners/design/previews/application-preview.tsx
index def518b966..b9360a5d44 100644
--- a/apps/web/ui/partners/design/previews/application-preview.tsx
+++ b/apps/web/ui/partners/design/previews/application-preview.tsx
@@ -3,10 +3,10 @@ import { Button, useScroll, Wordmark } from "@dub/ui";
import { cn, PARTNERS_DOMAIN } from "@dub/utils";
import { CSSProperties, useRef } from "react";
import { useWatch } from "react-hook-form";
-import { LanderRewards } from "../../lander/lander-rewards";
import { ProgramApplicationForm } from "../../lander/program-application-form";
import { useBrandingFormContext } from "../branding-form";
import { PreviewWindow } from "../preview-window";
+import { RewardsPreview } from "../rewards-preview";
// Currently unused, but will be needed when we add form customization
export function ApplicationPreview({
@@ -89,15 +89,7 @@ export function ApplicationPreview({
{/* Program rewards */}
<div className="mx-auto mt-6 max-w-screen-sm">
<div className="px-6">
- <LanderRewards
- className="mt-4"
- rewards={program.rewards ?? []}
- discount={
- program.discounts?.find(
- (d) => d.id === program.defaultDiscountId,
- ) || null
- }
- />
+ <RewardsPreview program={program} />
</div>
</div>
diff --git a/apps/web/ui/partners/design/previews/lander-preview.tsx b/apps/web/ui/partners/design/previews/lander-preview.tsx
index 7d6a944096..135705ab81 100644
--- a/apps/web/ui/partners/design/previews/lander-preview.tsx
+++ b/apps/web/ui/partners/design/previews/lander-preview.tsx
@@ -1,22 +1,13 @@
"use client";
-import { getProgramApplicationRewardsAndDiscount } from "@/lib/partners/get-program-application-rewards";
-import useDiscounts from "@/lib/swr/use-discounts";
-import useRewards from "@/lib/swr/use-rewards";
-import {
- ProgramLanderData,
- ProgramProps,
- ProgramWithLanderDataProps,
-} from "@/lib/types";
+import { ProgramLanderData, ProgramWithLanderDataProps } from "@/lib/types";
import { useEditHeroModal } from "@/ui/partners/design/modals/edit-hero-modal";
import { PreviewWindow } from "@/ui/partners/design/preview-window";
import { BLOCK_COMPONENTS } from "@/ui/partners/lander/blocks";
import { LanderHero } from "@/ui/partners/lander/lander-hero";
-import { LanderRewards } from "@/ui/partners/lander/lander-rewards";
import {
Button,
Grid,
- LoadingSpinner,
Pen2,
Plus2,
Tooltip,
@@ -39,6 +30,7 @@ import { useWatch } from "react-hook-form";
import { useBrandingFormContext } from "../branding-form";
import { AddBlockModal, DESIGNER_BLOCKS } from "../modals/add-block-modal";
import { useEditRewardsModal } from "../modals/edit-rewards-modal";
+import { RewardsPreview } from "../rewards-preview";
export function LanderPreview({
program,
@@ -307,35 +299,6 @@ export function LanderPreview({
);
}
-function RewardsPreview({ program }: { program: ProgramProps }) {
- const { getValues } = useBrandingFormContext();
- const { landerData } = {
- ...useWatch(),
- ...getValues(),
- };
-
- const { rewards, loading: rewardsLoading } = useRewards();
- const { discounts, loading: discountsLoading } = useDiscounts();
-
- if (rewardsLoading || discountsLoading)
- return (
- <div>
- <LoadingSpinner />
- </div>
- );
-
- const result = getProgramApplicationRewardsAndDiscount({
- program: {
- ...program,
- landerData,
- },
- rewards: rewards || [],
- discounts: discounts || [],
- });
-
- return <LanderRewards rewards={result.rewards} discount={result.discount} />;
-}
-
function AddBlockButton({ onClick }: { onClick: () => void }) {
return (
<Button
diff --git a/apps/web/ui/partners/design/rewards-preview.tsx b/apps/web/ui/partners/design/rewards-preview.tsx
new file mode 100644
index 0000000000..ac53948c76
--- /dev/null
+++ b/apps/web/ui/partners/design/rewards-preview.tsx
@@ -0,0 +1,39 @@
+"use client";
+
+import { getProgramApplicationRewardsAndDiscount } from "@/lib/partners/get-program-application-rewards";
+import useDiscounts from "@/lib/swr/use-discounts";
+import useRewards from "@/lib/swr/use-rewards";
+import { ProgramProps } from "@/lib/types";
+import { LanderRewards } from "@/ui/partners/lander/lander-rewards";
+import { LoadingSpinner } from "@dub/ui";
+import { useWatch } from "react-hook-form";
+import { useBrandingFormContext } from "./branding-form";
+
+export function RewardsPreview({ program }: { program: ProgramProps }) {
+ const { getValues } = useBrandingFormContext();
+ const { landerData } = {
+ ...useWatch(),
+ ...getValues(),
+ };
+
+ const { rewards, loading: rewardsLoading } = useRewards();
+ const { discounts, loading: discountsLoading } = useDiscounts();
+
+ if (rewardsLoading || discountsLoading)
+ return (
+ <div className="flex h-[117px] items-center justify-center">
+ <LoadingSpinner />
+ </div>
+ );
+
+ const result = getProgramApplicationRewardsAndDiscount({
+ program: {
+ ...program,
+ landerData,
+ },
+ rewards: rewards || [],
+ discounts: discounts || [],
+ });
+
+ return <LanderRewards rewards={result.rewards} discount={result.discount} />;
+}