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.

fix programapplicationsheet merge conflicts + partnerCanViewMarketplace

Steven Tey60dda5c2bb77
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/layout.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/layout.tsx
index 362ac3d937..0aa2661287 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/layout.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/layout.tsx
@@ -6,9 +6,13 @@ import { redirect } from "next/navigation";
import { PropsWithChildren } from "react";
export default function MarketplaceLayout({ children }: PropsWithChildren) {
- const { programEnrollments } = useProgramEnrollments();
+ const { programEnrollments, isLoading } = useProgramEnrollments();
- if (!partnerCanViewMarketplace(programEnrollments || []))
+ if (
+ !isLoading &&
+ programEnrollments &&
+ !partnerCanViewMarketplace(programEnrollments)
+ )
redirect("/programs");
return children;
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/program-card.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/program-card.tsx
index 0065b25c76..cf6d1be8a7 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/program-card.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/program-card.tsx
@@ -50,7 +50,7 @@ export function ProgramCard({ program }: { program?: NetworkProgramProps }) {
<div
className={cn(
program?.id &&
- "border-border-subtle cursor-pointer rounded-xl border bg-white p-6 hover:drop-shadow-sm",
+ "border-border-subtle hover:drop-shadow-card-hover cursor-pointer rounded-xl border bg-white p-6 transition-[filter]",
)}
{...getClickHandlers(url, router)}
>
@@ -82,18 +82,10 @@ export function ProgramCard({ program }: { program?: NetworkProgramProps }) {
<div className="h-6 w-32 animate-pulse rounded bg-neutral-200" />
)}
- <div className="text-content-default mt-1 flex items-center gap-1">
- <Link4 className="size-3.5" />
+ <div className="text-content-subtle mt-1 text-sm">
{/* Domain */}
{program ? (
- <a
- href={program.url || `https://${program.domain}`}
- target="_blank"
- rel="noreferrer noopener"
- className="text-sm font-medium"
- >
- {getPrettyUrl(program.url) || program.domain}
- </a>
+ `${program.name} is a program in the Dub Partner Network. Join the network to start partnering with them.`
) : (
<div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
)}
diff --git a/apps/web/ui/partners/program-application-sheet.tsx b/apps/web/ui/partners/program-application-sheet.tsx
index bddad7e47a..8210117d60 100644
--- a/apps/web/ui/partners/program-application-sheet.tsx
+++ b/apps/web/ui/partners/program-application-sheet.tsx
@@ -4,6 +4,10 @@ import { parseActionError } from "@/lib/actions/parse-action-errors";
import { createProgramApplicationAction } from "@/lib/actions/partners/create-program-application";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import { ProgramEnrollmentProps, ProgramProps } from "@/lib/types";
+import {
+ DEFAULT_PARTNER_GROUP,
+ PartnerProgramGroupSchema,
+} from "@/lib/zod/schemas/groups";
import { createProgramApplicationSchema } from "@/lib/zod/schemas/programs";
import { X } from "@/ui/shared/icons";
import {
@@ -13,18 +17,18 @@ import {
CircleCheckFill,
Grid,
Link4,
+ LoadingSpinner,
Sheet,
} from "@dub/ui";
-import { cn, OG_AVATAR_URL } from "@dub/utils";
+import { cn, fetcher, OG_AVATAR_URL } from "@dub/utils";
import { useAction } from "next-safe-action/hooks";
import Link from "next/link";
import { Dispatch, SetStateAction, useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { toast } from "sonner";
-import { mutate } from "swr";
+import useSWR, { mutate } from "swr";
import { z } from "zod";
import { ProgramApplicationFormField } from "./groups/design/application-form/fields";
-import { formDataForApplicationFormData } from "./groups/design/application-form/form-data-for-application-form-data";
interface ProgramApplicationSheetProps {
setIsOpen: Dispatch<SetStateAction<boolean>>;
@@ -46,17 +50,34 @@ type FormData = Omit<
function ProgramApplicationSheetContent({
program,
+ programEnrollment,
backDestination = "programs",
onSuccess,
}: ProgramApplicationSheetProps) {
const { partner } = usePartnerProfile();
+ const groupIdOrSlug =
+ programEnrollment?.groupId ||
+ program?.defaultGroupId ||
+ DEFAULT_PARTNER_GROUP.slug;
+
+ const {
+ data: group,
+ isLoading: isGroupLoading,
+ error: groupError,
+ } = useSWR<z.infer<typeof PartnerProgramGroupSchema>>(
+ groupIdOrSlug
+ ? `/api/partner-profile/programs/${program.id}/groups/${groupIdOrSlug}`
+ : null,
+ fetcher,
+ {
+ keepPreviousData: true,
+ },
+ );
const form = useForm<FormData>({
defaultValues: {
termsAgreement: false,
- formData: formDataForApplicationFormData(
- program["group"].applicationFormData?.fields ?? [],
- ),
+ formData: { fields: group?.applicationFormData?.fields ?? [] },
},
});
@@ -75,21 +96,15 @@ function ProgramApplicationSheetContent({
});
const onSubmit = async (data: FormData) => {
- if (!program || !partner?.email || !partner.country) {
- toast.error(
- "Submission failed due to missing partner email or country. Please contact support.",
- );
- return;
- }
+ if (!group || !program || !partner?.email || !partner.country) return;
const result = await executeAsync({
- // @ts-ignore
- formData: { fields: [] },
...data,
email: partner.email,
name: partner.name,
country: partner.country,
programId: program.id,
+ groupId: group.id,
});
if (result?.serverError || result?.validationErrors) {
@@ -100,22 +115,22 @@ function ProgramApplicationSheetContent({
}
};
- const fields = program["group"].applicationFormData?.fields || [];
+ const fields = group?.applicationFormData?.fields || [];
return (
<FormProvider {...form}>
- <div className="relative h-full">
- <form
- onSubmit={handleSubmit(onSubmit)}
- className={cn(
- "flex h-full flex-col transition-opacity duration-200",
- isSubmitSuccessful && "pointer-events-none opacity-0",
- )}
- {...{
- inert: isSubmitSuccessful,
- }}
- >
- <div className="flex items-start justify-between bg-neutral-50 p-6">
+ <form
+ onSubmit={handleSubmit(onSubmit)}
+ className={cn(
+ "flex h-full flex-col transition-opacity duration-200",
+ isSubmitSuccessful && "pointer-events-none opacity-0",
+ )}
+ {...{
+ inert: isSubmitSuccessful,
+ }}
+ >
+ <div className="sticky top-0 z-10 border-b border-neutral-200 bg-neutral-50">
+ <div className="flex items-start justify-between p-6">
<Sheet.Title asChild className="min-w-0">
<div>
<div className="flex items-center gap-3">
@@ -147,117 +162,126 @@ function ProgramApplicationSheetContent({
/>
</Sheet.Close>
</div>
+ </div>
- <div className="flex flex-col gap-6 p-5 sm:p-8">
- {fields?.length ? (
- fields.map((field, index) => {
- return (
- <ProgramApplicationFormField
- key={field.id}
- field={field}
- keyPath={`formData.fields.${index}`}
- />
- );
- })
- ) : (
- <p className="text-content-subtle flex items-center gap-1 text-sm">
- <CircleCheck className="inline-block size-4 text-green-500" />
- No additional information required to apply
- </p>
- )}
+ <div className="min-h-0 flex-1 overflow-y-auto">
+ {isGroupLoading ? (
+ <div className="flex items-center justify-center py-8">
+ <LoadingSpinner />
+ </div>
+ ) : (
+ <div className="flex flex-col gap-6 p-5 sm:p-8">
+ {fields?.length ? (
+ fields.map((field, index) => {
+ return (
+ <ProgramApplicationFormField
+ key={field.id}
+ field={field}
+ keyPath={`formData.fields.${index}`}
+ />
+ );
+ })
+ ) : (
+ <p className="text-content-subtle flex items-center gap-1 text-sm">
+ <CircleCheck className="inline-block size-4 text-green-500" />
+ No additional information required to apply
+ </p>
+ )}
- {program.termsUrl && (
- <div className="flex items-center gap-2">
- <input
- type="checkbox"
- id="termsAgreement"
- className={cn(
- "h-4 w-4 rounded border-neutral-300 text-[var(--brand)] focus:ring-[var(--brand)]",
- errors.termsAgreement &&
- "border-red-400 focus:ring-red-500",
- )}
- {...register("termsAgreement", {
- required: true,
- validate: (v) => v === true,
- })}
- />
- <label
- htmlFor="termsAgreement"
- className="text-sm text-neutral-800"
- >
- I agree to the{" "}
- <a
- href={program.termsUrl}
- target="_blank"
- rel="noopener noreferrer"
- className="text-[var(--brand)] underline hover:opacity-80"
+ {program.termsUrl && (
+ <div className="flex items-center gap-2">
+ <input
+ type="checkbox"
+ id="termsAgreement"
+ className={cn(
+ "h-4 w-4 rounded border-neutral-300 text-[var(--brand)] focus:ring-[var(--brand)]",
+ errors.termsAgreement &&
+ "border-red-400 focus:ring-red-500",
+ )}
+ {...register("termsAgreement", {
+ required: true,
+ validate: (v) => v === true,
+ })}
+ />
+ <label
+ htmlFor="termsAgreement"
+ className="text-sm text-neutral-800"
>
- {program.name} Affiliate Program Terms ↗
- </a>
- </label>
- </div>
- )}
- </div>
-
- <div className="flex grow flex-col justify-end p-5">
- <Button
- type="submit"
- variant="primary"
- text="Submit application"
- loading={isSubmitting}
- />
- </div>
- </form>
- <div
- className={cn(
- "absolute inset-0 flex items-center justify-center transition-[transform,opacity]",
- isSubmitSuccessful
- ? "translate-y-0 opacity-100"
- : "pointer-events-none translate-y-4 opacity-0",
+ I agree to the{" "}
+ <a
+ href={program.termsUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-[var(--brand)] underline hover:opacity-80"
+ >
+ {program.name} Affiliate Program Terms ↗
+ </a>
+ </label>
+ </div>
+ )}
+ </div>
)}
- inert={!isSubmitSuccessful}
- >
- <Grid
- cellSize={60}
- className="[mask-image:linear-gradient(black,transparent)]"
+ </div>
+
+ <div className="sticky bottom-0 z-10 border-t border-neutral-200 bg-white p-5">
+ <Button
+ type="submit"
+ variant="primary"
+ text="Submit application"
+ disabled={isGroupLoading || groupError}
+ loading={isSubmitting}
/>
- <div className="relative flex flex-col items-center">
- <div className="relative z-0 flex items-center">
- <img
- src={program.logo || `${OG_AVATAR_URL}${program.name}`}
- alt={program.name}
- className="z-10 size-20 rotate-[-15deg] rounded-full drop-shadow-md"
- />
- <img
- src={partner?.image || `${OG_AVATAR_URL}${partner?.name}`}
- alt={partner?.name || "Your avatar"}
- className="-ml-4 size-20 rotate-[15deg] rounded-full drop-shadow-md"
- />
- <div className="absolute -bottom-2 left-1/2 z-10 -translate-x-1/2 rounded-full bg-white p-0.5">
- <CircleCheckFill className="size-8 text-green-500" />
- </div>
+ </div>
+ </form>
+ <div
+ className={cn(
+ "absolute inset-0 flex items-center justify-center transition-[transform,opacity]",
+ isSubmitSuccessful
+ ? "translate-y-0 opacity-100"
+ : "pointer-events-none translate-y-4 opacity-0",
+ )}
+ inert={!isSubmitSuccessful}
+ >
+ <Grid
+ cellSize={60}
+ className="[mask-image:linear-gradient(black,transparent)]"
+ />
+ <div className="relative flex flex-col items-center">
+ <div className="relative z-0 flex items-center">
+ <img
+ src={program.logo || `${OG_AVATAR_URL}${program.name}`}
+ alt={program.name}
+ className="z-10 size-20 rotate-[-15deg] rounded-full drop-shadow-md"
+ />
+ <img
+ src={partner?.image || `${OG_AVATAR_URL}${partner?.name}`}
+ alt={partner?.name || "Your avatar"}
+ className="-ml-4 size-20 rotate-[15deg] rounded-full drop-shadow-md"
+ />
+ <div className="absolute -bottom-2 left-1/2 z-10 -translate-x-1/2 rounded-full bg-white p-0.5">
+ <CircleCheckFill className="size-8 text-green-500" />
</div>
- <span className="mt-6 block text-base font-semibold text-neutral-900">
- Application submitted
- </span>
- <p className="mt-2 max-w-[300px] text-pretty text-center text-sm text-neutral-500">
- You're all set! Your application is pending review and we'll email
- you once approved.
- </p>
- <Link
- href={
- backDestination === "marketplace"
- ? "/programs/marketplace"
- : "/programs"
- }
- className={cn(
- buttonVariants({ variant: "primary" }),
- "mt-8 flex h-9 w-fit cursor-pointer items-center rounded-lg border px-4 text-sm",
- )}
- >
- Back to {backDestination}
- </Link>
</div>
+ <span className="mt-6 block text-base font-semibold text-neutral-900">
+ Application submitted
+ </span>
+ <p className="mt-2 max-w-[300px] text-pretty text-center text-sm text-neutral-500">
+ You're all set! Your application is pending review and we'll email
+ you once approved.
+ </p>
+ <Link
+ href={
+ backDestination === "marketplace"
+ ? "/programs/marketplace"
+ : "/programs"
+ }
+ className={cn(
+ buttonVariants({ variant: "primary" }),
+ "mt-8 flex h-9 w-fit cursor-pointer items-center rounded-lg border px-4 text-sm",
+ )}
+ >
+ Back to {backDestination}
+ </Link>
</div>
</div>
</FormProvider>
diff --git a/packages/prisma/schema/program.prisma b/packages/prisma/schema/program.prisma
index c89463a733..ed801435b9 100644
--- a/packages/prisma/schema/program.prisma
+++ b/packages/prisma/schema/program.prisma
@@ -85,6 +85,7 @@ model Program {
@@index(workspaceId)
@@index(domain)
+ @@index(addedToMarketplaceAt)
}
model ProgramEnrollment {
diff --git a/packages/ui/src/filter/filter-select.tsx b/packages/ui/src/filter/filter-select.tsx
index 356abe9441..692bc9ab3d 100644
--- a/packages/ui/src/filter/filter-select.tsx
+++ b/packages/ui/src/filter/filter-select.tsx
@@ -189,7 +189,7 @@ export function FilterSelect({
selectedFilterKey ? reset() : setIsOpen(false);
}
}}
- emptySubmit={(e) => {
+ emptysubmit={(e) => {
e.preventDefault();
e.stopPropagation();
if (askAI) {
@@ -326,7 +326,7 @@ function isEmptyStateObject(
const CommandInput = (
props: React.ComponentProps<typeof Command.Input> & {
- emptySubmit?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
+ emptysubmit?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
},
) => {
const isEmpty = useCommandState((state) => state.filtered.count === 0);
@@ -339,7 +339,7 @@ const CommandInput = (
props.onKeyDown?.(e);
if (e.key === "Enter" && isEmpty) {
- props.emptySubmit?.(e);
+ props.emptysubmit?.(e);
}
}}
autoCapitalize="none"