PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.12
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.12
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 / CampaignsReports.jsx

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

103 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import CampaignsTable from '@/components/campaigns/CampaignsTable';
2 import { useGetCampaignsQuery } from '@/features/campaigns/campaignsApi';
3 import { selectDateRangeParams } from '@/features/dateRange/dateRangeSlice';
4 import useIsPro from '@/lib/useIsPro';
5 import { fmt } from '@/lib/utils';
6 import { __ } from '@wordpress/i18n';
7 import { useState } from 'react';
8 import { useSelector } from 'react-redux';
9
10 const CAMPAIGN_COLORS = [
11 '#ef4444',
12 '#3b82f6',
13 '#8b5cf6',
14 '#f59e0b',
15 '#10b981',
16 '#f97316',
17 '#06b6d4',
18 '#ec4899',
19 '#84cc16',
20 '#a78bfa',
21 ];
22
23 function formatDateRange(valid_date) {
24 if (!valid_date || valid_date === 'Unknown') return '—';
25 const { from, to } = valid_date;
26 if (!from && !to) return '—';
27 const fmt = (d) => {
28 if (!d) return '—';
29 return new Date(d).toLocaleDateString('en-US', {
30 month: 'short',
31 day: 'numeric',
32 });
33 };
34 return `${fmt(from)} – ${fmt(to)}`;
35 }
36
37 const CampaignsReports = () => {
38 const [search, setSearch] = useState('');
39 const [sortKey, setSortKey] = useState('revenue');
40 const [sortDir, setSortDir] = useState('desc');
41 const dateParams = useSelector(selectDateRangeParams);
42 const isPro = useIsPro();
43
44 const {
45 data: res,
46 isLoading,
47 isFetching,
48 } = useGetCampaignsQuery({
49 ...dateParams,
50 limit: isPro ? 20 : 10,
51 sort_by: sortKey,
52 order: sortDir,
53 search: search || undefined,
54 page: 1,
55 });
56
57 const campaigns = (res?.data ?? []).map((c, index) => ({
58 id: c.campaign_id,
59 name: c.campaign_name,
60 dotColor: CAMPAIGN_COLORS[index % CAMPAIGN_COLORS.length],
61 intent: c.intent,
62 dateRange: formatDateRange(c.valid_date),
63 orders: c.orders,
64 customers: c.customers,
65 revenue: fmt(c.revenue),
66 status: c.status,
67 }));
68
69 return (
70 <div className="disco-min-h-screen disco-bg-[#f9fafb] disco-p-6">
71 <div className="disco-mb-5">
72 <h1 className="disco-text-lg disco-font-bold disco-text-[#111827] disco-tracking-tight">
73 {__('Campaigns', 'disco')}
74 </h1>
75 <p className="disco-text-xs disco-text-[#9ca3af] disco-mt-0.5">
76 {__('All discount campaigns', 'disco')}
77 </p>
78 </div>
79
80 <CampaignsTable
81 campaigns={campaigns}
82 isLoading={isLoading || isFetching}
83 search={search}
84 sortKey={sortKey}
85 sortDir={sortDir}
86 onSearchChange={setSearch}
87 onSort={(key) => {
88 if (key === sortKey) {
89 setSortDir(sortDir === 'asc' ? 'desc' : 'asc');
90 } else {
91 setSortKey(key);
92 setSortDir('desc');
93 }
94 }}
95 count={res?.collection?.count}
96 total={res?.collection?.total}
97 />
98 </div>
99 );
100 };
101
102 export default CampaignsReports;
103