Add pagination to Customer Insights top customers list
Implemented pagination controls and page size selection for the top customers section in CustomerInsightsChart. Updated analytics-service to support paginated customer insights API calls and handle pagination metadata. Improves usability for stores with large customer bases.
This commit is contained in:
@@ -67,6 +67,16 @@ export interface CustomerInsights {
|
||||
username?: string;
|
||||
}>;
|
||||
averageOrdersPerCustomer: string;
|
||||
pagination?: {
|
||||
currentPage: number;
|
||||
totalPages: number;
|
||||
totalCustomers: number;
|
||||
limit: number;
|
||||
hasNextPage: boolean;
|
||||
hasPrevPage: boolean;
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface OrderAnalytics {
|
||||
@@ -112,9 +122,17 @@ export const getProductPerformance = async (storeId?: string): Promise<ProductPe
|
||||
/**
|
||||
* Get customer insights data
|
||||
* @param storeId Optional storeId for staff users
|
||||
* @param page Page number (default: 1)
|
||||
* @param limit Number of customers per page (default: 10)
|
||||
*/
|
||||
export const getCustomerInsights = async (storeId?: string): Promise<CustomerInsights> => {
|
||||
const url = storeId ? `/analytics/customer-insights?storeId=${storeId}` : '/analytics/customer-insights';
|
||||
export const getCustomerInsights = async (storeId?: string, page: number = 1, limit: number = 10): Promise<CustomerInsights> => {
|
||||
const params = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
limit: limit.toString()
|
||||
});
|
||||
if (storeId) params.append('storeId', storeId);
|
||||
|
||||
const url = `/analytics/customer-insights?${params.toString()}`;
|
||||
return clientFetch<CustomerInsights>(url);
|
||||
};
|
||||
|
||||
@@ -162,9 +180,9 @@ export const getProductPerformanceWithStore = async (): Promise<ProductPerforman
|
||||
return getProductPerformance(storeId);
|
||||
};
|
||||
|
||||
export const getCustomerInsightsWithStore = async (): Promise<CustomerInsights> => {
|
||||
export const getCustomerInsightsWithStore = async (page: number = 1, limit: number = 10): Promise<CustomerInsights> => {
|
||||
const storeId = getStoreIdForUser();
|
||||
return getCustomerInsights(storeId);
|
||||
return getCustomerInsights(storeId, page, limit);
|
||||
};
|
||||
|
||||
export const getOrderAnalyticsWithStore = async (period: string = '30'): Promise<OrderAnalytics> => {
|
||||
|
||||
Reference in New Issue
Block a user