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 / CampaignDetails.jsx

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

107 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import CampaignCustomersTable from '@/components/campaigns/CampaignCustomersTable';
2 import CampaignHeader from '@/components/campaigns/CampaignHeader';
3 import CampaignMetrics from '@/components/campaigns/CampaignMetrics';
4 import CampaignNotFound from '@/components/campaigns/CampaignNotFound';
5 import CampaignProductsTable from '@/components/campaigns/CampaignProductsTable';
6 import { useGetCampaignQuery } from '@/features/campaigns/campaignsApi';
7 import { selectDateRangeParams } from '@/features/dateRange/dateRangeSlice';
8 import { cn, fmt, formatDate } from '@/lib/utils';
9 import { __ } from '@wordpress/i18n';
10 import { useState } from 'react';
11 import { useSelector } from 'react-redux';
12 import { useParams } from 'react-router';
13
14 const CAMPAIGN_COLORS = ['#ef4444', '#3b82f6', '#8b5cf6', '#f59e0b', '#10b981'];
15
16 const TABS = [
17 { id: 'products', label: __('Products', 'disco') },
18 { id: 'customers', label: __('Customers', 'disco') },
19 ];
20
21 const CampaignDetails = () => {
22 const { campaignId } = useParams();
23 const dateParams = useSelector(selectDateRangeParams);
24 const { data, isLoading, isError } = useGetCampaignQuery({
25 id: campaignId,
26 ...dateParams,
27 });
28 const [activeTab, setActiveTab] = useState('products');
29
30 if (isError) {
31 return <CampaignNotFound />;
32 }
33
34 const campaign = data
35 ? {
36 dotColor:
37 CAMPAIGN_COLORS[data.campaign_id % CAMPAIGN_COLORS.length],
38 name: data.campaign_name,
39 intent: data.intent,
40 dateRange: `${formatDate(data.valid_date?.from)} - ${formatDate(data.valid_date?.to)}`,
41 status: data.status,
42 totalOrders: data.total_orders,
43 customers: data.total_customers,
44 revenue: fmt(data.revenue),
45 }
46 : null;
47
48 return (
49 <div className="disco:min-h-screen disco:bg-[#f9fafb] disco:px-6 disco:py-2 disco:space-y-3">
50 {isLoading ? (
51 <div className="disco:space-y-3">
52 <div className="disco:h-16 disco:animate-pulse disco:rounded-xl disco:bg-white disco:border disco:border-[#e5e7eb]" />
53 <div className="disco:flex disco:gap-3">
54 {Array.from({ length: 2 }).map((_, i) => (
55 <div
56 key={i}
57 className="disco:flex-1 disco:h-20 disco:animate-pulse disco:rounded-xl disco:bg-white disco:border disco:border-[#e5e7eb]"
58 />
59 ))}
60 </div>
61 </div>
62 ) : campaign ? (
63 <>
64 {/* Campaign header */}
65 <CampaignHeader campaign={campaign} />
66
67 {/* Metric cards */}
68 <CampaignMetrics
69 revenue={data.revenue}
70 averageOrderValue={data.average_order_value}
71 totalOrders={data.total_orders}
72 customers={data.total_customers}
73 />
74 </>
75 ) : null}
76
77 {/* Tabs */}
78 <div className="disco:bg-white disco:border disco:border-[#e5e7eb] disco:rounded-xl disco:overflow-hidden">
79 <div className="disco:flex disco:gap-0 disco:border-b disco:border-[#e5e7eb] disco:px-4 disco:pt-3">
80 {TABS.map((tab) => (
81 <button
82 key={tab.id}
83 onClick={() => setActiveTab(tab.id)}
84 className={cn(
85 'disco:px-3 disco:pb-2.5 disco:text-xs disco:font-medium disco:border-b-2 disco:transition-colors disco:mr-1',
86 activeTab === tab.id
87 ? 'disco:border-[#0dc98b] disco:text-[#0dc98b]'
88 : 'disco:border-transparent disco:text-[#6b7280] disco:hover:text-[#111827]'
89 )}
90 >
91 {tab.label}
92 </button>
93 ))}
94 </div>
95
96 {activeTab === 'products' ? (
97 <CampaignProductsTable embedded campaignId={campaignId} />
98 ) : (
99 <CampaignCustomersTable embedded campaignId={campaignId} />
100 )}
101 </div>
102 </div>
103 );
104 };
105
106 export default CampaignDetails;
107