Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions e2e/analytics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect, Page } from "@playwright/test";
import { test, expect, Page, BrowserContext } from "@playwright/test";

/**
* Analytics Dashboard E2E Tests - Serial Execution
Expand All @@ -18,8 +18,9 @@ const ANALYTICS_USER = {
password: "Test123!@#",
};

// Shared page context between tests
// Shared page and context between tests
let authenticatedPage: Page;
let browserContext: BrowserContext;

/**
* Helper to login with credentials
Expand Down Expand Up @@ -57,8 +58,8 @@ async function loginWithCredentials(page: Page): Promise<void> {
test.describe("Analytics Tests", () => {
test.beforeAll(async ({ browser }) => {
// Create a new context and page
const context = await browser.newContext();
authenticatedPage = await context.newPage();
browserContext = await browser.newContext();
authenticatedPage = await browserContext.newPage();

// Login once
await loginWithCredentials(authenticatedPage);
Expand All @@ -69,8 +70,8 @@ test.describe("Analytics Tests", () => {
});

test.afterAll(async () => {
if (authenticatedPage) {
await authenticatedPage.close();
if (browserContext) {
await browserContext.close();
}
});

Expand Down
37 changes: 1 addition & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/components/analytics/analytics-dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,18 @@ export function AnalyticsDashboard({ storeId: propStoreId }: AnalyticsDashboardP
to,
});

console.log(`[Analytics] Fetching dashboard for ${timeRange}: ${from} to ${to}`);

const response = await fetch(`/api/analytics/dashboard?${params}`, {
signal: abortController.signal,
cache: 'no-store',
});
if (!response.ok) throw new Error('Failed to fetch analytics');

const data = await response.json();
console.log(`[Analytics] Received dashboard data:`, data);
setMetrics(data);
setActiveTimeRange(timeRange);
} catch (error) {
if ((error as Error).name !== 'AbortError') {
toast.error('Failed to load analytics data');
console.error('Analytics error:', error);
}
} finally {
setLoading(false);
Expand Down
6 changes: 4 additions & 2 deletions src/components/ui/enhanced-data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ export function EnhancedDataTable<TData>({
return [selectColumn, ...columns];
}, [columns, enableRowSelection]);

// React Compiler note: disable the incompatible-library check for useReactTable

// The react compiler warns about memoizing functions returned from TanStack's useReactTable API.
// This is intentional: disable the incompatible-library check for this call so the compiler
// doesn't try to memoize the returned functions and trigger stale UI errors.
// eslint-disable-next-line react-hooks/incompatible-library
const table = useReactTable({
data,
columns: tableColumns,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/services/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ export class AnalyticsService {
// Retention: customers from previous period who also ordered in current period
let retainedCustomers = 0;
if (previousPeriodCustomerIds.length > 0) {
const retained = customerIdsInPeriod.filter(id => previousPeriodCustomerIds.includes(id));
const previousPeriodSet = new Set(previousPeriodCustomerIds);
const retained = customerIdsInPeriod.filter(id => previousPeriodSet.has(id));
retainedCustomers = retained.length;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/checkout.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class CheckoutService {
];

// Add free shipping for domestic orders over ৳5,000
if (isDomestic && cartSubtotal >= 50) {
if (isDomestic && cartSubtotal >= 5000) {
options.push({
id: 'free',
name: 'Free Shipping',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const CreateStoreSchema = z.object({
country: z.string().default('BD'),
currency: z.string().default('BDT'),
timezone: z.string().default('Asia/Dhaka'),
locale: z.string().default('en'),
locale: z.string().default('bn'),
subscriptionPlan: z.nativeEnum(SubscriptionPlan).default(SubscriptionPlan.FREE),
organizationId: z.string().optional(), // Optional - will be derived from session if not provided
});
Expand Down