Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 16 additions & 39 deletions apps/web/app/api/customers/[id]/activity/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { getCustomerEvents } from "@/lib/analytics/get-customer-events";
import { getCustomerOrThrow } from "@/lib/api/customers/get-customer-or-throw";
import { decodeLinkIfCaseSensitive } from "@/lib/api/links/case-sensitivity";
import { withWorkspace } from "@/lib/auth";
import { verifyFolderAccess } from "@/lib/folder/permissions";
import { customerActivityResponseSchema } from "@/lib/zod/schemas/customer-activity";
import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";
Expand All @@ -16,46 +15,24 @@ export const GET = withWorkspace(async ({ workspace, params, session }) => {
id: customerId,
});

if (!customer.linkId) {
return NextResponse.json(
customerActivityResponseSchema.parse({
customer,
events: [],
ltv: 0,
timeToLead: null,
timeToSale: null,
link: null,
}),
);
}
const events = await getCustomerEvents({
customerId: customer.id,
});

let [events, link] = await Promise.all([
getCustomerEvents({
customerId: customer.id,
}),
// get the first partner link that this customer interacted with
const firstLinkId = events[events.length - 1].link_id;

prisma.link.findUniqueOrThrow({
where: {
id: customer.linkId!,
},
select: {
id: true,
domain: true,
key: true,
shortLink: true,
folderId: true,
},
}),
]);

if (link.folderId) {
await verifyFolderAccess({
workspace,
userId: session.user.id,
folderId: link.folderId,
requiredPermission: "folders.read",
});
}
let link = await prisma.link.findUniqueOrThrow({
where: {
id: firstLinkId,
},
select: {
id: true,
domain: true,
key: true,
shortLink: true,
},
});

link = decodeLinkIfCaseSensitive(link);

Expand Down
2 changes: 1 addition & 1 deletion apps/web/lib/swr/use-partner-earnings-timeseries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function usePartnerEarningsTimeseries(
}),
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
},
{ include: ["type", "linkId", "customerId", "status"] },
{ include: ["type", "linkId", "customerId", "status", "payoutId"] },
)}`,
fetcher,
{
Expand Down
8 changes: 7 additions & 1 deletion apps/web/ui/analytics/events/events-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,13 @@ export default function EventsTable({
minSize: 120,
cell: ({ getValue }) => (
<div className="flex items-center gap-2">
<span>{currencyFormatter(getValue() / 100)}</span>
<span>
{currencyFormatter(getValue() / 100, {
maximumFractionDigits: undefined,
// @ts-ignore – trailingZeroDisplay is a valid option but TS is outdated
trailingZeroDisplay: "stripIfInteger",
})}
</span>
<span className="text-neutral-400">USD</span>
</div>
),
Expand Down
25 changes: 11 additions & 14 deletions apps/web/ui/customers/customer-partner-earnings-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function CustomerPartnerEarningsTable({
getCoreRowModel: getCoreRowModel(),
});

const As = viewAllHref ? Link : "div";
return (
<div className="overflow-x-auto">
{isLoading ? (
Expand Down Expand Up @@ -117,22 +118,18 @@ export function CustomerPartnerEarningsTable({
))}
</tbody>
</table>
{viewAllHref && (
<div className="mt-2 flex items-center gap-1 px-2 text-sm text-neutral-600">
{commissions.length} of
{totalCommissions ? (
<Link
href={viewAllHref}
className="font-medium text-neutral-700 hover:text-neutral-900"
>
{totalCommissions}
</Link>
) : (
<div className="mt-2 flex items-center gap-1 px-2 text-sm text-neutral-600">
{commissions.length} of
<As
href={viewAllHref ?? "#"}
className="flex items-center gap-1.5 font-medium text-neutral-700 hover:text-neutral-900"
>
{totalCommissions ?? (
<div className="size-3 animate-pulse rounded-md bg-neutral-100" />
)}
)}{" "}
results
</div>
)}
</As>
</div>
</>
)}
</div>
Expand Down
25 changes: 11 additions & 14 deletions apps/web/ui/customers/customer-sales-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export function CustomerSalesTable({
getCoreRowModel: getCoreRowModel(),
});

const As = viewAllHref ? Link : "div";
return (
<div className="overflow-x-auto">
{isLoading ? (
Expand Down Expand Up @@ -136,22 +137,18 @@ export function CustomerSalesTable({
))}
</tbody>
</table>
{viewAllHref && (
<div className="mt-2 flex items-center gap-1 px-2 text-sm text-neutral-600">
{sales.length} of
{totalSales ? (
<Link
href={viewAllHref}
className="font-medium text-neutral-700 hover:text-neutral-900"
>
{totalSales}
</Link>
) : (
<div className="mt-2 flex items-center gap-1 px-2 text-sm text-neutral-600">
{sales.length} of
<As
href={viewAllHref ?? "#"}
className="flex items-center gap-1.5 font-medium text-neutral-700 hover:text-neutral-900"
>
{totalSales ?? (
<div className="size-3 animate-pulse rounded-md bg-neutral-100" />
)}
)}{" "}
results
</div>
)}
</As>
</div>
</>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dub/ui",
"description": "UI components for Dub.co",
"version": "0.2.32",
"version": "0.2.34",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const FEATURES_LIST = [
title: "Dub Integrations",
description: "Connect Dub with your favorite tools",
icon: ConnectedDotsFill,
href: "/docs/integrations",
href: "/integrations",
},
];

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/nav/content/product-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const largeLinks = [
title: "Dub Integrations",
description: "Connect Dub with your favorite tools",
icon: ConnectedDotsFill,
href: "/docs/integrations",
href: "/integrations",
},
];

Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/nav/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export const navItems = [
name: "Product",
content: ProductContent,
childItems: FEATURES_LIST,
segments: ["/home", "/analytics", "/features", "/compare"],
segments: ["/home", "/analytics", "/features", "/compare", "/integrations"],
},
{
name: "Solutions",
content: SolutionsContent,
childItems: SOLUTIONS,
segments: ["/solutions"],
segments: ["/solutions", "/sdks"],
},
{
name: "Resources",
Expand Down