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.

CustomerDetailsSheet

Steven Tey4b29ef277764
diff --git a/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/payout-details-sheet.tsx b/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/payout-details-sheet.tsx
index b011ad78ce..70214db429 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/payout-details-sheet.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/payout-details-sheet.tsx
@@ -24,7 +24,7 @@ import {
formatDateTime,
} from "@dub/utils";
import Link from "next/link";
-import { Dispatch, Fragment, SetStateAction, useMemo, useState } from "react";
+import { Dispatch, Fragment, SetStateAction, useMemo } from "react";
import useSWR from "swr";
type PayoutDetailsSheetProps = {
@@ -249,20 +249,3 @@ export function PayoutDetailsSheet({
</Sheet>
);
}
-
-export function usePayoutDetailsSheet({
- payout,
-}: Omit<PayoutDetailsSheetProps, "setIsOpen">) {
- const [isOpen, setIsOpen] = useState(false);
-
- return {
- payoutDetailsSheet: (
- <PayoutDetailsSheet
- payout={payout}
- isOpen={isOpen}
- setIsOpen={setIsOpen}
- />
- ),
- setIsOpen,
- };
-}
diff --git a/apps/web/scripts/backfill-customers.ts b/apps/web/scripts/backfill-customers.ts
index f0edf93aa6..260c5b6907 100644
--- a/apps/web/scripts/backfill-customers.ts
+++ b/apps/web/scripts/backfill-customers.ts
@@ -75,7 +75,7 @@ async function main() {
);
if (!leadEvent || !clickEvent) {
- return;
+ return customer;
}
return prisma.customer.update({
@@ -94,13 +94,6 @@ async function main() {
clickedAt: true,
},
});
- // return {
- // linkId: clickEvent.link_id,
- // clickId: clickEvent.click_id,
- // country: clickEvent.country,
- // clickedAt: new Date(clickEvent.timestamp + "Z"),
- // createdAt: customer.createdAt,
- // };
}),
);
diff --git a/apps/web/ui/analytics/events/customer-row-item.tsx b/apps/web/ui/analytics/events/customer-row-item.tsx
index b5e92f3b50..02eab77773 100644
--- a/apps/web/ui/analytics/events/customer-row-item.tsx
+++ b/apps/web/ui/analytics/events/customer-row-item.tsx
@@ -1,22 +1,24 @@
import { generateRandomName } from "@/lib/names";
import { Customer } from "@/lib/types";
-import { useCustomerDetailsSheet } from "@/ui/partners/customer-details-sheet";
-import { ChartActivity2 } from "@dub/ui";
+import { ChartActivity2, useRouterStuff } from "@dub/ui";
+import Link from "next/link";
export function CustomerRowItem({ customer }: { customer: Customer }) {
- const { customerDetailsSheet, setIsOpen: setShowCustomerDetailsSheet } =
- useCustomerDetailsSheet({
- customer,
- });
-
const display = customer.name || customer.email || generateRandomName();
+ const { queryParams } = useRouterStuff();
return (
<>
- {customerDetailsSheet}
- <button
+ <Link
+ href={
+ queryParams({
+ set: {
+ customerId: customer.id,
+ },
+ getNewPath: true,
+ }) as string
+ }
className="flex w-full items-center justify-between px-4 py-2.5 transition-colors hover:bg-stone-100"
- onClick={() => setShowCustomerDetailsSheet(true)}
>
<div className="flex items-center gap-3" title={display}>
<img
@@ -27,7 +29,7 @@ export function CustomerRowItem({ customer }: { customer: Customer }) {
<span className="truncate">{display}</span>
</div>
<ChartActivity2 className="size-3.5" />
- </button>
+ </Link>
</>
);
}
diff --git a/apps/web/ui/analytics/events/events-table.tsx b/apps/web/ui/analytics/events/events-table.tsx
index f738a76fce..e84a4dd23b 100644
--- a/apps/web/ui/analytics/events/events-table.tsx
+++ b/apps/web/ui/analytics/events/events-table.tsx
@@ -1,7 +1,8 @@
"use client";
import { editQueryString } from "@/lib/analytics/utils";
-import { ClickEvent, LeadEvent, SaleEvent } from "@/lib/types";
+import { ClickEvent, Customer, LeadEvent, SaleEvent } from "@/lib/types";
+import { CustomerDetailsSheet } from "@/ui/partners/customer-details-sheet";
import EmptyState from "@/ui/shared/empty-state";
import {
CopyText,
@@ -25,7 +26,7 @@ import {
} from "@dub/utils";
import { Cell, ColumnDef } from "@tanstack/react-table";
import { Link2 } from "lucide-react";
-import { ReactNode, useContext, useEffect, useMemo } from "react";
+import { ReactNode, useContext, useEffect, useMemo, useState } from "react";
import useSWR from "swr";
import { AnalyticsContext } from "../analytics-provider";
import ContinentIcon from "../continent-icon";
@@ -506,20 +507,54 @@ export default function EventsTable({
resourceName: (plural) => `event${plural ? "s" : ""}`,
});
+ const [customerDetailsSheet, setCustomerDetailsSheet] = useState<
+ | { open: false; customer: Customer | null }
+ | { open: true; customer: Customer }
+ >({ open: false, customer: null });
+
+ useEffect(() => {
+ const customerId = searchParams.get("customerId");
+ if (!data || data.every((d) => !("customer" in d))) return;
+ if (customerId) {
+ const customerEvent = data.find(
+ (d) => "customer" in d && d.customer?.id === customerId,
+ );
+ if (customerEvent && "customer" in customerEvent) {
+ setCustomerDetailsSheet({
+ open: true,
+ customer: customerEvent.customer,
+ });
+ }
+ }
+ }, [searchParams, data]);
+
return (
- <Table
- {...tableProps}
- table={table}
- scrollWrapperClassName={requiresUpgrade ? "overflow-x-hidden" : undefined}
- >
- {requiresUpgrade && (
- <>
- <div className="absolute inset-0 flex touch-pan-y items-center justify-center bg-gradient-to-t from-[#fff_70%] to-[#fff6]">
- {upgradeOverlay}
- </div>
- <div className="h-[400px]" />
- </>
+ <>
+ {customerDetailsSheet.customer && (
+ <CustomerDetailsSheet
+ isOpen={customerDetailsSheet.open}
+ setIsOpen={(open) =>
+ setCustomerDetailsSheet((s) => ({ ...s, open }) as any)
+ }
+ customer={customerDetailsSheet.customer}
+ />
)}
- </Table>
+ <Table
+ {...tableProps}
+ table={table}
+ scrollWrapperClassName={
+ requiresUpgrade ? "overflow-x-hidden" : undefined
+ }
+ >
+ {requiresUpgrade && (
+ <>
+ <div className="absolute inset-0 flex touch-pan-y items-center justify-center bg-gradient-to-t from-[#fff_70%] to-[#fff6]">
+ {upgradeOverlay}
+ </div>
+ <div className="h-[400px]" />
+ </>
+ )}
+ </Table>
+ </>
);
}
diff --git a/apps/web/ui/partners/customer-details-sheet.tsx b/apps/web/ui/partners/customer-details-sheet.tsx
index 1bfc0dfd0b..d4fbf8bb92 100644
--- a/apps/web/ui/partners/customer-details-sheet.tsx
+++ b/apps/web/ui/partners/customer-details-sheet.tsx
@@ -30,7 +30,7 @@ import {
} from "@dub/utils";
import { formatDistanceStrict } from "date-fns";
import Link from "next/link";
-import { Dispatch, SetStateAction, useState } from "react";
+import { Dispatch, SetStateAction } from "react";
import useSWR from "swr";
interface CustomerDetailsSheetProps {
@@ -38,10 +38,7 @@ interface CustomerDetailsSheetProps {
setIsOpen: Dispatch<SetStateAction<boolean>>;
}
-function CustomerDetailsSheetContent({
- customer,
- setIsOpen,
-}: CustomerDetailsSheetProps) {
+function CustomerDetailsSheetContent({ customer }: CustomerDetailsSheetProps) {
const { id: workspaceId, slug } = useWorkspace();
let { data: customerActivity, isLoading } = useSWR<CustomerActivityResponse>(
@@ -312,7 +309,7 @@ function ActivitySkeleton() {
);
}
-function CustomerDetailsSheet({
+export function CustomerDetailsSheet({
isOpen,
...rest
}: CustomerDetailsSheetProps & {
@@ -330,19 +327,3 @@ function CustomerDetailsSheet({
</Sheet>
);
}
-export function useCustomerDetailsSheet({
- customer,
-}: Omit<CustomerDetailsSheetProps, "setIsOpen">) {
- const [isOpen, setIsOpen] = useState(false);
-
- return {
- customerDetailsSheet: (
- <CustomerDetailsSheet
- customer={customer}
- setIsOpen={setIsOpen}
- isOpen={isOpen}
- />
- ),
- setIsOpen,
- };
-}