PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.9
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.9
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 1.3.49 All 181 releases
disco / backend / views / components / Main / pages / Rules / Tabs / MainTabs.jsx

MainTabs.jsx in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.9, at backend/views/components/Main/pages/Rules/Tabs/MainTabs.jsx

91 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Tab } from '@headlessui/react';
2 import { __ } from '@wordpress/i18n';
3 import { useEffect } from 'react';
4 import { useDispatch, useSelector } from 'react-redux';
5 import { useLocation } from 'react-router';
6 import ProIcon from '../../../components/ProIcon';
7 import { setTab } from '../../../features/discount/discountSlice';
8 import {
9 setComponentToEdit,
10 setShowEditor,
11 } from '../../../features/interaction/interactionSlice';
12 import useIsPro from '../../../hooks/useIsPro';
13 import CampaignSetup from './CampaignSetup/CampaignSetup';
14 import DesignBlock from './DesignBlock/DesignBlock';
15 import Summary from './Summary/Summary';
16 import TabButton from './TabButton';
17
18 const MainTabs = () => {
19 const isPro = useIsPro();
20 const location = useLocation();
21 const params = new URLSearchParams(location.search);
22 const edit = params.get('edit');
23
24 const tabsButtons = [
25 {
26 id: 1,
27 text: __('Setup', 'disco'),
28 },
29
30 {
31 id: 2,
32 text: __('Display', 'disco'),
33 },
34 {
35 id: 3,
36 text: __('Summary', 'disco'),
37 },
38 ];
39 const { ui } = useSelector((state) => state.discount);
40 const dispatch = useDispatch();
41
42 // Reset editor state whenever tab changes
43 useEffect(() => {
44 dispatch(setShowEditor(false));
45 dispatch(setComponentToEdit(''));
46 }, [ui[0], dispatch]);
47
48 const handleTabChange = (index) => {
49 // Tab disabled when creating a new campaign (no edit param) for index > 0.
50 // Block the switch but keep the button enabled so ProIcon link stays clickable.
51 if (!edit && index > 0) {
52 return;
53 }
54 dispatch(setTab(index));
55 };
56
57 return (
58 <Tab.Group
59 onChange={handleTabChange}
60 // selectedIndex={ 1 }
61 selectedIndex={ui[0]}
62 manual
63 >
64 <Tab.List className="disco-flex disco-z-50 disco-sticky disco-top-8 disco-bg-gray-50 disco-p-2 disco-rounded-t-xl">
65 {tabsButtons.map((button, index) => (
66 <TabButton key={button.id} disabled={!edit && index > 0}>
67 <span className="disco-flex disco-justify-center disco-items-center disco-gap-2">
68 {button.text}
69 {!isPro && index === 1 ? <ProIcon /> : ''}
70 </span>
71 </TabButton>
72 ))}
73 </Tab.List>
74 <div className="">
75 <Tab.Panels>
76 <Tab.Panel>
77 <CampaignSetup />
78 </Tab.Panel>
79 <Tab.Panel>
80 <DesignBlock />
81 </Tab.Panel>
82 <Tab.Panel>
83 <Summary />
84 </Tab.Panel>
85 </Tab.Panels>
86 </div>
87 </Tab.Group>
88 );
89 };
90 export default MainTabs;
91