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.

Program overview UI updates

Tim Wilson5b190f07391b
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/page-client.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/page-client.tsx
index 2049647cd9..45256680b3 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/page-client.tsx
@@ -4,6 +4,7 @@ import usePartnerAnalytics from "@/lib/swr/use-partner-analytics";
import usePartnerEvents from "@/lib/swr/use-partner-events";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
import Areas from "@/ui/charts/areas";
+import { ChartContext } from "@/ui/charts/chart-context";
import TimeSeriesChart from "@/ui/charts/time-series-chart";
import XAxis from "@/ui/charts/x-axis";
import YAxis from "@/ui/charts/y-axis";
@@ -26,43 +27,12 @@ import {
nFormatter,
} from "@dub/utils";
import { LinearGradient } from "@visx/gradient";
-import { subDays } from "date-fns";
import { useId, useMemo } from "react";
-const mockValues = (factor = 1) => {
- const timeseries = [...Array(30)].map((_, i) => ({
- date: subDays(new Date(), 30 - i),
- value: Math.floor(Math.random() * 100 * factor),
- }));
-
- return {
- total: timeseries.reduce((acc, curr) => acc + curr.value, 0),
- timeseries,
- isError: false,
- };
-};
-
-const mockSales = () =>
- [...Array(10)].map((_, i) => ({
- date: subDays(new Date(), 10 - i),
- earnings: Math.floor(Math.random() * 15),
- customer: `*****@${["dub.co", "gmail.com"][i % 2]}`,
- }));
-
export default function ProgramPageClient() {
const { programEnrollment } = useProgramEnrollment();
const [copied, copyToClipboard] = useCopyToClipboard();
- const { total: leads, timeseries: leadsTimeseries } = useMemo(
- () => mockValues(1),
- [],
- );
- const { total: sales, timeseries: salesTimeseries } = useMemo(
- () => mockValues(0.25),
- [],
- );
- const statsError = false;
-
return (
<MaxWidthWrapper className="pb-10">
<div className="flex flex-col items-start justify-between gap-4 rounded-lg border border-neutral-300 bg-neutral-50 p-4 sm:flex-row sm:items-center md:p-8">
@@ -102,7 +72,7 @@ export default function ProgramPageClient() {
</div>
</div>
<div className="mt-6 rounded-lg border border-neutral-300">
- <div className="p-4 md:p-8 md:pb-4">
+ <div className="p-4 md:p-6 md:pb-4">
<EarningsChart />
</div>
</div>
@@ -112,7 +82,10 @@ export default function ProgramPageClient() {
<StatCard title="Sales" event="sales" />
</div>
<div className="mt-6">
- <SalesTable />
+ <h2 className="text-base font-medium text-neutral-900">Recent Sales</h2>
+ <div className="mt-4">
+ <SalesTable />
+ </div>
</div>
</MaxWidthWrapper>
);
@@ -141,7 +114,7 @@ function EarningsChart() {
<span className="block text-sm text-neutral-500">Earnings</span>
<div className="mt-2">
{total !== undefined ? (
- <span className="text-3xl text-neutral-800">
+ <span className="text-2xl text-neutral-800">
{currencyFormatter(total / 100)}
</span>
) : (
@@ -180,20 +153,25 @@ function EarningsChart() {
);
}}
>
- <LinearGradient
- id={`${id}-color-gradient`}
- from="#7D3AEC"
- to="#DA2778"
- x1={0}
- x2={1}
- />
+ <ChartContext.Consumer>
+ {(context) => (
+ <LinearGradient
+ id={`${id}-color-gradient`}
+ from="#7D3AEC"
+ to="#DA2778"
+ x1={0}
+ x2={context?.width ?? 1}
+ gradientUnits="userSpaceOnUse"
+ />
+ )}
+ </ChartContext.Consumer>
<XAxis />
<YAxis showGridLines />
<Areas
seriesStyles={[
{
- id: "value",
+ id: "earnings",
areaFill: `url(#${id}-color-gradient)`,
lineStroke: `url(#${id}-color-gradient)`,
lineClassName: "text-[#DA2778]",
diff --git a/packages/blocks/src/mini-area-chart.tsx b/packages/blocks/src/mini-area-chart.tsx
index 9245d2978c..68328ae4c5 100644
--- a/packages/blocks/src/mini-area-chart.tsx
+++ b/packages/blocks/src/mini-area-chart.tsx
@@ -5,7 +5,7 @@ import { ParentSize } from "@visx/responsive";
import { scaleLinear, scaleUtc } from "@visx/scale";
import { Area, AreaClosed } from "@visx/shape";
import { motion } from "framer-motion";
-import { useMemo } from "react";
+import { useId, useMemo } from "react";
export type MiniAreaChartProps = {
data: { date: Date; value: number }[];
@@ -33,6 +33,8 @@ function MiniAreaChartInner({
data,
curve = true,
}: MiniAreaChartProps & { width: number; height: number }) {
+ const id = useId();
+
const zeroedData = useMemo(
() =>
data.map(({ date }) => ({
@@ -69,7 +71,7 @@ function MiniAreaChartInner({
<svg width={width} height={height} key={data.length}>
<defs>
<LinearGradient
- id="color-gradient"
+ id={`${id}-color-gradient`}
from="#7D3AEC"
to="#DA2778"
x1={0}
@@ -77,7 +79,7 @@ function MiniAreaChartInner({
gradientUnits="userSpaceOnUse"
/>
<LinearGradient
- id="mask-gradient"
+ id={`${id}-mask-gradient`}
from="white"
to="white"
fromOpacity={0.3}
@@ -87,8 +89,8 @@ function MiniAreaChartInner({
y1={0}
y2={1}
/>
- <mask id="mask" maskContentUnits="objectBoundingBox">
- <rect width="1" height="1" fill="url(#mask-gradient)" />
+ <mask id={`${id}-mask`} maskContentUnits="objectBoundingBox">
+ <rect width="1" height="1" fill={`url(#${id}-mask-gradient)`} />
</mask>
</defs>
<Group left={padding.left} top={padding.top}>
@@ -104,7 +106,7 @@ function MiniAreaChartInner({
initial={{ d: path(zeroedData) || "", opacity: 0 }}
animate={{ d: path(data) || "", opacity: 1 }}
strokeWidth={1.5}
- stroke="url(#color-gradient)"
+ stroke={`url(#${id}-color-gradient)`}
/>
);
}}
@@ -122,8 +124,8 @@ function MiniAreaChartInner({
<motion.path
initial={{ d: path(zeroedData) || "", opacity: 0 }}
animate={{ d: path(data) || "", opacity: 1 }}
- fill="url(#color-gradient)"
- mask="url(#mask)"
+ fill={`url(#${id}-color-gradient)`}
+ mask={`url(#${id}-mask)`}
/>
);
}}
diff --git a/packages/tinybird/pipes/v1_events.pipe b/packages/tinybird/pipes/v1_events.pipe
index 02bd4e0c6a..0fcf50c530 100644
--- a/packages/tinybird/pipes/v1_events.pipe
+++ b/packages/tinybird/pipes/v1_events.pipe
@@ -4,12 +4,14 @@ DESCRIPTION >
TOKEN "v2_events_endpoint_read_8799" READ
+TAGS Dub Endpoints
+
NODE workspace_links
SQL >
%
SELECT link_id, domain, key
- from dub_links_metadata_latest
+ from dub_links_metadata_lambda
WHERE
workspace_id
= {{
@@ -33,13 +35,13 @@ NODE click_events
SQL >
%
- SELECT *, 'click' as event
- FROM dub_click_events_mv dce
+ SELECT *, splitByString('?', referer_url)[1] as referer_url_processed, 'click' as event
+ FROM dub_click_events_mv
WHERE
timestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }}
AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }}
- {% if defined(linkId) %} AND dce.link_id = {{ String(linkId) }}
- {% elif defined(workspaceId) %} AND dce.link_id IN (SELECT link_id FROM workspace_links)
+ {% if defined(linkId) %} AND link_id = {{ String(linkId) }}
+ {% elif defined(workspaceId) %} AND link_id IN (SELECT link_id FROM workspace_links)
{% end %}
{% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
{% if defined(continent) %} AND continent = {{ continent }} {% end %}
@@ -49,7 +51,7 @@ SQL >
{% if defined(browser) %} AND browser = {{ browser }} {% end %}
{% if defined(os) %} AND os = {{ os }} {% end %}
{% if defined(referer) %} AND referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %} AND referer_url = {{ refererUrl }} {% end %}
+ {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %}
{% if defined(url) %} AND url = {{ url }} {% end %}
ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
LIMIT {{ Int32(limit, 100) }}
@@ -63,6 +65,7 @@ SQL >
%
SELECT
*,
+ splitByString('?', referer_url)[1] as referer_url_processed,
'lead' as event
FROM dub_lead_events_mv
WHERE
@@ -79,7 +82,7 @@ SQL >
{% if defined(browser) %} AND browser = {{ browser }} {% end %}
{% if defined(os) %} AND os = {{ os }} {% end %}
{% if defined(referer) %} AND referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %} AND referer_url = {{ refererUrl }} {% end %}
+ {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %}
{% if defined(url) %} AND url = {{ url }} {% end %}
ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
LIMIT {{ Int32(limit, 100) }}
@@ -94,6 +97,7 @@ SQL >
SELECT
*,
amount as saleAmount,
+ splitByString('?', referer_url)[1] as referer_url_processed,
'sale' as event
FROM dub_sale_events_mv
WHERE
@@ -110,7 +114,7 @@ SQL >
{% if defined(browser) %} AND browser = {{ browser }} {% end %}
{% if defined(os) %} AND os = {{ os }} {% end %}
{% if defined(referer) %} AND referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %} AND referer_url = {{ refererUrl }} {% end %}
+ {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %}
{% if defined(url) %} AND url = {{ url }} {% end %}
ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
LIMIT {{ Int32(limit, 100) }}