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.

final step

Kiran Kd557b8fef3c7
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/form-wrapper.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/form-wrapper.tsx
index b8ed561b40..20efb65b7e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/form-wrapper.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/form-wrapper.tsx
@@ -13,8 +13,11 @@ export function FormWrapper({ children }: { children: React.ReactNode }) {
...programOnboarding,
linkType: programOnboarding?.linkType ?? "short",
programType: programOnboarding?.programType ?? "new",
+ type: programOnboarding?.type ?? "flat",
amount: programOnboarding?.amount ?? null,
- partners: programOnboarding?.partners?.length ? programOnboarding.partners : [{ email: "", key: "" }],
+ partners: programOnboarding?.partners?.length
+ ? programOnboarding.partners
+ : [{ email: "", key: "" }],
},
});
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/overview/form.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/overview/form.tsx
index 6f276c1e8f..b7c647c881 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/overview/form.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/overview/form.tsx
@@ -2,7 +2,6 @@
import { onboardProgramAction } from "@/lib/actions/partners/onboard-program";
import useWorkspace from "@/lib/swr/use-workspace";
-import { useWorkspaceStore } from "@/lib/swr/use-workspace-store";
import { ProgramData } from "@/lib/zod/schemas/program-onboarding";
import { ProgramRewardDescription } from "@/ui/partners/program-reward-description";
import { CommissionType, EventType } from "@dub/prisma/client";
@@ -11,15 +10,17 @@ import { Pencil } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
import Link from "next/link";
import { useRouter } from "next/navigation";
+import { useMemo } from "react";
import { useFormContext } from "react-hook-form";
import { toast } from "sonner";
import { LINK_TYPES } from "../form";
export function Form() {
const router = useRouter();
- const { id: workspaceId, slug: workspaceSlug } = useWorkspace();
- const [programOnboarding, __, { mutateWorkspace }] = useWorkspaceStore<ProgramData>("programOnboarding");
const { getValues } = useFormContext<ProgramData>();
+ const { id: workspaceId, slug: workspaceSlug } = useWorkspace();
+
+ const data = getValues();
const { executeAsync, isPending } = useAction(onboardProgramAction, {
onSuccess: ({ data }) => {
@@ -35,8 +36,6 @@ export function Form() {
const onClick = async () => {
if (!workspaceId) return;
- const data = getValues();
-
await executeAsync({
...data,
workspaceId,
@@ -44,43 +43,69 @@ export function Form() {
});
};
- const rewardful = programOnboarding?.rewardful?.campaign;
+ const isValid = useMemo(() => {
+ const {
+ name,
+ url,
+ domain,
+ logo,
+ programType,
+ rewardful,
+ type,
+ amount,
+ maxDuration,
+ } = data;
+
+ if (!name || !url || !domain || !logo) {
+ return false;
+ }
+
+ if (programType === "new" && (!amount || !type || !maxDuration)) {
+ return false;
+ }
+
+ if (programType === "import" && (!rewardful || !rewardful.id)) {
+ return false;
+ }
+
+ return true;
+ }, [data]);
- const reward = rewardful
+ const reward = data.rewardful
? {
- type: rewardful.reward_type === "amount" ? ("flat" as const) : ("percentage" as const),
+ type:
+ data.rewardful.reward_type === "amount"
+ ? ("flat" as const)
+ : ("percentage" as const),
amount:
- rewardful.reward_type === "amount"
- ? rewardful.commission_amount_cents ?? 0
- : rewardful.commission_percent ?? 0,
- maxDuration: rewardful.max_commission_period_months,
+ data.rewardful.reward_type === "amount"
+ ? data.rewardful.commission_amount_cents ?? 0
+ : data.rewardful.commission_percent ?? 0,
+ maxDuration: data.rewardful.max_commission_period_months,
event: "sale" as EventType,
}
: {
- type: (programOnboarding?.type ?? "flat") as CommissionType,
- amount: programOnboarding?.amount ?? 0,
- maxDuration: programOnboarding?.maxDuration ?? 0,
+ type: (data.type ?? "flat") as CommissionType,
+ amount: data.amount ?? 0,
+ maxDuration: data.maxDuration ?? 0,
event: "sale" as EventType,
};
const SECTIONS = [
{
title: "Reward",
- content: reward ? (
- <ProgramRewardDescription reward={reward} />
- ) : null,
+ content: reward ? <ProgramRewardDescription reward={reward} /> : null,
href: `/${workspaceSlug}/programs/new/rewards`,
},
{
title: "Referral link structure",
- content: LINK_TYPES.find(
- (linkType) => linkType.value === programOnboarding?.linkType,
- )?.preview,
+ content: LINK_TYPES.find((linkType) => linkType.value === data.linkType)
+ ?.preview,
href: `/${workspaceSlug}/programs/new`,
},
{
title: "Destination URL",
- content: programOnboarding?.url,
+ content: data.url,
href: `/${workspaceSlug}/programs/new`,
},
] as const;
@@ -116,6 +141,12 @@ export function Form() {
loading={isPending}
type="button"
onClick={onClick}
+ disabled={!isValid}
+ disabledTooltip={
+ !isValid
+ ? "Please fill all the required fields to create a program."
+ : undefined
+ }
/>
</div>
);
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/partners/form.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/partners/form.tsx
index adc9f60f3f..c83e0df9a7 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/partners/form.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/(new)/new/partners/form.tsx
@@ -4,6 +4,7 @@ import { onboardProgramAction } from "@/lib/actions/partners/onboard-program";
import useWorkspace from "@/lib/swr/use-workspace";
import { useWorkspaceStore } from "@/lib/swr/use-workspace-store";
import { ProgramData } from "@/lib/zod/schemas/program-onboarding";
+import { AlertCircleFill } from "@/ui/shared/icons";
import { Button, Input } from "@dub/ui";
import { cn } from "@dub/utils";
import { Plus, Trash2 } from "lucide-react";
@@ -62,7 +63,7 @@ export function Form() {
try {
const res = await fetch(
- `/api/links/exists?domain=dub.sh&key=zuck&workspaceId=${workspaceId}`,
+ `/api/links/exists?domain=${domain}&key=${value}&workspaceId=${workspaceId}`,
);
const { error } = await res.json();
@@ -185,12 +186,17 @@ export function Form() {
<div className="mt-2 w-full">
<div
className={cn(
- "flex items-stretch overflow-hidden rounded-md border border-neutral-200 bg-white focus-within:border-neutral-500 focus-within:ring-1 focus-within:ring-neutral-500",
+ "relative flex items-stretch overflow-hidden rounded-md border border-neutral-200 bg-white focus-within:border-neutral-500 focus-within:ring-1 focus-within:ring-neutral-500",
keyErrors[index] &&
- "border-red-300 focus-within:border-red-500 focus-within:ring-red-500",
+ "border-red-500 focus-within:border-red-500 focus-within:ring-red-500",
)}
>
- <div className="flex items-center border-r border-neutral-300 bg-neutral-100 px-3">
+ <div
+ className={cn(
+ "flex items-center border-r border-neutral-300 bg-neutral-100 px-3",
+ keyErrors[index] && "border-red-500",
+ )}
+ >
<span className="text-sm font-medium text-neutral-800">
{domain}
</span>
@@ -204,13 +210,19 @@ export function Form() {
className={cn(
"w-full border-0 bg-transparent px-3 py-2 text-sm text-neutral-900 placeholder:text-neutral-400 focus:outline-none focus:ring-0",
keyErrors[index] &&
- "text-red-900 placeholder-red-300",
+ "pr-10 text-red-900 placeholder-red-300",
)}
/>
+
+ {keyErrors[index] && (
+ <div className="absolute inset-y-0 right-0 flex items-center pr-3">
+ <AlertCircleFill className="h-5 w-5 text-red-500" />
+ </div>
+ )}
</div>
{keyErrors[index] && (
- <p className="mt-2 text-xs text-red-400">
+ <p className="mt-2 text-xs text-red-500">
{keyErrors[index]}
</p>
)}
@@ -241,6 +253,7 @@ export function Form() {
}}
disabled={fields.length >= 10}
/>
+
{fields.length >= 10 && (
<p className="text-sm text-neutral-600">
You can add up to 10 partners at a time