The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
make createCommission more flexible
Steven Teyc508d8604035
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/create-commission-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/create-commission-sheet.tsxindex 028309843a..62b151d403 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/create-commission-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/create-commission-sheet.tsx@@ -36,11 +36,8 @@ function CreateCommissionSheetContent({const { partners } = usePartners();const { id: workspaceId } = useWorkspace();const [hasInvoiceId, setHasInvoiceId] = useState(false);- const [isNewCustomer, setIsNewCustomer] = useState(false);- const [hasDifferentCreationDate, setHasDifferentCreationDate] =- useState(false);- const [hasDifferentLeadEventName, setHasDifferentLeadEventName] =- useState(false);+ const [hasCustomLeadEventDate, setHasCustomLeadEventDate] = useState(false);+ const [hasCustomLeadEventName, setHasCustomLeadEventName] = useState(false);const {register,@@ -59,16 +56,10 @@ function CreateCommissionSheetContent({]);useEffect(() => {- if (!hasDifferentCreationDate) {+ if (!hasCustomLeadEventDate) {setValue("leadEventDate", null);}- }, [hasDifferentCreationDate, setValue]);-- useEffect(() => {- if (customerId) {- setValue("customerId", customerId, { shouldValidate: true });- }- }, [customerId, setValue]);+ }, [hasCustomLeadEventDate, setValue]);const partnerOptions = useMemo(() => {return partners?.map((partner) => ({@@ -85,12 +76,6 @@ function CreateCommissionSheetContent({}));}, [partners]);- const programDefaultReward = useMemo(() => {- return program?.rewards?.find(- (reward) => reward.id === program?.defaultRewardId,- );- }, [program]);-const { executeAsync, isPending } = useAction(createCommissionAction, {onSuccess: async () => {toast.success("A commission has been created for the partner!");@@ -126,9 +111,6 @@ function CreateCommissionSheetContent({});};- const displayLeadEventDate =- customerId && !isNewCustomer && programDefaultReward?.event === "sale";-return (<form onSubmit={handleSubmit(onSubmit)} className="flex h-full flex-col"><div className="sticky top-0 z-10 border-b border-neutral-200 bg-white">@@ -201,121 +183,6 @@ function CreateCommissionSheetContent({</div><div className="grid grid-cols-1 gap-6 rounded-xl border border-neutral-200 px-4 py-5">- {programDefaultReward?.event === "sale" && (- <SmartDateTimePicker- value={saleEventDate}- onChange={(date) => {- setValue("saleEventDate", date, { shouldDirty: true });- }}- label="Sale date"- required={programDefaultReward?.event === "sale"}- placeholder='E.g. "2024-03-01", "Last Thursday", "2 hours ago"'- />- )}-- {programDefaultReward?.event === "sale" && (- <div>- <label- htmlFor="saleAmount"- className="flex items-center space-x-2"- >- <h2 className="text-sm font-medium text-neutral-900">- Sale amount- </h2>- </label>- <div className="relative mt-2 rounded-md shadow-sm">- <span className="absolute inset-y-0 left-0 flex items-center pl-3 text-sm text-neutral-400">- $- </span>- <input- className={cn(- "block w-full rounded-md border-neutral-300 pl-6 pr-12 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",- errors.saleAmount &&- "border-red-600 focus:border-red-500 focus:ring-red-600",- )}- {...register("saleAmount", {- valueAsNumber: true,- min: 0,- onChange: handleMoneyInputChange,- setValueAs: (value) => (value === "" ? null : value),- required: programDefaultReward?.event === "sale",- })}- placeholder="0.00"- />- <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-sm text-neutral-400">- USD- </span>- </div>- </div>- )}-- {programDefaultReward?.event === "lead" && (- <SmartDateTimePicker- value={leadEventDate}- onChange={(date) => {- setValue("leadEventDate", date, { shouldDirty: true });- }}- label="Lead date"- placeholder='E.g. "2024-03-01", "Last Thursday", "2 hours ago"'- />- )}-- {programDefaultReward?.event !== "lead" && (- <AnimatedSizeContainer- height- transition={{ ease: "easeInOut", duration: 0.2 }}- className={!hasInvoiceId ? "hidden" : ""}- style={{ display: !hasInvoiceId ? "none" : "block" }}- >- <div className="flex items-center gap-4">- <Switch- fn={setHasInvoiceId}- checked={hasInvoiceId}- trackDimensions="w-8 h-4"- thumbDimensions="w-3 h-3"- thumbTranslate="translate-x-4"- />- <div className="flex gap-1">- <h3 className="text-sm font-medium text-neutral-700">- Add{" "}- </h3>- <span className="rounded-md border border-neutral-200 bg-neutral-100 px-1 py-0.5 text-xs">- invoiceID- </span>- </div>- </div>-- {hasInvoiceId && (- <div className="mt-4">- <label- htmlFor="invoiceId"- className="flex items-center space-x-2"- >- <h2 className="text-sm font-medium text-neutral-900">- Invoice ID- </h2>- </label>- <div className="mt-2 p-px">- <input- type="text"- id="invoiceId"- className={cn(- "block w-full rounded-md border-neutral-300 px-3 py-2 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",- errors.invoiceId &&- "border-red-600 focus:border-red-500 focus:ring-red-600",- )}- {...register("invoiceId", {- required: hasInvoiceId,- setValueAs: (value) => (value === "" ? null : value),- })}- placeholder="Enter invoice ID"- />- </div>- </div>- )}- </AnimatedSizeContainer>- )}-<div><label htmlFor="name" className="flex items-center space-x-2"><h2 className="text-sm font-medium text-neutral-900">@@ -328,25 +195,24 @@ function CreateCommissionSheetContent({setSelectedCustomerId={(id) => {setValue("customerId", id, { shouldDirty: true });}}- setIsNewCustomer={setIsNewCustomer}/></div></div>- {displayLeadEventDate && (+ {customerId && (<AnimatedSizeContainerheighttransition={{ ease: "easeInOut", duration: 0.2 }}style={{- height: hasDifferentCreationDate ? "auto" : "0px",+ height: hasCustomLeadEventDate ? "auto" : "0px",overflow: "hidden",}}><div className="flex flex-col gap-6"><div className="flex items-center gap-4"><Switch- fn={setHasDifferentCreationDate}- checked={hasDifferentCreationDate}+ fn={setHasCustomLeadEventDate}+ checked={hasCustomLeadEventDate}trackDimensions="w-8 h-4"thumbDimensions="w-3 h-3"thumbTranslate="translate-x-4"@@ -358,7 +224,7 @@ function CreateCommissionSheetContent({</div></div>- {hasDifferentCreationDate && (+ {hasCustomLeadEventDate && (<div className="p-px"><SmartDateTimePickervalue={leadEventDate}@@ -376,20 +242,20 @@ function CreateCommissionSheetContent({</AnimatedSizeContainer>)}- {displayLeadEventDate && (+ {customerId && (<AnimatedSizeContainerheighttransition={{ ease: "easeInOut", duration: 0.2 }}style={{- height: hasDifferentLeadEventName ? "auto" : "0px",+ height: hasCustomLeadEventName ? "auto" : "0px",overflow: "hidden",}}><div className="flex flex-col gap-6"><div className="flex items-center gap-4"><Switch- fn={setHasDifferentLeadEventName}- checked={hasDifferentLeadEventName}+ fn={setHasCustomLeadEventName}+ checked={hasCustomLeadEventName}trackDimensions="w-8 h-4"thumbDimensions="w-3 h-3"thumbTranslate="translate-x-4"@@ -401,7 +267,7 @@ function CreateCommissionSheetContent({</div></div>- {hasDifferentLeadEventName && (+ {hasCustomLeadEventName && (<div className="p-px"><inputtype="text"@@ -421,6 +287,101 @@ function CreateCommissionSheetContent({</AnimatedSizeContainer>)}</div>++ <div className="grid grid-cols-1 gap-6 rounded-xl border border-neutral-200 px-4 py-5">+ <SmartDateTimePicker+ value={saleEventDate}+ onChange={(date) => {+ setValue("saleEventDate", date, { shouldDirty: true });+ }}+ label="Sale date"+ placeholder='E.g. "2024-03-01", "Last Thursday", "2 hours ago"'+ />+ <div>+ <label+ htmlFor="saleAmount"+ className="flex items-center space-x-2"+ >+ <h2 className="text-sm font-medium text-neutral-900">+ Sale amount+ </h2>+ </label>+ <div className="relative mt-2 rounded-md shadow-sm">+ <span className="absolute inset-y-0 left-0 flex items-center pl-3 text-sm text-neutral-400">+ $+ </span>+ <input+ className={cn(+ "block w-full rounded-md border-neutral-300 pl-6 pr-12 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",+ errors.saleAmount &&+ "border-red-600 focus:border-red-500 focus:ring-red-600",+ )}+ {...register("saleAmount", {+ valueAsNumber: true,+ min: 0,+ onChange: handleMoneyInputChange,+ setValueAs: (value) => (value === "" ? null : value),+ })}+ placeholder="0.00"+ />+ <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-sm text-neutral-400">+ USD+ </span>+ </div>+ </div>++ <AnimatedSizeContainer+ height+ transition={{ ease: "easeInOut", duration: 0.2 }}+ className={!hasInvoiceId ? "hidden" : ""}+ style={{ display: !hasInvoiceId ? "none" : "block" }}+ >+ <div className="flex items-center gap-4">+ <Switch+ fn={setHasInvoiceId}+ checked={hasInvoiceId}+ trackDimensions="w-8 h-4"+ thumbDimensions="w-3 h-3"+ thumbTranslate="translate-x-4"+ />+ <div className="flex gap-1">+ <h3 className="text-sm font-medium text-neutral-700">Add </h3>+ <span className="rounded-md border border-neutral-200 bg-neutral-100 px-1 py-0.5 text-xs">+ invoiceID+ </span>+ </div>+ </div>++ {hasInvoiceId && (+ <div className="mt-4">+ <label+ htmlFor="invoiceId"+ className="flex items-center space-x-2"+ >+ <h2 className="text-sm font-medium text-neutral-900">+ Invoice ID+ </h2>+ </label>+ <div className="mt-2 p-px">+ <input+ type="text"+ id="invoiceId"+ className={cn(+ "block w-full rounded-md border-neutral-300 px-3 py-2 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",+ errors.invoiceId &&+ "border-red-600 focus:border-red-500 focus:ring-red-600",+ )}+ {...register("invoiceId", {+ required: hasInvoiceId,+ setValueAs: (value) => (value === "" ? null : value),+ })}+ placeholder="Enter invoice ID"+ />+ </div>+ </div>+ )}+ </AnimatedSizeContainer>+ </div></div></div>diff --git a/apps/web/lib/actions/partners/create-commission.ts b/apps/web/lib/actions/partners/create-commission.tsindex 755477b918..34fefc6bb7 100644--- a/apps/web/lib/actions/partners/create-commission.ts+++ b/apps/web/lib/actions/partners/create-commission.ts@@ -80,8 +80,6 @@ export const createCommissionAction = authActionClient}}- const shouldRecordSale = saleAmount && saleEventDate;-// Record clickconst dummyRequest = new Request(link.url, {headers: new Headers({@@ -150,7 +148,7 @@ export const createCommissionAction = authActionClient});// Record sale- if (shouldRecordSale) {+ if (saleAmount && saleEventDate) {const clickEvent = clickEventSchemaTB.parse({...clickData,bot: 0,diff --git a/apps/web/lib/swr/use-links.ts b/apps/web/lib/swr/use-links.tsindex ee09c21ac0..8ca7424317 100644--- a/apps/web/lib/swr/use-links.ts+++ b/apps/web/lib/swr/use-links.ts@@ -42,7 +42,16 @@ export default function useLinks(...opts,},{- exclude: ["import", "upgrade", "newLink"],+ include: [+ "folderId",+ "tagIds",+ "domain",+ "userId",+ "search",+ "sortBy",+ "sortOrder",+ "showArchived",+ ],},)}`: admindiff --git a/apps/web/ui/customers/customer-selector.tsx b/apps/web/ui/customers/customer-selector.tsxindex b3a68ecce1..f1a0c93d0c 100644--- a/apps/web/ui/customers/customer-selector.tsx+++ b/apps/web/ui/customers/customer-selector.tsx@@ -9,13 +9,11 @@ import { useAddCustomerModal } from "../modals/add-customer-modal";interface CustomerSelectorProps {selectedCustomerId: string;setSelectedCustomerId: (customerId: string) => void;- setIsNewCustomer: (isNewCustomer: boolean) => void;}export function CustomerSelector({selectedCustomerId,setSelectedCustomerId,- setIsNewCustomer,}: CustomerSelectorProps) {const [search, setSearch] = useState("");const [useAsync, setUseAsync] = useState(false);@@ -42,7 +40,6 @@ export function CustomerSelector({const { AddCustomerModal, setShowAddCustomerModal } = useAddCustomerModal({onSuccess: (customer) => {setSelectedCustomerId(customer.id);- setIsNewCustomer(true);},});@@ -87,7 +84,6 @@ export function CustomerSelector({options={loading ? undefined : customerOptions}setSelected={(option) => {setSelectedCustomerId(option.value);- setIsNewCustomer(false);}}selected={selectedOption}icon={selectedCustomersLoading ? null : selectedOption?.icon}diff --git a/apps/web/ui/partners/partner-link-selector.tsx b/apps/web/ui/partners/partner-link-selector.tsxindex d93bee1984..ee2a1a8f25 100644--- a/apps/web/ui/partners/partner-link-selector.tsx+++ b/apps/web/ui/partners/partner-link-selector.tsx@@ -43,9 +43,9 @@ export function PartnerLinkSelector({const { links } = useLinks({+ folderId: program?.defaultFolderId ?? undefined,domain: program?.domain ?? undefined,search: debouncedSearch,- sort: "clicks", // need to specify this to avoid the ?sort= param in the URL overriding the default...(partnerId && { partnerId }),includeDashboard: false,includeWebhooks: false,