Skip to content

Commit 2646a8c

Browse files
committed
address vercel comments #1
1 parent 056db62 commit 2646a8c

File tree

7 files changed

+99
-29
lines changed

7 files changed

+99
-29
lines changed

apps/dashboard/src/components/pay/PayAnalytics/PayAnalytics.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export function PayAnalytics(props: { apiKey: ApiKey }) {
5555
getLastNDaysRange("last-120"),
5656
);
5757

58+
const numberOfDays = Math.round(
59+
(range.to.getTime() - range.from.getTime()) / (1000 * 60 * 60 * 24),
60+
);
61+
5862
return (
5963
<div>
6064
<div className="flex mb-2">
@@ -69,12 +73,22 @@ export function PayAnalytics(props: { apiKey: ApiKey }) {
6973
to={range.to}
7074
/>
7175
</div>
72-
<TotalPayVolume clientId={clientId} from={range.from} to={range.to} />
76+
<TotalPayVolume
77+
clientId={clientId}
78+
from={range.from}
79+
to={range.to}
80+
numberOfDays={numberOfDays}
81+
/>
7382
</GridWithSeparator>
7483

7584
<div className="grid gap-4 grid-cols-1 xl:grid-cols-2 ">
7685
<div className="border border-border rounded-xl p-4 xl:p-6">
77-
<Payouts clientId={clientId} from={range.from} to={range.to} />
86+
<Payouts
87+
clientId={clientId}
88+
from={range.from}
89+
to={range.to}
90+
numberOfDays={numberOfDays}
91+
/>
7892
</div>
7993
<div className="border border-border rounded-xl p-4 xl:p-6 flex ">
8094
<PaymentsSuccessRate
@@ -91,6 +105,7 @@ export function PayAnalytics(props: { apiKey: ApiKey }) {
91105
clientId={clientId}
92106
from={range.from}
93107
to={range.to}
108+
numberOfDays={numberOfDays}
94109
/>
95110
</div>
96111
<PayCustomersTable

apps/dashboard/src/components/pay/PayAnalytics/components/PayCustomersTable.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import {
88
usePayCustomers,
99
} from "../hooks/usePayCustomers";
1010
import { ExportToCSVButton } from "./ExportToCSVButton";
11-
import { NoDataAvailable, TableData, TableHeading } from "./common";
11+
import {
12+
NoDataAvailable,
13+
TableData,
14+
TableHeading,
15+
TableHeadingRow,
16+
} from "./common";
1217

1318
import {
1419
Select,
@@ -78,7 +83,7 @@ export function PayCustomersTable(props: {
7883
const customersData = uiData.data?.customers;
7984

8085
return (
81-
<div>
86+
<div className="flex flex-col">
8287
{/* header */}
8388
<div className="flex flex-col lg:flex-row lg:justify-between gap-2 lg:items-center">
8489
<Select
@@ -109,15 +114,16 @@ export function PayCustomersTable(props: {
109114
)}
110115
</div>
111116

112-
<div className="h-5" />
113-
114117
{!uiData.isError ? (
115-
<RenderData
116-
data={uiData.data}
117-
loadMore={() => {
118-
topCustomersQuery.fetchNextPage();
119-
}}
120-
/>
118+
<>
119+
<div className="h-5" />
120+
<RenderData
121+
data={uiData.data}
122+
loadMore={() => {
123+
topCustomersQuery.fetchNextPage();
124+
}}
125+
/>
126+
</>
121127
) : (
122128
<NoDataAvailable />
123129
)}
@@ -130,10 +136,10 @@ function RenderData(props: { data?: UIData; loadMore: () => void }) {
130136
<ScrollShadow scrollableClassName="h-[250px]" disableTopShadow={true}>
131137
<table className="w-full">
132138
<thead>
133-
<tr className="border-b border-border sticky top-0 bg-background z-10">
139+
<TableHeadingRow>
134140
<TableHeading> Wallet Address </TableHeading>
135141
<TableHeading> Total spend </TableHeading>
136-
</tr>
142+
</TableHeadingRow>
137143
</thead>
138144
<tbody>
139145
{props.data ? (

apps/dashboard/src/components/pay/PayAnalytics/components/PayNewCustomers.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { format } from "date-fns";
2-
import { useId, useState } from "react";
2+
import { useEffect, useId, useState } from "react";
33
import { Area, AreaChart, ResponsiveContainer, Tooltip, XAxis } from "recharts";
44
import { SkeletonContainer } from "../../../../@/components/ui/skeleton";
55
import { AreaChartLoadingState } from "../../../analytics/area-chart";
@@ -27,8 +27,18 @@ export function PayNewCustomers(props: {
2727
clientId: string;
2828
from: Date;
2929
to: Date;
30+
numberOfDays: number;
3031
}) {
31-
const [intervalType, setIntervalType] = useState<"day" | "week">("day");
32+
const [intervalType, setIntervalType] = useState<"day" | "week">(
33+
props.numberOfDays > 30 ? "week" : "day",
34+
);
35+
36+
// if prop changes, update intervalType
37+
// eslint-disable-next-line no-restricted-syntax
38+
useEffect(() => {
39+
setIntervalType(props.numberOfDays > 30 ? "week" : "day");
40+
}, [props.numberOfDays]);
41+
3242
const newCustomersQuery = usePayNewCustomers({
3343
clientId: props.clientId,
3444
from: props.from,
@@ -82,12 +92,12 @@ export function PayNewCustomers(props: {
8292
<div className="flex justify-between gap-2 items-center mb-1">
8393
<CardHeading>New Customers </CardHeading>
8494

85-
{uiData.data && (
95+
<div className={!uiData.data ? "invisible" : ""}>
8696
<IntervalSelector
8797
intervalType={intervalType}
8898
setIntervalType={setIntervalType}
8999
/>
90-
)}
100+
</div>
91101
</div>
92102

93103
{/* Chart */}

apps/dashboard/src/components/pay/PayAnalytics/components/PaymentHistory.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
NoDataAvailable,
1717
TableData,
1818
TableHeading,
19+
TableHeadingRow,
1920
} from "./common";
2021

2122
type UIData = {
@@ -102,19 +103,19 @@ function RenderData(props: {
102103
}) {
103104
return (
104105
<ScrollShadow
105-
scrollableClassName="max-h-[350px] lg:max-h-[700px]"
106+
scrollableClassName="max-h-[350px] lg:max-h-[700px] rounded-lg"
106107
disableTopShadow={true}
107108
>
108109
<table className="w-full selection:bg-muted">
109110
<thead>
110-
<tr className="border-b border-border sticky top-0 bg-background z-10">
111+
<TableHeadingRow>
111112
<TableHeading> Bought </TableHeading>
112113
<TableHeading> Paid </TableHeading>
113114
<TableHeading>Type</TableHeading>
114115
<TableHeading>Status</TableHeading>
115116
<TableHeading>Recipient</TableHeading>
116117
<TableHeading>Date</TableHeading>
117-
</tr>
118+
</TableHeadingRow>
118119
</thead>
119120
<tbody>
120121
{props.data ? (

apps/dashboard/src/components/pay/PayAnalytics/components/Payouts.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useQuery } from "@tanstack/react-query";
22
import { format } from "date-fns";
3-
import { useState } from "react";
3+
import { useEffect, useState } from "react";
44
import { Bar, BarChart, ResponsiveContainer, Tooltip, XAxis } from "recharts";
55
import { SkeletonContainer } from "../../../../@/components/ui/skeleton";
66
import { AreaChartLoadingState } from "../../../analytics/area-chart";
@@ -24,8 +24,22 @@ type UIQueryData = {
2424
percentChange: number;
2525
};
2626

27-
export function Payouts(props: { clientId: string; from: Date; to: Date }) {
28-
const [intervalType, setIntervalType] = useState<"day" | "week">("day");
27+
export function Payouts(props: {
28+
clientId: string;
29+
from: Date;
30+
to: Date;
31+
numberOfDays: number;
32+
}) {
33+
const [intervalType, setIntervalType] = useState<"day" | "week">(
34+
props.numberOfDays > 30 ? "week" : "day",
35+
);
36+
37+
// if prop changes, update intervalType
38+
// eslint-disable-next-line no-restricted-syntax
39+
useEffect(() => {
40+
setIntervalType(props.numberOfDays > 30 ? "week" : "day");
41+
}, [props.numberOfDays]);
42+
2943
const payoutsQuery = usePayVolume({
3044
clientId: props.clientId,
3145
from: props.from,

apps/dashboard/src/components/pay/PayAnalytics/components/TotalPayVolume.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
SelectValue,
77
} from "@/components/ui/select";
88
import { format } from "date-fns";
9-
import { useId, useState } from "react";
9+
import { useEffect, useId, useState } from "react";
1010
import { Area, AreaChart, ResponsiveContainer, Tooltip, XAxis } from "recharts";
1111
import { AreaChartLoadingState } from "../../../analytics/area-chart";
1212
import { type PayVolumeData, usePayVolume } from "../hooks/usePayVolume";
@@ -26,8 +26,23 @@ export function TotalPayVolume(props: {
2626
clientId: string;
2727
from: Date;
2828
to: Date;
29+
numberOfDays: number;
2930
}) {
30-
const [intervalType, setIntervalType] = useState<"day" | "week">("day");
31+
const [intervalType, setIntervalType] = useState<"day" | "week">(
32+
props.numberOfDays > 30 ? "week" : "day",
33+
);
34+
35+
// if prop changes, update intervalType
36+
// eslint-disable-next-line no-restricted-syntax
37+
useEffect(() => {
38+
setIntervalType(props.numberOfDays > 30 ? "week" : "day");
39+
}, [props.numberOfDays]);
40+
41+
// if prop changes, update intervalType
42+
// eslint-disable-next-line no-restricted-syntax
43+
useEffect(() => {
44+
setIntervalType(props.numberOfDays > 30 ? "week" : "day");
45+
}, [props.numberOfDays]);
3146

3247
const volumeQuery = usePayVolume({
3348
clientId: props.clientId,

apps/dashboard/src/components/pay/PayAnalytics/components/common.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212

1313
export function NoDataAvailable() {
1414
return (
15-
<div className="h-[250px] flex items-center justify-center">
15+
<div className="min-h-[250px] flex items-center justify-center flex-1">
1616
<div className="flex items-center gap-2">
1717
<OctagonXIcon className="size-5 text-destructive-foreground" />
1818
<p className="text-muted-foreground">No data available</p>
@@ -53,12 +53,21 @@ export function ChangeBadge(props: { percent: number }) {
5353
}
5454

5555
export function TableData({ children }: { children: React.ReactNode }) {
56-
return <td className="px-0 py-2 text-sm">{children}</td>;
56+
return <td className="px-3 py-2 text-sm">{children}</td>;
57+
}
58+
59+
export function TableHeadingRow({ children }: { children: React.ReactNode }) {
60+
return (
61+
<tr className="sticky top-0 bg-background z-10">
62+
{children}
63+
<div className="border-b border-border absolute inset-0 z-10" />
64+
</tr>
65+
);
5766
}
5867

5968
export function TableHeading(props: { children: React.ReactNode }) {
6069
return (
61-
<th className="text-left px-0 py-3 text-sm font-medium text-muted-foreground min-w-[150px]">
70+
<th className="bg-secondary border-b border-border text-left px-3 py-3 text-sm font-medium text-muted-foreground min-w-[150px]">
6271
{props.children}
6372
</th>
6473
);

0 commit comments

Comments
 (0)