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.

Edit customer info (#3372)

Kiran K0d365d80e673
diff --git a/apps/web/app/(ee)/api/customers/[id]/route.ts b/apps/web/app/(ee)/api/customers/[id]/route.ts
index 09fea0bc87..0d0ec718fa 100644
--- a/apps/web/app/(ee)/api/customers/[id]/route.ts
+++ b/apps/web/app/(ee)/api/customers/[id]/route.ts
@@ -57,9 +57,8 @@ export const PATCH = withWorkspace(
const { includeExpandedFields } =
getCustomersQuerySchema.parse(searchParams);
- const { name, email, avatar, externalId } = updateCustomerBodySchema.parse(
- await parseRequestBody(req),
- );
+ const { name, email, avatar, externalId, stripeCustomerId } =
+ updateCustomerBodySchema.parse(await parseRequestBody(req));
const customer = await getCustomerOrThrow(
{
@@ -91,6 +90,7 @@ export const PATCH = withWorkspace(
email,
avatar: finalCustomerAvatar,
externalId,
+ stripeCustomerId,
},
});
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
index e2d2aabdeb..80a734e0e3 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
@@ -79,7 +79,15 @@ export function ProgramCustomerPageClient() {
<div className="@3xl/page:grid-cols-[minmax(440px,1fr)_minmax(0,360px)] grid grid-cols-1 gap-6">
<div className="@3xl/page:order-2">
<CustomerDetailsColumn
- customer={customer}
+ customer={
+ customer && customer.id
+ ? {
+ ...customer,
+ name: customer.name || "",
+ externalId: "",
+ }
+ : undefined
+ }
customerActivity={customer?.activity}
isCustomerActivityLoading={!customer}
/>
diff --git a/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/page.tsx b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/page.tsx
index 71926a3e66..5cd8b19482 100644
--- a/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/page.tsx
+++ b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/page.tsx
@@ -1,3 +1,4 @@
+import { encodeKeyIfCaseSensitive } from "@/lib/api/links/case-sensitivity";
import { deepViewDataSchema } from "@/lib/zod/schemas/deep-links";
import { prisma } from "@dub/prisma";
import { Grid, Wordmark } from "@dub/ui";
@@ -9,7 +10,6 @@ import { redirect } from "next/navigation";
import { DeepLinkActionButtons } from "./action-buttons";
import { BrandLogoBadge } from "./brand-logo-badge";
import { getLanguage, getTranslations } from "./translations";
-import { encodeKeyIfCaseSensitive } from "@/lib/api/links/case-sensitivity";
export default async function DeepLinkPreviewPage(props: {
params: Promise<{ domain: string; key: string }>;
@@ -27,7 +27,7 @@ export default async function DeepLinkPreviewPage(props: {
// Encode the key for case-sensitive domains before querying
const encodedKey = encodeKeyIfCaseSensitive({
domain,
- key
+ key,
});
const link = await prisma.link.findUnique({
diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.ts
index ac57c6faa9..8d8da87707 100644
--- a/apps/web/lib/zod/schemas/customers.ts
+++ b/apps/web/lib/zod/schemas/customers.ts
@@ -93,7 +93,7 @@ export const createCustomerBodySchema = z.object({
"The customer's avatar URL. If not provided, a random avatar will be generated.",
),
externalId: z
- .string()
+ .string("External ID is required")
.describe(
"The customer's unique identifier your database. This is useful for associating subsequent conversion events from Dub's API to your internal systems.",
),
diff --git a/apps/web/ui/customers/customer-details-column.tsx b/apps/web/ui/customers/customer-details-column.tsx
index 393e19c1f4..d4bdef458f 100644
--- a/apps/web/ui/customers/customer-details-column.tsx
+++ b/apps/web/ui/customers/customer-details-column.tsx
@@ -1,5 +1,7 @@
import { CustomerActivityResponse, CustomerEnriched } from "@/lib/types";
import {
+ Button,
+ CalendarIcon,
CopyText,
Envelope,
Globe,
@@ -16,9 +18,11 @@ import {
getPrettyUrl,
OG_AVATAR_URL,
} from "@dub/utils";
+import { Pencil } from "lucide-react";
import { useParams } from "next/navigation";
import { Fragment, HTMLProps, useMemo } from "react";
import { DeviceIcon } from "../analytics/device-icon";
+import { useEditCustomerModal } from "../modals/edit-customer-modal";
import { ConditionalLink } from "../shared/conditional-link";
export function CustomerDetailsColumn({
@@ -28,30 +32,24 @@ export function CustomerDetailsColumn({
isProgramPage = false,
workspaceSlug,
}: {
- customer?: Omit<
- CustomerEnriched,
- "name" | "externalId" | "sales" | "saleAmount"
- > & {
- name?: string | null;
- externalId?: string;
- };
+ customer?: CustomerEnriched;
customerActivity?: CustomerActivityResponse;
isCustomerActivityLoading: boolean;
isProgramPage?: boolean;
workspaceSlug?: string;
}) {
const { programSlug } = useParams<{ programSlug: string }>();
+ const { EditCustomerModal, openEditCustomerModal } = useEditCustomerModal();
const basicFields = [
- ...(!customer || customer?.email
- ? [
- {
- id: "email",
- icon: <Envelope className="size-3.5 shrink-0" />,
- text: customer?.email,
- },
- ]
- : []),
+ customer?.email
+ ? {
+ id: "email",
+ icon: <Envelope className="size-3.5 shrink-0" />,
+ text: customer.email,
+ }
+ : null,
+
{
id: "country",
icon: customer?.country ? (
@@ -65,7 +63,32 @@ export function CustomerDetailsColumn({
),
text: customer?.country ? COUNTRIES[customer.country] : "Planet Earth",
},
- ];
+
+ customer?.createdAt
+ ? {
+ id: "since",
+ icon: <CalendarIcon className="size-3.5 shrink-0" />,
+ text: (
+ <span>
+ Since{" "}
+ <TimestampTooltip
+ timestamp={customer.createdAt}
+ rows={["local", "utc", "unix"]}
+ side="left"
+ >
+ <span>
+ {new Date(customer.createdAt).toLocaleDateString("en-US", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ })}
+ </span>
+ </TimestampTooltip>
+ </span>
+ ),
+ }
+ : null,
+ ].filter((field): field is NonNullable<typeof field> => field !== null);
const partner = customer?.partner;
const link = customerActivity?.link;
@@ -82,263 +105,253 @@ export function CustomerDetailsColumn({
}, [click?.url]);
return (
- <div className="grid grid-cols-1 gap-6 overflow-hidden whitespace-nowrap text-sm text-neutral-900">
- <div className="border-border-subtle flex flex-col divide-y divide-neutral-200 rounded-xl border bg-white">
- <div className="p-4">
- <div className="flex items-start justify-between gap-2">
- <div className="relative w-fit">
- {customer ? (
- <img
- src={customer.avatar || `${OG_AVATAR_URL}${customer.id}`}
- alt={customer.id}
- className="size-10 rounded-full border border-neutral-100"
+ <>
+ <EditCustomerModal />
+ <div className="grid grid-cols-1 gap-6 overflow-hidden whitespace-nowrap text-sm text-neutral-900">
+ <div className="border-border-subtle flex flex-col divide-y divide-neutral-200 rounded-xl border bg-white">
+ <div className="p-4">
+ <div className="flex items-start justify-between gap-2">
+ <div className="relative w-fit">
+ {customer ? (
+ <img
+ src={customer.avatar || `${OG_AVATAR_URL}${customer.id}`}
+ alt={customer.id}
+ className="size-10 rounded-full border border-neutral-100"
+ />
+ ) : (
+ <div className="size-10 animate-pulse rounded-full bg-neutral-200" />
+ )}
+ </div>
+
+ {customer && (
+ <Button
+ variant="secondary"
+ icon={<Pencil className="size-4" />}
+ text="Edit"
+ className="h-7 w-fit rounded-lg px-2"
+ onClick={() => openEditCustomerModal(customer)}
/>
- ) : (
- <div className="size-10 animate-pulse rounded-full bg-neutral-200" />
)}
</div>
- {customer ? (
- <div className="text-content-default bg-bg-emphasis rounded-md px-1 text-xs font-medium">
- Since{" "}
- <TimestampTooltip
- timestamp={customer.createdAt}
- rows={["local", "utc", "unix"]}
- side="left"
- >
- <span>
- {new Date(customer.createdAt).toLocaleDateString("en-US", {
- month: "short",
- day: "numeric",
- year: "numeric",
- })}
+ <div className="mt-3">
+ {customer ? (
+ <div className="flex items-center gap-2">
+ <span className="text-content-emphasis text-base font-semibold">
+ {customer.name || customer.email}
</span>
- </TimestampTooltip>
- </div>
- ) : (
- <div className="h-5 w-24 animate-pulse rounded-md bg-neutral-100" />
- )}
+ </div>
+ ) : (
+ <div className="h-7 w-24 animate-pulse rounded bg-neutral-200" />
+ )}
+ </div>
</div>
- <div className="mt-3">
- {customer ? (
- <div className="flex items-center gap-2">
- <span className="text-content-emphasis text-base font-semibold">
- {customer.name || customer.email}
- </span>
- </div>
- ) : (
- <div className="h-7 w-24 animate-pulse rounded bg-neutral-200" />
- )}
+ <div className="flex flex-col gap-2 p-4">
+ {basicFields.map(({ id, icon, text }) => (
+ <div key={id}>
+ <div className="text-content-default flex items-center gap-1.5">
+ {text !== undefined ? (
+ <>
+ {icon}
+ <span className="min-w-0 truncate text-xs font-medium">
+ {text}
+ </span>
+ </>
+ ) : (
+ <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
+ )}
+ </div>
+ </div>
+ ))}
</div>
- </div>
- <div className="flex flex-col gap-2 p-4">
- {basicFields
- .filter(({ text }) => text !== null)
- .map(({ id, icon, text }) => (
- <div key={id}>
- <div className="text-content-default flex items-center gap-1.5">
- {text !== undefined ? (
- <>
- {icon}
- <span className="min-w-0 truncate text-xs font-medium">
- {text}
- </span>
- </>
- ) : (
- <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
- )}
- </div>
- </div>
- ))}
- </div>
+ <div className="@md/page:grid-cols-2 @3xl/page:grid-cols-1 grid grid-cols-1 gap-5 p-4 text-xs">
+ <div>
+ <h2 className="text-content-emphasis text-sm font-semibold">
+ Details
+ </h2>
- <div className="@md/page:grid-cols-2 @3xl/page:grid-cols-1 grid grid-cols-1 gap-5 p-4 text-xs">
- <div>
- <h2 className="text-content-emphasis text-sm font-semibold">
- Details
- </h2>
+ <div className="mt-2.5 flex flex-col gap-5 text-xs">
+ <div className="flex flex-col gap-2">
+ {click
+ ? [
+ {
+ key: "device",
+ icon: (
+ <DeviceIcon
+ display={capitalize(click.device)!}
+ tab="devices"
+ className="size-3.5 shrink-0"
+ />
+ ),
+ value: click.device,
+ },
+ {
+ key: "browser",
+ icon: (
+ <DeviceIcon
+ display={capitalize(click.browser)!}
+ tab="browsers"
+ className="size-3.5 shrink-0"
+ />
+ ),
+ value: click.browser,
+ },
+ {
+ key: "os",
+ icon: (
+ <DeviceIcon
+ display={capitalize(click.os)!}
+ tab="os"
+ className="size-3.5 shrink-0"
+ />
+ ),
+ value: click.os,
+ },
+ ]
+ .filter(({ value }) => value)
+ .map(({ key, icon, value }) => (
+ <ConditionalLink
+ key={key}
+ href={
+ value === "Unknown"
+ ? undefined
+ : `/${workspaceSlug || `programs/${programSlug}`}/${isProgramPage ? "program/" : ""}analytics?${key}=${encodeURIComponent(value)}`
+ }
+ target="_blank"
+ >
+ <span className="flex items-center gap-2">
+ {icon}
+ <span className="truncate">{value}</span>
+ </span>
+ </ConditionalLink>
+ ))
+ : (isCustomerActivityLoading || !customer) && (
+ <div className="h-5 w-12 animate-pulse rounded-md bg-neutral-100" />
+ )}
+ </div>
- <div className="mt-2.5 flex flex-col gap-5 text-xs">
- <div className="flex flex-col gap-2">
- {click
- ? [
- {
- key: "device",
- icon: (
- <DeviceIcon
- display={capitalize(click.device)!}
- tab="devices"
- className="size-3.5 shrink-0"
- />
- ),
- value: click.device,
- },
- {
- key: "browser",
- icon: (
- <DeviceIcon
- display={capitalize(click.browser)!}
- tab="browsers"
- className="size-3.5 shrink-0"
- />
- ),
- value: click.browser,
- },
- {
- key: "os",
- icon: (
- <DeviceIcon
- display={capitalize(click.os)!}
- tab="os"
- className="size-3.5 shrink-0"
- />
- ),
- value: click.os,
- },
- ]
- .filter(({ value }) => value)
- .map(({ key, icon, value }) => (
- <ConditionalLink
- key={key}
- href={
- value === "Unknown"
- ? undefined
- : `/${workspaceSlug || `programs/${programSlug}`}/${isProgramPage ? "program/" : ""}analytics?${key}=${encodeURIComponent(value)}`
- }
- target="_blank"
- >
- <span className="flex items-center gap-2">
- {icon}
- <span className="truncate">{value}</span>
- </span>
- </ConditionalLink>
- ))
- : (isCustomerActivityLoading || !customer) && (
- <div className="h-5 w-12 animate-pulse rounded-md bg-neutral-100" />
- )}
- </div>
+ {customer?.externalId && (
+ <div className="flex flex-col gap-2.5">
+ <DetailHeading>External ID</DetailHeading>
+ <div>
+ <CopyText
+ value={customer.externalId}
+ className="truncate text-xs"
+ >
+ {customer.externalId}
+ </CopyText>
+ </div>
+ </div>
+ )}
- {customer?.externalId && (
- <div className="flex flex-col gap-2.5">
- <DetailHeading>External ID</DetailHeading>
- <div>
- <CopyText
- value={customer.externalId}
- className="truncate text-xs"
- >
- {customer.externalId}
- </CopyText>
+ {customer?.stripeCustomerId && (
+ <div className="flex flex-col gap-2.5">
+ <DetailHeading>Stripe Customer ID</DetailHeading>
+ <div>
+ <Tooltip content="View in Stripe" align="start">
+ <div>
+ <ConditionalLink
+ href={`https://dashboard.stripe.com/customers/${customer.stripeCustomerId}`}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="truncate text-xs"
+ >
+ {customer.stripeCustomerId}
+ </ConditionalLink>
+ </div>
+ </Tooltip>
+ </div>
</div>
- </div>
- )}
+ )}
+ </div>
+ </div>
- {customer?.stripeCustomerId && (
+ {utmParams && Boolean(utmParams.length) && (
+ <div className="flex flex-col gap-5 text-xs">
<div className="flex flex-col gap-2.5">
- <DetailHeading>Stripe Customer ID</DetailHeading>
- <div>
- <Tooltip content="View in Stripe" align="start">
- <div>
+ <DetailHeading>UTM</DetailHeading>
+ <div className="grid w-full grid-cols-[min-content,minmax(0,1fr)] gap-x-4 gap-y-2 overflow-hidden">
+ {utmParams.map(({ key, label, value }) => (
+ <Fragment key={key}>
+ <span className="truncate">{label}</span>
<ConditionalLink
- href={`https://dashboard.stripe.com/customers/${customer.stripeCustomerId}`}
+ href={
+ workspaceSlug
+ ? `/${workspaceSlug}/${isProgramPage ? "program/" : ""}analytics?${key}=${encodeURIComponent(value)}`
+ : undefined
+ }
target="_blank"
- rel="noopener noreferrer"
- className="truncate text-xs"
+ className="truncate text-neutral-500"
>
- {customer.stripeCustomerId}
+ {value}
</ConditionalLink>
- </div>
- </Tooltip>
+ </Fragment>
+ ))}
</div>
</div>
- )}
- </div>
- </div>
-
- {utmParams && Boolean(utmParams.length) && (
- <div className="flex flex-col gap-5 text-xs">
- <div className="flex flex-col gap-2.5">
- <DetailHeading>UTM</DetailHeading>
- <div className="grid w-full grid-cols-[min-content,minmax(0,1fr)] gap-x-4 gap-y-2 overflow-hidden">
- {utmParams.map(({ key, label, value }) => (
- <Fragment key={key}>
- <span className="truncate">{label}</span>
- <ConditionalLink
- href={
- workspaceSlug
- ? `/${workspaceSlug}/${isProgramPage ? "program/" : ""}analytics?${key}=${encodeURIComponent(value)}`
- : undefined
- }
- target="_blank"
- className="truncate text-neutral-500"
- >
- {value}
- </ConditionalLink>
- </Fragment>
- ))}
- </div>
</div>
- </div>
- )}
+ )}
+ </div>
</div>
- </div>
-
- {(link || !customer) && (
- <div className="border-border-subtle rounded-lg border p-4">
- <h2 className="text-content-emphasis mb-2.5 text-sm font-semibold">
- Referral {partner ? "partner" : "link"}
- </h2>
- {partner && (
- <div className="mb-4 flex items-center gap-2">
- <img
- src={partner.image || `${OG_AVATAR_URL}${partner.id}`}
- alt=""
- className="size-5 rounded-full"
- />
- <ConditionalLink
- href={
- workspaceSlug
- ? `/${workspaceSlug}/program/partners/${partner.id}`
- : undefined
- }
- target="_blank"
- className="min-w-0 overflow-hidden truncate text-xs font-semibold"
- >
- {partner.name}
- </ConditionalLink>
- </div>
- )}
+ {(link || !customer) && (
+ <div className="border-border-subtle rounded-lg border p-4">
+ <h2 className="text-content-emphasis mb-2.5 text-sm font-semibold">
+ Referral {partner ? "partner" : "link"}
+ </h2>
- <div className="flex flex-col gap-2 text-xs">
- {partner && <DetailHeading>Referral link</DetailHeading>}
- {!customer || isCustomerActivityLoading ? (
- <div className="h-5 w-12 animate-pulse rounded-md bg-neutral-100" />
- ) : link ? (
- <div className="flex items-center gap-1.5">
- <Hyperlink className="size-3.5 shrink-0" />
+ {partner && (
+ <div className="mb-4 flex items-center gap-2">
+ <img
+ src={partner.image || `${OG_AVATAR_URL}${partner.id}`}
+ alt=""
+ className="size-5 rounded-full"
+ />
<ConditionalLink
href={
workspaceSlug
- ? `/${workspaceSlug}/links/${link.domain}/${link.key}`
- : programSlug
- ? `/programs/${programSlug}/analytics?domain=${encodeURIComponent(link.domain)}&key=${encodeURIComponent(link.key)}`
- : undefined
+ ? `/${workspaceSlug}/program/partners/${partner.id}`
+ : undefined
}
target="_blank"
- className="min-w-0 overflow-hidden truncate"
+ className="min-w-0 overflow-hidden truncate text-xs font-semibold"
>
- {getPrettyUrl(link.shortLink)}
+ {partner.name}
</ConditionalLink>
</div>
- ) : (
- <span>-</span>
)}
+
+ <div className="flex flex-col gap-2 text-xs">
+ {partner && <DetailHeading>Referral link</DetailHeading>}
+ {!customer || isCustomerActivityLoading ? (
+ <div className="h-5 w-12 animate-pulse rounded-md bg-neutral-100" />
+ ) : link ? (
+ <div className="flex items-center gap-1.5">
+ <Hyperlink className="size-3.5 shrink-0" />
+ <ConditionalLink
+ href={
+ workspaceSlug
+ ? `/${workspaceSlug}/links/${link.domain}/${link.key}`
+ : programSlug
+ ? `/programs/${programSlug}/analytics?domain=${encodeURIComponent(link.domain)}&key=${encodeURIComponent(link.key)}`
+ : undefined
+ }
+ target="_blank"
+ className="min-w-0 overflow-hidden truncate"
+ >
+ {getPrettyUrl(link.shortLink)}
+ </ConditionalLink>
+ </div>
+ ) : (
+ <span>-</span>
+ )}
+ </div>
</div>
- </div>
- )}
- </div>
+ )}
+ </div>
+ </>
);
}
diff --git a/apps/web/ui/modals/edit-customer-modal.tsx b/apps/web/ui/modals/edit-customer-modal.tsx
new file mode 100644
index 0000000000..abf0ec68d1
--- /dev/null
+++ b/apps/web/ui/modals/edit-customer-modal.tsx
@@ -0,0 +1,201 @@
+import { mutatePrefix } from "@/lib/swr/mutate";
+import { useApiMutation } from "@/lib/swr/use-api-mutation";
+import { CustomerEnriched, CustomerProps } from "@/lib/types";
+import { updateCustomerBodySchema } from "@/lib/zod/schemas/customers";
+import { Button, Modal, useMediaQuery } from "@dub/ui";
+import { useEffect, useState } from "react";
+import { useForm } from "react-hook-form";
+import { toast } from "sonner";
+import * as z from "zod/v4";
+
+type FormData = z.infer<typeof updateCustomerBodySchema>;
+
+type EditCustomerModalProps = {
+ showModal: boolean;
+ setShowModal: (showModal: boolean) => void;
+ customer: Pick<
+ CustomerEnriched,
+ "id" | "name" | "email" | "stripeCustomerId" | "externalId"
+ >;
+};
+
+function EditCustomerModal({
+ showModal,
+ setShowModal,
+ customer,
+}: EditCustomerModalProps) {
+ const { isMobile } = useMediaQuery();
+ const { makeRequest: updateCustomer, isSubmitting } =
+ useApiMutation<CustomerProps>();
+
+ const {
+ register,
+ handleSubmit,
+ reset,
+ formState: { isDirty },
+ } = useForm<FormData>({
+ defaultValues: {
+ name: customer?.name || null,
+ email: customer?.email || null,
+ stripeCustomerId: customer?.stripeCustomerId || null,
+ externalId: customer?.externalId || "",
+ },
+ });
+
+ useEffect(() => {
+ if (showModal) {
+ reset({
+ name: customer?.name || null,
+ email: customer?.email || null,
+ stripeCustomerId: customer?.stripeCustomerId || null,
+ externalId: customer?.externalId || "",
+ });
+ }
+ }, [showModal, customer, reset]);
+
+ const onSubmit = async (data: FormData) => {
+ await updateCustomer(`/api/customers/${customer.id}`, {
+ method: "PATCH",
+ body: data,
+ onSuccess: async () => {
+ setShowModal(false);
+ await mutatePrefix("/api/customers");
+ toast.success("Customer updated successfully!");
+ },
+ });
+ };
+
+ return (
+ <Modal showModal={showModal} setShowModal={setShowModal}>
+ <div className="space-y-2 border-b border-neutral-200 px-4 py-4 sm:px-6">
+ <h3 className="text-lg font-medium">Edit customer</h3>
+ </div>
+
+ <div className="bg-neutral-50">
+ <form
+ onSubmit={(e) => {
+ e.stopPropagation();
+ return handleSubmit(onSubmit)(e);
+ }}
+ >
+ <div className="flex flex-col gap-4 px-4 py-6 text-left sm:px-6">
+ <div>
+ <label className="text-content-emphasis text-sm font-normal">
+ Name
+ </label>
+ <input
+ type="text"
+ autoComplete="off"
+ className="border-border-subtle mt-2 block w-full rounded-lg text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ placeholder="John Doe"
+ autoFocus={!isMobile}
+ {...register("name", {
+ setValueAs: (value) => (value === "" ? null : value),
+ })}
+ />
+ </div>
+
+ <div>
+ <label className="text-content-emphasis text-sm font-normal">
+ Email
+ </label>
+ <input
+ type="email"
+ autoComplete="off"
+ className="border-border-subtle mt-2 block w-full rounded-lg text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ placeholder="[email protected]"
+ {...register("email", {
+ setValueAs: (value) => (value === "" ? null : value),
+ })}
+ />
+ </div>
+
+ <div>
+ <label className="text-content-emphasis text-sm font-normal">
+ External ID
+ </label>
+ <input
+ type="text"
+ autoComplete="off"
+ className="border-border-subtle mt-2 block w-full rounded-lg text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ placeholder="user_1K92AP652K2R7ANJAAHKENJNF"
+ {...register("externalId", {
+ setValueAs: (value) => (value === "" ? null : value),
+ })}
+ />
+ </div>
+
+
+ <div>
+ <label className="text-content-emphasis text-sm font-normal">
+ Stripe Customer ID
+ </label>
+ <input
+ type="text"
+ autoComplete="off"
+ className="border-border-subtle mt-2 block w-full rounded-lg text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ placeholder="cus_N1YwZ8JxQ2AbC9"
+ {...register("stripeCustomerId", {
+ setValueAs: (value) => (value === "" ? null : value),
+ })}
+ />
+ </div>
+ </div>
+
+ <div className="flex items-center justify-end border-t border-neutral-200 px-4 py-4 sm:px-6">
+ <div className="flex gap-2">
+ <Button
+ type="button"
+ variant="secondary"
+ text="Cancel"
+ className="h-9 w-fit"
+ onClick={() => setShowModal(false)}
+ disabled={isSubmitting}
+ />
+ <Button
+ type="submit"
+ text="Save"
+ className="h-9 w-fit"
+ loading={isSubmitting}
+ disabled={!isDirty}
+ />
+ </div>
+ </div>
+ </form>
+ </div>
+ </Modal>
+ );
+}
+
+export function useEditCustomerModal() {
+ const [customer, setCustomer] = useState<CustomerEnriched | null>(null);
+
+ function openEditCustomerModal(customer: CustomerEnriched) {
+ setCustomer(customer);
+ }
+
+ function closeEditCustomerModal() {
+ setCustomer(null);
+ }
+
+ function EditCustomerModalWrapper() {
+ if (!customer) return null;
+
+ return (
+ <EditCustomerModal
+ customer={customer}
+ showModal
+ setShowModal={(show) => {
+ if (!show) closeEditCustomerModal();
+ }}
+ />
+ );
+ }
+
+ return {
+ openEditCustomerModal,
+ closeEditCustomerModal,
+ EditCustomerModal: EditCustomerModalWrapper,
+ isEditCustomerModalOpen: customer !== null,
+ };
+}