The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
"How you work" section
Tim Wilsonec0fdab3f896
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/how-you-work-form.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/how-you-work-form.tsxnew file mode 100644index 0000000000..9eb50ae52f--- /dev/null+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/how-you-work-form.tsx@@ -0,0 +1,203 @@+import { updatePartnerProfileAction } from "@/lib/actions/partners/update-partner-profile";+import { PartnerProps } from "@/lib/types";+import { Button, Check2 } from "@dub/ui";+import { useAction } from "next-safe-action/hooks";+import { useEffect } from "react";+import { Controller, useForm } from "react-hook-form";+import { toast } from "sonner";+import { SettingsRow } from "./settings-row";++import {+ preferredEarningStructures,+ salesChannels,+} from "@/lib/partners/partner-profile";+import { PreferredEarningStructure, SalesChannel } from "@dub/prisma/client";+import { cn } from "@dub/utils";++type HowYouWorkFormData = {+ preferredEarningStructure: PreferredEarningStructure[];+ salesChannels: SalesChannel[];+};++export function HowYouWorkForm({ partner }: { partner?: PartnerProps }) {+ const {+ control,+ handleSubmit,+ setError,+ getValues,+ reset,+ formState: { isSubmitting, isSubmitSuccessful },+ } = useForm<HowYouWorkFormData>({+ defaultValues: {+ preferredEarningStructure: partner?.preferredEarningStructure ?? [],+ salesChannels: partner?.salesChannels ?? [],+ },+ });++ // Reset form dirty state after submit+ useEffect(() => {+ if (isSubmitSuccessful)+ reset(getValues(), { keepValues: true, keepDirty: false });+ }, [isSubmitSuccessful, reset, getValues]);++ const { executeAsync } = useAction(updatePartnerProfileAction, {+ onSuccess: () => {+ toast.success("Your profile has been updated.");+ },+ onError({ error }) {+ setError("root.serverError", {+ message: error.serverError,+ });++ toast.error(error.serverError);+ },+ });++ return (+ <div className="border-border-subtle divide-border-subtle flex flex-col divide-y rounded-lg border">+ <div className="px-6 py-8">+ <h3 className="text-content-emphasis text-lg font-semibold leading-7">+ How you work+ </h3>+ <p className="text-content-subtle text-sm font-normal leading-5">+ Share how you prefer to earn and promote products to help programs+ understand your style of partnership.+ </p>+ </div>++ <form+ onSubmit={handleSubmit(async (data) => {+ await executeAsync(data);+ })}+ >+ <SettingsRow+ heading="Preferred earning structure"+ description="Choose how you'd like to be rewarded. Select all that apply."+ >+ <div className="@container/panel">+ <div className="@sm/panel:grid-cols-2 grid grid-cols-1 gap-4">+ <Controller+ control={control}+ name="preferredEarningStructure"+ render={({ field }) => (+ <>+ {preferredEarningStructures.map((earningStructure) => (+ <label+ key={earningStructure.id}+ className="ring-border-subtle hover:bg-bg-muted flex cursor-pointer select-none items-center gap-2.5 rounded-full bg-white px-4 py-3 ring-1 transition-all duration-100 ease-out"+ >+ <input+ type="checkbox"+ className="hidden"+ checked={field.value.includes(earningStructure.id)}+ onChange={(e) =>+ e.target.checked+ ? field.onChange([+ ...field.value,+ earningStructure.id,+ ])+ : field.onChange(+ field.value.filter(+ (id) => id !== earningStructure.id,+ ),+ )+ }+ />+ <div+ className={cn(+ "bg-content-inverted border-border-default flex size-4 items-center justify-center rounded border",+ field.value.includes(earningStructure.id) &&+ "bg-content-emphasis border-content-emphasis",+ )}+ >+ <Check2+ className={cn(+ "text-content-inverted size-3",+ !field.value.includes(earningStructure.id) &&+ "opacity-0",+ )}+ />+ </div>+ <span className="text-content-emphasis text-sm font-medium">+ {earningStructure.label}+ </span>+ </label>+ ))}+ </>+ )}+ />+ </div>+ </div>+ </SettingsRow>++ <SettingsRow+ heading="Sales channels"+ description="Where you promote products and links. Select all that apply."+ >+ <div className="@container/panel">+ <div className="@sm/panel:grid-cols-2 grid grid-cols-1 gap-4">+ <Controller+ control={control}+ name="salesChannels"+ render={({ field }) => (+ <>+ {salesChannels.map((salesChannel) => (+ <label+ key={salesChannel.id}+ className="ring-border-subtle hover:bg-bg-muted flex cursor-pointer select-none items-center gap-2.5 rounded-full bg-white px-4 py-3 ring-1 transition-all duration-100 ease-out"+ >+ <input+ type="checkbox"+ className="hidden"+ checked={field.value.includes(salesChannel.id)}+ onChange={(e) =>+ e.target.checked+ ? field.onChange([+ ...field.value,+ salesChannel.id,+ ])+ : field.onChange(+ field.value.filter(+ (id) => id !== salesChannel.id,+ ),+ )+ }+ />+ <div+ className={cn(+ "bg-content-inverted border-border-default flex size-4 items-center justify-center rounded border",+ field.value.includes(salesChannel.id) &&+ "bg-content-emphasis border-content-emphasis",+ )}+ >+ <Check2+ className={cn(+ "text-content-inverted size-3",+ !field.value.includes(salesChannel.id) &&+ "opacity-0",+ )}+ />+ </div>+ <span className="text-content-emphasis text-sm font-medium">+ {salesChannel.label}+ </span>+ </label>+ ))}+ </>+ )}+ />+ </div>+ </div>+ </SettingsRow>++ <div className="flex items-center justify-end rounded-b-lg border-t border-neutral-200 bg-neutral-50 px-6 py-4">+ <Button+ text="Save changes"+ className="h-8 w-fit px-2.5"+ loading={isSubmitting}+ />+ </div>+ </form>+ </div>+ );+}diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsxindex 0614f546d4..7ec4bc12e9 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx@@ -6,6 +6,7 @@ import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";import { useMergePartnerAccountsModal } from "@/ui/partners/merge-accounts/merge-partner-accounts-modal";import { Button } from "@dub/ui";import { AboutYouForm } from "./about-you-form";+import { HowYouWorkForm } from "./how-you-work-form";import { ProfileDetailsForm } from "./profile-details-form";export function ProfileSettingsPageClient() {@@ -24,6 +25,7 @@ export function ProfileSettingsPageClient() {<PageWidthWrapper className="mb-20 flex flex-col gap-6"><ProfileDetailsForm partner={partner} /><AboutYouForm partner={partner} />+ <HowYouWorkForm partner={partner} /></PageWidthWrapper></PageContent>);diff --git a/apps/web/lib/partners/partner-profile.ts b/apps/web/lib/partners/partner-profile.tsindex e4595e205b..1e398c3a0a 100644--- a/apps/web/lib/partners/partner-profile.ts+++ b/apps/web/lib/partners/partner-profile.ts@@ -1,4 +1,9 @@-import { IndustryInterest, MonthlyTraffic } from "@dub/prisma/client";+import {+ IndustryInterest,+ MonthlyTraffic,+ PreferredEarningStructure,+ SalesChannel,+} from "@dub/prisma/client";import {BookOpen,BracketsCurly,@@ -153,7 +158,7 @@ export const industryInterests: {},];-export const monthlyTrafficAmounts = [+export const monthlyTrafficAmounts: { id: MonthlyTraffic; label: string }[] = [{id: MonthlyTraffic.ZeroToOneThousand,label: "0 - 1,000",@@ -175,3 +180,60 @@ export const monthlyTrafficAmounts = [label: "100,000+",},];++export const preferredEarningStructures: {+ id: PreferredEarningStructure;+ label: string;+}[] = [+ {+ id: PreferredEarningStructure.Revenue_Share,+ label: "Rev-share (% of sale)",+ },+ {+ id: PreferredEarningStructure.Per_Lead,+ label: "Per lead (CPL)",+ },+ {+ id: PreferredEarningStructure.Per_Sale,+ label: "Per sale (CPS)",+ },+ {+ id: PreferredEarningStructure.Per_Click,+ label: "Per click (CPC)",+ },+ {+ id: PreferredEarningStructure.One_Time_Payment,+ label: "One-time payment",+ },+];++export const salesChannels: { id: SalesChannel; label: string }[] = [+ {+ id: SalesChannel.Blogs,+ label: "Blogs",+ },+ {+ id: SalesChannel.Coupons,+ label: "Coupons",+ },+ {+ id: SalesChannel.Direct_Reselling,+ label: "Direct reselling",+ },+ {+ id: SalesChannel.Newsletters,+ label: "Newsletters",+ },+ {+ id: SalesChannel.Social_Media,+ label: "Social media",+ },+ {+ id: SalesChannel.Events,+ label: "Events",+ },+ {+ id: SalesChannel.Company_Referrals,+ label: "Company referrals",+ },+];