PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.19
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.19
1.4.19 1.4.18 1.4.17 1.4.16 1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 All 182 releases
disco / backend / views / components / Analytics / pages / Products.jsx

Products.jsx in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.19, at backend/views/components/Analytics/pages/Products.jsx

96 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import ProductsTable from '@/components/products/ProductsTable';
2 import { selectDateRangeParams } from '@/features/dateRange/dateRangeSlice';
3 import { useGetProductsQuery } from '@/features/products/productsApi';
4 import useIsPro from '@/lib/useIsPro';
5 import { campaignsSort, fmt } from '@/lib/utils';
6 import { __ } from '@wordpress/i18n';
7 import { useState } from 'react';
8 import { useSelector } from 'react-redux';
9
10 const SORT_MAP = {
11 orders: 'orders',
12 customers: 'customers',
13 revenue: 'revenue',
14 };
15
16 const Products = () => {
17 const dateParams = useSelector(selectDateRangeParams);
18 const [page, setPage] = useState(1);
19 const [sortKey, setSortKey] = useState('revenue');
20 const [sortDir, setSortDir] = useState('desc');
21 const [search, setSearch] = useState('');
22 const isPro = useIsPro();
23
24 const {
25 data: res,
26 isLoading,
27 isFetching,
28 } = useGetProductsQuery({
29 ...dateParams,
30 limit: isPro ? 20 : 10,
31 sort_by: SORT_MAP[sortKey] ?? 'revenue',
32 order: sortDir,
33 page,
34 ...(search ? { search } : {}),
35 });
36
37 const products = (res?.data ?? []).map((p) => ({
38 id: p.id,
39 image: p.image,
40 name: p.name,
41 unitPrice: `${fmt(p.unit_price)} unit price`,
42 category: (p.categories ?? []).map((c) => c.name).join(', ') || '—',
43 campaigns: campaignsSort([...p.campaigns]),
44 orders: p.total_orders,
45 customers: p.total_customers,
46 revenue: fmt(p.total_revenue),
47 }));
48
49 const total = res?.collection?.total ?? 0;
50 const totalPages = res?.collection?.total_pages ?? 1;
51 const count = res?.collection?.count ?? 0;
52
53 const handleSort = (key) => {
54 if (sortKey === key) setSortDir((d) => (d === 'asc' ? 'desc' : 'asc'));
55 else {
56 setSortKey(key);
57 setSortDir('desc');
58 }
59 setPage(1);
60 };
61
62 const handleSearch = (value) => {
63 setSearch(value);
64 setPage(1);
65 };
66
67 return (
68 <div className="disco:min-h-screen disco:bg-[#f9fafb] disco:px-6 disco:py-2">
69 <div className="disco:mb-5">
70 <h1 className="disco:text-lg! disco:font-bold! disco:text-[#111827]! disco:tracking-tight">
71 {__('Products', 'disco')}
72 </h1>
73 <p className="disco:text-xs! disco:text-[#9ca3af] disco:mt-0.5">
74 {__('Revenue and discount performance by product', 'disco')}
75 </p>
76 </div>
77 <ProductsTable
78 products={products}
79 isLoading={isLoading || isFetching}
80 search={search}
81 onSearchChange={handleSearch}
82 sortKey={sortKey}
83 sortDir={sortDir}
84 onSort={handleSort}
85 page={page}
86 totalPages={totalPages}
87 total={total}
88 count={count}
89 onPageChange={setPage}
90 />
91 </div>
92 );
93 };
94
95 export default Products;
96