Skip to content

Commit bf161cd

Browse files
committed
up
1 parent 9599754 commit bf161cd

4 files changed

Lines changed: 73 additions & 64 deletions

File tree

src/app/(dashboard)/products/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Metadata } from 'next';
55
import Link from 'next/link';
66
import { Flex, Heading, Text, Container, Section } from '@radix-ui/themes';
77
import { PlusIcon, DownloadIcon, UploadIcon } from '@radix-ui/react-icons';
8-
import { ProductsTable } from '@/components/products/products-table';
8+
import ProductsTable from '@/components/products/products-table';
99
import { getCurrentUser } from '@/lib/get-current-user';
1010

1111
export const dynamic = 'force-dynamic';

src/components/products/products-table.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// PERFORMANCE OPTIMIZED: React.memo and useMemo for expensive renders
44
'use client';
55

6-
import { useState, useMemo, memo } from 'react';
6+
import { useState, useMemo, useCallback, memo } from 'react';
77
import Link from 'next/link';
88
import Image from 'next/image';
99
import { Button } from '@/components/ui/button';
@@ -46,16 +46,13 @@ interface ProductsTableProps {
4646
// OPTIMIZED: Memoized currency formatter (created once, reused)
4747
// Performance: Prevents creating new Intl.NumberFormat on every render
4848
// ============================================================================
49-
const currencyFormatter = new Intl.NumberFormat('en-US', {
50-
style: 'currency',
51-
currency: 'USD',
52-
});
49+
// Removed unused currencyFormatter (now memoized below)
5350

5451
// ============================================================================
5552
// MAIN COMPONENT
5653
// ============================================================================
5754

58-
function ProductsTableComponent({ products, pagination, searchParams }: ProductsTableProps) {
55+
function ProductsTable({ products, pagination, searchParams }: ProductsTableProps) {
5956
const [selectedProducts, setSelectedProducts] = useState<string[]>([]);
6057

6158
// OPTIMIZED: useCallback prevents function recreation on every render

src/services/analytics-service.ts

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export class AnalyticsService {
302302
const previousPeriodEnd = startDate;
303303

304304
// Execute all queries in parallel (3x faster than sequential)
305-
const [totalCustomers, newCustomers, returningCustomerIds] = await Promise.all([
305+
const [totalCustomers, newCustomers] = await Promise.all([
306306
// Total customers (ever)
307307
this.db.customer.count({
308308
where: {
@@ -322,57 +322,10 @@ export class AnalyticsService {
322322
deletedAt: null,
323323
},
324324
}),
325-
326-
// Returning customers (customers who made orders in this period)
327-
this.db.order.groupBy({
328-
by: ['customerId'],
329-
where: {
330-
storeId,
331-
createdAt: {
332-
gte: startDate,
333-
lte: endDate,
334-
},
335-
customerId: {
336-
not: null,
337-
},
338-
deletedAt: null,
339-
},
340-
having: {
341-
customerId: {
342-
_count: {
343-
gt: 0,
344-
},
345-
},
346-
deletedAt: null,
347-
},
348-
}),
349325
]);
350326

351-
// Check which of these customers had orders before the period
352-
const customerIdsWithPreviousOrders = returningCustomerIds.length > 0 ? await this.db.order.findMany({
353-
where: {
354-
storeId,
355-
customerId: {
356-
in: returningCustomerIds.map((item) => item.customerId!),
357-
},
358-
createdAt: {
359-
lt: startDate,
360-
},
361-
deletedAt: null,
362-
},
363-
select: {
364-
customerId: true,
365-
},
366-
distinct: ['customerId'],
367-
}) : [];
368-
369-
const returningCustomerCount = customerIdsWithPreviousOrders.length;
370-
371327
// Calculate retention rate (simplified - returning customers / total customers from previous period)
372-
const previousPeriodEnd = startDate;
373-
const previousPeriodStart = new Date(startDate);
374-
const periodLength = endDate.getTime() - startDate.getTime();
375-
previousPeriodStart.setTime(previousPeriodStart.getTime() - periodLength);
328+
// previousPeriodStart and previousPeriodEnd already computed above
376329

377330
const previousPeriodCustomers = await this.db.customer.count({
378331
where: {
@@ -381,8 +334,8 @@ export class AnalyticsService {
381334
gte: previousPeriodStart,
382335
lt: previousPeriodEnd,
383336
},
384-
}),
385-
]);
337+
},
338+
});
386339

387340
// Use optimized raw SQL to find returning customers
388341
// A returning customer is one who ordered in current period AND had orders before current period

typescript-errors.json

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,78 @@
11
{
22
"summary": {
3-
"totalErrors": 0,
4-
"exitCode": 0,
5-
"timestamp": "2025-11-03T16:46:51Z",
3+
"totalErrors": 6,
4+
"exitCode": 1,
5+
"timestamp": "2025-11-08T03:26:21Z",
66
"command": "npm run type-check",
77
"totalWarnings": 0,
8-
"totalLines": 4
8+
"totalLines": 10
99
},
1010
"rawOutput": [
1111
"",
1212
"\u003e stormcom@0.1.0 type-check",
1313
"\u003e tsc --noEmit --incremental",
14-
""
14+
"",
15+
"src/app/(dashboard)/products/page.tsx(8,10): error TS2614: Module \u0027\"@/components/products/products-table\"\u0027 has no exported member \u0027ProductsTable\u0027. Did you mean to use \u0027import ProductsTable from \"@/components/products/products-table\"\u0027 instead?",
16+
"src/components/products/products-table.tsx(49,7): error TS6133: \u0027currencyFormatter\u0027 is declared but its value is never read.",
17+
"src/components/products/products-table.tsx(58,10): error TS6133: \u0027ProductsTableComponent\u0027 is declared but its value is never read.",
18+
"src/components/products/products-table.tsx(62,31): error TS2304: Cannot find name \u0027useCallback\u0027.",
19+
"src/components/products/products-table.tsx(71,27): error TS2304: Cannot find name \u0027useCallback\u0027.",
20+
"src/components/products/products-table.tsx(295,21): error TS2304: Cannot find name \u0027ProductsTable\u0027."
1521
],
1622
"errors": [
17-
23+
{
24+
"message": "Module \u0027\"@/components/products/products-table\"\u0027 has no exported member \u0027ProductsTable\u0027. Did you mean to use \u0027import ProductsTable from \"@/components/products/products-table\"\u0027 instead?",
25+
"column": 10,
26+
"line": 8,
27+
"fullText": "src/app/(dashboard)/products/page.tsx(8,10): error TS2614: Module \u0027\"@/components/products/products-table\"\u0027 has no exported member \u0027ProductsTable\u0027. Did you mean to use \u0027import ProductsTable from \"@/components/products/products-table\"\u0027 instead?",
28+
"code": "TS2614",
29+
"severity": "error",
30+
"file": "src/app/(dashboard)/products/page.tsx"
31+
},
32+
{
33+
"message": "\u0027currencyFormatter\u0027 is declared but its value is never read.",
34+
"column": 7,
35+
"line": 49,
36+
"fullText": "src/components/products/products-table.tsx(49,7): error TS6133: \u0027currencyFormatter\u0027 is declared but its value is never read.",
37+
"code": "TS6133",
38+
"severity": "error",
39+
"file": "src/components/products/products-table.tsx"
40+
},
41+
{
42+
"message": "\u0027ProductsTableComponent\u0027 is declared but its value is never read.",
43+
"column": 10,
44+
"line": 58,
45+
"fullText": "src/components/products/products-table.tsx(58,10): error TS6133: \u0027ProductsTableComponent\u0027 is declared but its value is never read.",
46+
"code": "TS6133",
47+
"severity": "error",
48+
"file": "src/components/products/products-table.tsx"
49+
},
50+
{
51+
"message": "Cannot find name \u0027useCallback\u0027.",
52+
"column": 31,
53+
"line": 62,
54+
"fullText": "src/components/products/products-table.tsx(62,31): error TS2304: Cannot find name \u0027useCallback\u0027.",
55+
"code": "TS2304",
56+
"severity": "error",
57+
"file": "src/components/products/products-table.tsx"
58+
},
59+
{
60+
"message": "Cannot find name \u0027useCallback\u0027.",
61+
"column": 27,
62+
"line": 71,
63+
"fullText": "src/components/products/products-table.tsx(71,27): error TS2304: Cannot find name \u0027useCallback\u0027.",
64+
"code": "TS2304",
65+
"severity": "error",
66+
"file": "src/components/products/products-table.tsx"
67+
},
68+
{
69+
"message": "Cannot find name \u0027ProductsTable\u0027.",
70+
"column": 21,
71+
"line": 295,
72+
"fullText": "src/components/products/products-table.tsx(295,21): error TS2304: Cannot find name \u0027ProductsTable\u0027.",
73+
"code": "TS2304",
74+
"severity": "error",
75+
"file": "src/components/products/products-table.tsx"
76+
}
1877
]
1978
}

0 commit comments

Comments
 (0)