The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Customer name fix (#3165)
Marcus Farrell25451d55f2b6
diff --git a/apps/web/ui/customers/customer-selector.tsx b/apps/web/ui/customers/customer-selector.tsxindex 023eba4735..aa7b305851 100644--- a/apps/web/ui/customers/customer-selector.tsx+++ b/apps/web/ui/customers/customer-selector.tsx@@ -4,7 +4,7 @@ import { Combobox } from "@dub/ui";import { cn, OG_AVATAR_URL } from "@dub/utils";import { useEffect, useMemo, useState } from "react";import { useDebounce } from "use-debounce";-import { useAddCustomerModal } from "../modals/add-customer-modal";+import { AddCustomerModal } from "../modals/add-customer-modal";interface CustomerSelectorProps {selectedCustomerId: string;@@ -37,11 +37,8 @@ export function CustomerSelector({}}, [customers, useAsync]);- const { AddCustomerModal, setShowAddCustomerModal } = useAddCustomerModal({- onSuccess: (customer) => {- setSelectedCustomerId(customer.id);- },- });+ const [showAddCustomerModal, setShowAddCustomerModal] = useState(false);+ const [newCustomerName, setNewCustomerName] = useState<string | undefined>();const customerOptions = useMemo(() => {return (@@ -101,7 +98,14 @@ export function CustomerSelector({return (<>- <AddCustomerModal />+ <AddCustomerModal+ showModal={showAddCustomerModal}+ setShowModal={setShowAddCustomerModal}+ initialName={newCustomerName}+ onSuccess={(customer) => {+ setSelectedCustomerId(customer.id);+ }}+ /><Comboboxoptions={loading ? undefined : customerOptions}setSelected={(option) => {@@ -116,7 +120,8 @@ export function CustomerSelector({createLabel={(search) =>`Create ${search ? `"${search}"` : "new customer"}`}- onCreate={async () => {+ onCreate={async (search) => {+ setNewCustomerName(search);setShowAddCustomerModal(true);return true;}}diff --git a/apps/web/ui/modals/add-customer-modal.tsx b/apps/web/ui/modals/add-customer-modal.tsxindex 993f60b388..91e0661880 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, useEffect, useMemo, useState } from "react";+import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { useForm } from "react-hook-form";import { toast } from "sonner";import { mutate } from "swr";@@ -17,7 +17,7 @@ interface AddCustomerModalProps {type FormData = z.infer<typeof createCustomerBodySchema>;-const AddCustomerModal = ({+export const AddCustomerModal = ({showModal,setShowModal,onSuccess,@@ -41,22 +41,19 @@ const AddCustomerModal = ({},});+ const prevShowModal = useRef(showModal);+useEffect(() => {- if (showModal && initialName) {- reset({- name: initialName,- email: null,- externalId: "",- stripeCustomerId: null,- });- } else if (showModal) {+ // Only reset when the modal opens (transitions from false to true)+ if (showModal && !prevShowModal.current) {reset({- name: null,+ name: initialName || null,email: null,externalId: "",stripeCustomerId: null,});}+ prevShowModal.current = showModal;}, [showModal, initialName, reset]);const onSubmit = async (data: FormData) => {