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.

fix activity list

Steven Tey6d8e89ec0ccb
diff --git a/apps/web/app/api/customers/[id]/activity/route.ts b/apps/web/app/api/customers/[id]/activity/route.ts
index bc7f46301f..5398b9bc44 100644
--- a/apps/web/app/api/customers/[id]/activity/route.ts
+++ b/apps/web/app/api/customers/[id]/activity/route.ts
@@ -20,21 +20,31 @@ export const GET = withWorkspace(async ({ workspace, params }) => {
});
// get the first partner link that this customer interacted with
- const firstLinkId = events[events.length - 1].link_id;
+ const firstLinkId =
+ events.length > 0 ? events[events.length - 1].link_id : customer.linkId;
- let link = await prisma.link.findUniqueOrThrow({
- where: {
- id: firstLinkId,
- },
- select: {
- id: true,
- domain: true,
- key: true,
- shortLink: true,
- },
- });
+ let link: {
+ id: string;
+ domain: string;
+ key: string;
+ shortLink: string;
+ } | null = null;
+
+ if (firstLinkId) {
+ link = await prisma.link.findUniqueOrThrow({
+ where: {
+ id: firstLinkId,
+ },
+ select: {
+ id: true,
+ domain: true,
+ key: true,
+ shortLink: true,
+ },
+ });
- link = decodeLinkIfCaseSensitive(link);
+ link = decodeLinkIfCaseSensitive(link);
+ }
// Find the LTV of the customer
// TODO: Calculate this from all events, not limited
diff --git a/apps/web/scripts/tinybird/delete-lead-event.ts b/apps/web/scripts/tinybird/delete-lead-event.ts
new file mode 100644
index 0000000000..e74c57e9c4
--- /dev/null
+++ b/apps/web/scripts/tinybird/delete-lead-event.ts
@@ -0,0 +1,41 @@
+import "dotenv-flow/config";
+
+// update tinybird sale event
+async function main() {
+ const deleteCondition = "customer_id = 'cus_1JR0TMY8CHWH303VGQEX6H6KQ'";
+
+ // delete data from tinybird
+ const deleteRes = await Promise.allSettled([
+ deleteData({
+ dataSource: "dub_lead_events",
+ deleteCondition,
+ }),
+ deleteData({
+ dataSource: "dub_lead_events_mv",
+ deleteCondition,
+ }),
+ ]);
+ console.log(deleteRes);
+}
+
+const deleteData = async ({
+ dataSource,
+ deleteCondition,
+}: {
+ dataSource: string;
+ deleteCondition: string;
+}) => {
+ return fetch(
+ `https://api.us-east.tinybird.co/v0/datasources/${dataSource}/delete`,
+ {
+ method: "POST",
+ headers: {
+ Authorization: `Bearer ${process.env.TINYBIRD_API_KEY}`,
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ body: `delete_condition=${deleteCondition}`,
+ },
+ ).then((res) => res.json());
+};
+
+main();
diff --git a/apps/web/scripts/tinybird/delete-sale-event.ts b/apps/web/scripts/tinybird/delete-sale-event.ts
index b5ba4213f4..f2b8dbf685 100644
--- a/apps/web/scripts/tinybird/delete-sale-event.ts
+++ b/apps/web/scripts/tinybird/delete-sale-event.ts
@@ -2,21 +2,21 @@ import "dotenv-flow/config";
// update tinybird sale event
async function main() {
- const eventId = "xxx";
+ const deleteCondition = "customer_id = 'cus_1JR0TMY8CHWH303VGQEX6H6KQ'";
// delete data from tinybird
const deleteRes = await Promise.allSettled([
deleteData({
dataSource: "dub_sale_events",
- eventId,
+ deleteCondition,
}),
deleteData({
dataSource: "dub_sale_events_mv",
- eventId,
+ deleteCondition,
}),
deleteData({
dataSource: "dub_sale_events_id",
- eventId,
+ deleteCondition,
}),
]);
console.log(deleteRes);
@@ -24,10 +24,10 @@ async function main() {
const deleteData = async ({
dataSource,
- eventId,
+ deleteCondition,
}: {
dataSource: string;
- eventId: string;
+ deleteCondition: string;
}) => {
return fetch(
`https://api.us-east.tinybird.co/v0/datasources/${dataSource}/delete`,
@@ -37,7 +37,7 @@ const deleteData = async ({
Authorization: `Bearer ${process.env.TINYBIRD_API_KEY}`,
"Content-Type": "application/x-www-form-urlencoded",
},
- body: `delete_condition=event_id='${eventId}'`,
+ body: `delete_condition=${deleteCondition}`,
},
).then((res) => res.json());
};
diff --git a/apps/web/ui/customers/customer-activity-list.tsx b/apps/web/ui/customers/customer-activity-list.tsx
index b0de54c806..a6037f6dcd 100644
--- a/apps/web/ui/customers/customer-activity-list.tsx
+++ b/apps/web/ui/customers/customer-activity-list.tsx
@@ -133,8 +133,8 @@ export function CustomerActivityList({
return isLoading ? (
<div className="flex h-32 w-full animate-pulse rounded-lg border border-transparent bg-neutral-100" />
) : !activity?.events?.length ? (
- <div className="text-sm text-neutral-500">
- {activity?.events ? "No activity" : "Failed to load activity"}
+ <div className="flex h-32 w-full items-center justify-center border border-neutral-200 text-xs text-neutral-500">
+ {activity?.events ? "No activity yet" : "Failed to load activity"}
</div>
) : (
<ul className="flex flex-col gap-5 text-sm">