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.

Increase the usability of the manual commission flow (#3079)

Marcus Farrella11cedff0a81
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx
index 19baaed1cf..8f78902d95 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx
@@ -25,7 +25,13 @@ import {
ToggleGroup,
useTable,
} from "@dub/ui";
-import { cn, currencyFormatter, fetcher, formatDateTime } from "@dub/utils";
+import {
+ cn,
+ currencyFormatter,
+ fetcher,
+ formatDateTime,
+ pluralize,
+} from "@dub/utils";
import { CommissionType } from "@prisma/client";
import { useAction } from "next-safe-action/hooks";
import Link from "next/link";
@@ -536,14 +542,17 @@ function CreateCommissionSheetContent({
</h2>
</label>
<ToggleGroup
- className="mt-2 flex w-full items-center gap-1 rounded-md border border-neutral-200 bg-neutral-50 p-1"
+ className="mt-2 flex w-full items-center gap-1 rounded-lg border border-neutral-200 bg-neutral-50 p-1"
optionClassName="h-8 flex items-center justify-center rounded-md flex-1 text-sm normal-case"
indicatorClassName="bg-white"
options={[
- { value: "new", label: "Create new events" },
+ {
+ value: "new",
+ label: "Create new event",
+ },
{
value: "existing",
- label: "Use existing events",
+ label: `Use existing ${pluralize("event", filteredEvents.length)}`,
},
]}
selected={useExistingEvents ? "existing" : "new"}
@@ -647,10 +656,17 @@ function CreateCommissionSheetContent({
{hasCustomLeadEventName && (
<div className="p-px">
+ <label
+ htmlFor="leadEventName"
+ className="block text-sm font-medium text-neutral-900"
+ >
+ Lead event name
+ </label>
<input
+ id="leadEventName"
type="text"
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",
+ "mt-2 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.leadEventName &&
"border-red-600 focus:border-red-500 focus:ring-red-600",
)}
@@ -658,7 +674,7 @@ function CreateCommissionSheetContent({
setValueAs: (value) =>
value === "" ? null : value,
})}
- placeholder="Enter lead event name"
+ placeholder="Sign up"
/>
</div>
)}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/partner-stats.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/partner-stats.tsx
index eb2a3e9f70..63f193c99c 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/partner-stats.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/partner-stats.tsx
@@ -105,7 +105,7 @@ export function PartnerStats({
return (
<As
key={label}
- href={href ?? ""}
+ href={href ?? "#"}
target="_blank"
className="flex flex-col bg-white p-3 transition-colors duration-150 hover:bg-neutral-50"
>
diff --git a/apps/web/ui/customers/customer-selector.tsx b/apps/web/ui/customers/customer-selector.tsx
index f1a0c93d0c..ce4326889d 100644
--- a/apps/web/ui/customers/customer-selector.tsx
+++ b/apps/web/ui/customers/customer-selector.tsx
@@ -1,6 +1,6 @@
import useCustomers from "@/lib/swr/use-customers";
import { CUSTOMERS_MAX_PAGE_SIZE } from "@/lib/zod/schemas/customers";
-import { Button, Combobox } from "@dub/ui";
+import { Combobox } from "@dub/ui";
import { cn, OG_AVATAR_URL } from "@dub/utils";
import { useEffect, useMemo, useState } from "react";
import { useDebounce } from "use-debounce";
@@ -44,16 +44,18 @@ export function CustomerSelector({
});
const customerOptions = useMemo(() => {
- return customers?.map((customer) => ({
- value: customer.id,
- label: customer.name || customer.email || customer.externalId,
- icon: (
- <img
- src={customer.avatar || `${OG_AVATAR_URL}${customer.id}`}
- className="size-4 rounded-full"
- />
- ),
- }));
+ return (
+ customers?.map((customer) => ({
+ value: customer.id,
+ label: customer.name || customer.email || customer.externalId,
+ icon: (
+ <img
+ src={customer.avatar || `${OG_AVATAR_URL}${customer.id}`}
+ className="size-4 rounded-full"
+ />
+ ),
+ })) || []
+ );
}, [customers]);
const selectedOption = useMemo(() => {
@@ -89,8 +91,15 @@ export function CustomerSelector({
icon={selectedCustomersLoading ? null : selectedOption?.icon}
caret={true}
placeholder={selectedCustomersLoading ? "" : "Select customer"}
- searchPlaceholder="Search customer..."
+ searchPlaceholder="Search or create customer..."
onSearchChange={setSearch}
+ createLabel={(search) =>
+ `Create ${search ? `"${search}"` : "new customer"}`
+ }
+ onCreate={async () => {
+ setShowAddCustomerModal(true);
+ return true;
+ }}
shouldFilter={!useAsync}
matchTriggerWidth
open={openPopover}
@@ -102,20 +111,6 @@ export function CustomerSelector({
"focus:ring-1 focus:ring-neutral-500 focus:border-neutral-500 transition-none",
),
}}
- emptyState={
- <div className="flex w-full flex-col items-center gap-2 py-4">
- No customers found
- <Button
- onClick={() => {
- setOpenPopover(false);
- setShowAddCustomerModal(true);
- }}
- variant="primary"
- className="h-7 w-fit px-2"
- text="Create customer"
- />
- </div>
- }
>
{selectedCustomersLoading ? (
<div className="my-0.5 h-5 w-1/3 animate-pulse rounded bg-neutral-200" />
diff --git a/apps/web/ui/links/link-builder/tag-select.tsx b/apps/web/ui/links/link-builder/tag-select.tsx
index 0daaca61f3..d3f6cf7006 100644
--- a/apps/web/ui/links/link-builder/tag-select.tsx
+++ b/apps/web/ui/links/link-builder/tag-select.tsx
@@ -202,6 +202,7 @@ export const TagSelect = memo(() => {
selectedTags.length === 0 && "text-neutral-400",
),
}}
+ createLabel={(search) => `Create ${search ? `"${search}"` : "new tag"}`}
onCreate={(search) => createTag(search)}
open={isOpen}
onOpenChange={setIsOpen}
diff --git a/apps/web/ui/modals/add-customer-modal.tsx b/apps/web/ui/modals/add-customer-modal.tsx
index 6a3d22f6d3..993f60b388 100644
--- a/apps/web/ui/modals/add-customer-modal.tsx
+++ b/apps/web/ui/modals/add-customer-modal.tsx
@@ -2,7 +2,7 @@ import useWorkspace from "@/lib/swr/use-workspace";
import { CustomerProps } from "@/lib/types";
import { createCustomerBodySchema } from "@/lib/zod/schemas/customers";
import { Button, Modal, useMediaQuery } from "@dub/ui";
-import { useCallback, useMemo, useState } from "react";
+import { useCallback, useEffect, useMemo, useState } from "react";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import { mutate } from "swr";
@@ -12,6 +12,7 @@ interface AddCustomerModalProps {
showModal: boolean;
setShowModal: (showModal: boolean) => void;
onSuccess?: (customer: CustomerProps) => void;
+ initialName?: string;
}
type FormData = z.infer<typeof createCustomerBodySchema>;
@@ -20,6 +21,7 @@ const AddCustomerModal = ({
showModal,
setShowModal,
onSuccess,
+ initialName,
}: AddCustomerModalProps) => {
const { id: workspaceId } = useWorkspace();
const { isMobile } = useMediaQuery();
@@ -28,6 +30,7 @@ const AddCustomerModal = ({
register,
handleSubmit,
watch,
+ reset,
formState: { isSubmitting },
} = useForm<FormData>({
defaultValues: {
@@ -38,6 +41,24 @@ const AddCustomerModal = ({
},
});
+ useEffect(() => {
+ if (showModal && initialName) {
+ reset({
+ name: initialName,
+ email: null,
+ externalId: "",
+ stripeCustomerId: null,
+ });
+ } else if (showModal) {
+ reset({
+ name: null,
+ email: null,
+ externalId: "",
+ stripeCustomerId: null,
+ });
+ }
+ }, [showModal, initialName, reset]);
+
const onSubmit = async (data: FormData) => {
try {
const response = await fetch(
@@ -183,22 +204,37 @@ export function useAddCustomerModal({
onSuccess?: (customer: CustomerProps) => void;
} = {}) {
const [showAddCustomerModal, setShowAddCustomerModal] = useState(false);
+ const [initialName, setInitialName] = useState<string | undefined>();
const AddCustomerModalCallback = useCallback(() => {
return (
<AddCustomerModal
showModal={showAddCustomerModal}
- setShowModal={setShowAddCustomerModal}
+ setShowModal={(show) => {
+ setShowAddCustomerModal(show);
+ if (!show) {
+ setInitialName(undefined);
+ }
+ }}
onSuccess={onSuccess}
+ initialName={initialName}
/>
);
- }, [showAddCustomerModal, setShowAddCustomerModal]);
+ }, [showAddCustomerModal, initialName, onSuccess]);
+
+ const setShowAddCustomerModalWithName = useCallback(
+ (show: boolean, name?: string) => {
+ setShowAddCustomerModal(show);
+ setInitialName(name);
+ },
+ [],
+ );
return useMemo(
() => ({
- setShowAddCustomerModal,
+ setShowAddCustomerModal: setShowAddCustomerModalWithName,
AddCustomerModal: AddCustomerModalCallback,
}),
- [setShowAddCustomerModal, AddCustomerModalCallback],
+ [setShowAddCustomerModalWithName, AddCustomerModalCallback],
);
}
diff --git a/packages/ui/src/combobox/index.tsx b/packages/ui/src/combobox/index.tsx
index cca2863b66..436d95af98 100644
--- a/packages/ui/src/combobox/index.tsx
+++ b/packages/ui/src/combobox/index.tsx
@@ -1,5 +1,5 @@
import { cn } from "@dub/utils";
-import { Command, CommandInput, CommandItem, useCommandState } from "cmdk";
+import { Command, useCommandState } from "cmdk";
import { ChevronDown } from "lucide-react";
import {
forwardRef,
@@ -200,6 +200,35 @@ export function Combobox({
useEffect(() => onSearchChange?.(search), [search]);
+ const createOptionItem = (
+ <Command.Item
+ className={cn(
+ "flex cursor-pointer items-center gap-3 whitespace-nowrap rounded-md px-3 py-2 text-left text-sm text-neutral-700",
+ "data-[selected=true]:bg-neutral-100",
+ optionClassName,
+ )}
+ onSelect={async () => {
+ setIsCreating(true);
+ const success = await onCreate?.(search);
+ if (success) {
+ setSearch("");
+ setIsOpen(false);
+ }
+ setIsCreating(false);
+ }}
+ >
+ {isCreating ? (
+ <LoadingSpinner className="size-4 shrink-0" />
+ ) : (
+ <CreateIcon className="size-4 shrink-0" />
+ )}
+ <div className="grow truncate">
+ {createLabel?.(search) ??
+ `Create ${search ? `"${search}"` : "new option..."}`}
+ </div>
+ </Command.Item>
+ );
+
return (
<Popover
openPopover={isOpen}
@@ -225,7 +254,7 @@ export function Combobox({
<Command loop shouldFilter={shouldFilter}>
{!hideSearch && (
<div className="flex items-center overflow-hidden rounded-t-lg border-b border-neutral-200">
- <CommandInput
+ <Command.Input
placeholder={searchPlaceholder}
value={search}
onValueChange={setSearch}
@@ -252,7 +281,12 @@ export function Combobox({
)}
</div>
)}
- <ScrollContainer className="max-h-[min(50vh,250px)]">
+ <ScrollContainer
+ className={cn(
+ "max-h-[min(50vh,250px)]",
+ onCreate && !multiple && "max-h-[calc(min(50vh,250px)-3.5rem)]",
+ )}
+ >
<Command.List
className={cn("flex w-full min-w-[100px] flex-col gap-1 p-1")}
>
@@ -271,33 +305,11 @@ export function Combobox({
className={optionClassName}
/>
))}
- {search.length > 0 && onCreate && (
- <CommandItem
- className={cn(
- "flex cursor-pointer items-center gap-3 whitespace-nowrap rounded-md px-3 py-2 text-left text-sm text-neutral-700",
- "data-[selected=true]:bg-neutral-100",
- optionClassName,
- )}
- onSelect={async () => {
- setIsCreating(true);
- const success = await onCreate?.(search);
- if (success) {
- setSearch("");
- setIsOpen(false);
- }
- setIsCreating(false);
- }}
- >
- {isCreating ? (
- <LoadingSpinner className="size-4 shrink-0" />
- ) : (
- <CreateIcon className="size-4 shrink-0" />
- )}
- <div className="grow truncate">
- {createLabel?.(search) || `Create "${search}"`}
- </div>
- </CommandItem>
- )}
+ {/* for multiple selection, the create option item is shown at the bottom of the list */}
+ {onCreate &&
+ multiple &&
+ search.length > 0 &&
+ createOptionItem}
{shouldFilter ? (
<Empty className="flex min-h-12 items-center justify-center text-sm text-neutral-500">
{emptyState ? emptyState : "No matches"}
@@ -318,6 +330,12 @@ export function Combobox({
)}
</Command.List>
</ScrollContainer>
+ {/* for single selection, the create option item is shown as a sticky item outside of the scroll container */}
+ {onCreate && !multiple && (
+ <div className="rounded-b-lg border-t border-neutral-200 bg-white p-1">
+ {createOptionItem}
+ </div>
+ )}
</Command>
</AnimatedSizeContainer>
}
diff --git a/packages/ui/src/scroll-container.tsx b/packages/ui/src/scroll-container.tsx
index 674597d9c2..15917a2e43 100644
--- a/packages/ui/src/scroll-container.tsx
+++ b/packages/ui/src/scroll-container.tsx
@@ -25,7 +25,7 @@ export function ScrollContainer({
</div>
{/* Bottom scroll fade */}
<div
- className="pointer-events-none absolute bottom-0 left-0 hidden h-16 w-full rounded-b-lg bg-gradient-to-t from-white sm:block"
+ className="pointer-events-none absolute bottom-0 left-0 hidden h-16 w-full rounded-b-lg bg-gradient-to-t from-white to-transparent sm:block z-10"
style={{ opacity: 1 - Math.pow(scrollProgress, 2) }}
/>
</div>