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.

simplify BLOCK_COMPONENTS

Steven Tey137e743e8204
diff --git a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/page.tsx b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/page.tsx
index 02586d091c..eb79a4b18e 100644
--- a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/page.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/page.tsx
@@ -52,15 +52,7 @@ export default async function ApplyPage({
{landerData.blocks.map((block, idx) => {
const Component = BLOCK_COMPONENTS[block.type];
return Component ? (
- <Component
- key={idx}
- block={block}
- logo={program.logo}
- brandColor={program.brandColor}
- reward={program.rewards?.find(
- (r) => r.id === program.defaultRewardId,
- )}
- />
+ <Component key={idx} block={block} program={program} />
) : null;
})}
</div>
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx
index 704bef9292..8c97a45726 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx
@@ -58,15 +58,7 @@ export default async function ProgramDetailsPage({
.blocks.map((block, idx) => {
const Component = BLOCK_COMPONENTS[block.type];
return Component ? (
- <Component
- key={idx}
- block={block}
- logo={program.logo}
- brandColor={program.brandColor}
- reward={program.rewards?.find(
- (r) => r.id === program.defaultRewardId,
- )}
- />
+ <Component key={idx} block={block} program={program} />
) : null;
})}
</div>
diff --git a/apps/web/ui/partners/design/branding-form.tsx b/apps/web/ui/partners/design/branding-form.tsx
index b6bd6c0917..49499b9f1b 100644
--- a/apps/web/ui/partners/design/branding-form.tsx
+++ b/apps/web/ui/partners/design/branding-form.tsx
@@ -478,14 +478,7 @@ function LanderPreview({ program }: { program: ProgramWithLanderDataProps }) {
{...{ inert: "" }}
>
<div className="px-6">
- <Component
- block={block}
- logo={program.logo}
- brandColor={brandColor}
- reward={program.rewards?.find(
- (r) => r.id === program.defaultRewardId,
- )}
- />
+ <Component block={block} program={program} />
</div>
</div>
</div>
diff --git a/apps/web/ui/partners/design/modals/add-block-modal.tsx b/apps/web/ui/partners/design/modals/add-block-modal.tsx
index 0700ffaedf..72977635b2 100644
--- a/apps/web/ui/partners/design/modals/add-block-modal.tsx
+++ b/apps/web/ui/partners/design/modals/add-block-modal.tsx
@@ -74,7 +74,7 @@ export const DESIGNER_BLOCKS: ({
{
id: "earnings-calculator",
label: "Earnings Calculator",
- description: "Show partners how much they can earn..",
+ description: "Show partners how much they can earn.",
modal: EarningsCalculatorBlockModal,
icon: Calculator,
},
diff --git a/apps/web/ui/partners/design/modals/earnings-calculator-block-modal.tsx b/apps/web/ui/partners/design/modals/earnings-calculator-block-modal.tsx
index d5915ce67c..3abec4e516 100644
--- a/apps/web/ui/partners/design/modals/earnings-calculator-block-modal.tsx
+++ b/apps/web/ui/partners/design/modals/earnings-calculator-block-modal.tsx
@@ -10,6 +10,7 @@ import { Dispatch, SetStateAction, useId, useRef } from "react";
import { Control, useForm, useWatch } from "react-hook-form";
import { z } from "zod";
import { EarningsCalculatorBlock } from "../../lander-blocks/earnings-calculator-block";
+import { useBrandingFormContext } from "../branding-form";
type EarningsCalculatorBlockData = z.infer<
typeof programLanderEarningsCalculatorBlockSchema
@@ -174,6 +175,15 @@ function Preview({
}) {
const productPrice = useWatch({ control, name: "productPrice" });
+ const { program } = useProgram();
+ const { control: brandingFormControl } = useBrandingFormContext();
+ const brandColor = useWatch({
+ control: brandingFormControl,
+ name: "brandColor",
+ });
+
+ if (!program) return null;
+
return (
<EarningsCalculatorBlock
block={{
@@ -184,6 +194,7 @@ function Preview({
Math.min(Math.max(productPrice || 0, 0), MAX_PRODUCT_PRICE) * 100,
},
}}
+ program={{ ...program, brandColor }}
showTitleAndDescription={false}
/>
);
diff --git a/apps/web/ui/partners/lander-blocks/FilesBlock.tsx b/apps/web/ui/partners/lander-blocks/FilesBlock.tsx
index 34dd87cdee..064803b4b6 100644
--- a/apps/web/ui/partners/lander-blocks/FilesBlock.tsx
+++ b/apps/web/ui/partners/lander-blocks/FilesBlock.tsx
@@ -1,3 +1,4 @@
+import { ProgramProps } from "@/lib/types";
import { programLanderFilesBlockSchema } from "@/lib/zod/schemas/program-lander";
import { ArrowUpRight, Download } from "@dub/ui/icons";
import { z } from "zod";
@@ -5,10 +6,10 @@ import { BlockTitle } from "./BlockTitle";
export function FilesBlock({
block,
- logo,
+ program,
}: {
block: z.infer<typeof programLanderFilesBlockSchema>;
- logo: string | null;
+ program: ProgramProps;
}) {
return (
<div className="space-y-5">
@@ -24,8 +25,12 @@ export function FilesBlock({
<div className="flex min-w-0 items-center gap-4">
<div className="shrink-0 rounded-full border border-neutral-200">
<div className="rounded-full border border-white bg-gradient-to-t from-neutral-100 p-1 md:p-2">
- {logo ? (
- <img src={logo} alt="" className="size-4 rounded-full" />
+ {program.logo ? (
+ <img
+ src={program.logo}
+ alt=""
+ className="size-4 rounded-full"
+ />
) : (
<Download className="size-4" />
)}
diff --git a/apps/web/ui/partners/lander-blocks/earnings-calculator-block.tsx b/apps/web/ui/partners/lander-blocks/earnings-calculator-block.tsx
index 4b5fc14777..fd72377838 100644
--- a/apps/web/ui/partners/lander-blocks/earnings-calculator-block.tsx
+++ b/apps/web/ui/partners/lander-blocks/earnings-calculator-block.tsx
@@ -1,32 +1,27 @@
"use client";
-import useProgram from "@/lib/swr/use-program";
+import { ProgramProps } from "@/lib/types";
import { programLanderEarningsCalculatorBlockSchema } from "@/lib/zod/schemas/program-lander";
import { InvoiceDollar } from "@dub/ui";
import NumberFlow from "@number-flow/react";
import { useId, useState } from "react";
-import { useWatch } from "react-hook-form";
import { z } from "zod";
-import { useBrandingFormContext } from "../design/branding-form";
import { formatRewardDescription } from "../format-reward-description";
import { BlockDescription } from "./BlockDescription";
import { BlockTitle } from "./BlockTitle";
export function EarningsCalculatorBlock({
block,
+ program,
showTitleAndDescription = true,
}: {
block: z.infer<typeof programLanderEarningsCalculatorBlockSchema>;
+ program: ProgramProps;
showTitleAndDescription?: boolean;
}) {
const id = useId();
- const { program } = useProgram();
- const { control: brandingFormControl } = useBrandingFormContext();
- const brandColor = useWatch({
- control: brandingFormControl,
- name: "brandColor",
- });
+ console.log({ program });
const reward = program?.rewards?.find(
(r) => r.id === program?.defaultRewardId,
);
@@ -67,7 +62,7 @@ export function EarningsCalculatorBlock({
value={value}
onChange={(e) => setValue(Number(e.target.value))}
className="mt-4 w-full"
- style={{ accentColor: brandColor || "black" }}
+ style={{ accentColor: program.brandColor || "black" }}
/>
<div className="mt-2 flex items-center gap-1">
<InvoiceDollar className="size-3.5 text-neutral-400" />
@@ -79,7 +74,7 @@ export function EarningsCalculatorBlock({
<div className="relative border-t border-neutral-200">
<div
className="absolute inset-0 opacity-5"
- style={{ backgroundColor: brandColor || "black" }}
+ style={{ backgroundColor: program.brandColor || "black" }}
/>
<div className="flex flex-col items-center justify-center p-4 font-semibold text-neutral-800/60 sm:p-6">
<span>You can earn</span>