Skip to content

Commit c96bc05

Browse files
committed
Chart update
1 parent 9a8dcff commit c96bc05

4 files changed

Lines changed: 42 additions & 5 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### ✨ Features
22

3-
- Chart updated
3+
- Min value added for subscriber growth chart.
44
- New features and improvements.
55

66
### 🐛 Bug Fixes

apps/backend/prisma/seed.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { hashPassword } from "../src/utils/auth"
22
import { prisma } from "../src/utils/prisma"
33
import { SmtpEncryption } from "./client"
4+
import dayjs from "dayjs"
45

56
async function seed() {
67
if (!(await prisma.organization.findFirst())) {
@@ -55,6 +56,37 @@ async function seed() {
5556
},
5657
})
5758
}
59+
60+
// Create 5000 subscribers
61+
const subscribers = Array.from({ length: 5000 }, (_, i) => ({
62+
name: `Subscriber ${i + 1}`,
63+
email: `subscriber${i + 1}@example.com`,
64+
organizationId: orgId,
65+
createdAt: dayjs().subtract(12, "days").toDate(),
66+
}))
67+
await prisma.subscriber.createMany({
68+
data: subscribers,
69+
skipDuplicates: true,
70+
})
71+
// Then 10 more for each day for 10 days
72+
const now = new Date()
73+
for (let d = 0; d < 10; d++) {
74+
const day = dayjs(now)
75+
.subtract(d + 1, "day")
76+
.toDate()
77+
78+
const dailySubs = Array.from({ length: 10 }, (_, i) => ({
79+
name: `DailySub ${d + 1}-${i + 1}`,
80+
email: `dailysub${d + 1}-${i + 1}@example.com`,
81+
organizationId: orgId,
82+
createdAt: day,
83+
updatedAt: day,
84+
}))
85+
await prisma.subscriber.createMany({
86+
data: dailySubs,
87+
skipDuplicates: true,
88+
})
89+
}
5890
}
5991

6092
seed()

apps/web/src/pages/dashboard/dashboard/subscriber-growth-chart.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "@repo/ui"
1616
import dayjs from "dayjs"
1717
import { ArrowDown, TrendingUp } from "lucide-react"
18+
import { useMemo } from "react"
1819
import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts"
1920

2021
const chartConfig = {
@@ -49,9 +50,12 @@ export const SubscriberGrowthChart = () => {
4950

5051
const isLoading = analyticsLoading || dashboardLoading
5152

52-
const maxCount = Math.max(
53-
...(dashboard?.subscriberGrowth.map((item) => item.count) || [])
53+
const countMapped = useMemo(
54+
() => dashboard?.subscriberGrowth.map((item) => item.count) || [],
55+
[dashboard?.subscriberGrowth]
5456
)
57+
const maxCount = useMemo(() => Math.max(...countMapped), [countMapped])
58+
const minCount = useMemo(() => Math.min(...countMapped), [countMapped])
5559

5660
return (
5761
<Card hoverEffect className="col-span-4">
@@ -88,7 +92,8 @@ export const SubscriberGrowthChart = () => {
8892
tickLine={false}
8993
axisLine={false}
9094
tickMargin={8}
91-
tickCount={Math.min(maxCount, 10)}
95+
domain={[minCount, maxCount]}
96+
allowDataOverflow={true}
9297
/>
9398
<ChartTooltip
9499
cursor={false}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.4.11",
2+
"version": "0.4.12",
33
"name": "letterspace",
44
"private": true,
55
"scripts": {

0 commit comments

Comments
 (0)