PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.2
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.2
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 1.3.48 All 180 releases
disco / backend / views / components / Main / pages / Rules / Tabs / DesignBlock / DesignBlock.jsx

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

88 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect } from 'react';
2 import { useDispatch, useSelector } from 'react-redux';
3 import { useSearchParams } from 'react-router';
4 import FooterButtons from '../../../../components/FooterButtons';
5 import { useUpdateCampaignMutation } from '../../../../features/campaigns/campaignsApi';
6 import { setTab } from '../../../../features/discount/discountSlice';
7 import {
8 setComponentToEdit,
9 setShowEditor,
10 } from '../../../../features/interaction/interactionSlice';
11 import {
12 cleanFilters,
13 validateEmptyField,
14 } from '../../../../utilities/utilities';
15 import RenderBlocks from './components/RenderBlocks';
16 import RenderEditor from './components/RenderEditor';
17 const DesignBlock = () => {
18 const dispatch = useDispatch();
19 const { discount_intent } = useSelector((state) => state.discount);
20 const { showEditor, componentToEdit } = useSelector(
21 (state) => state.interaction
22 );
23
24 const discount = useSelector((state) => state.discount);
25
26 const [updateCampaign] = useUpdateCampaignMutation();
27 const [searchParams] = useSearchParams();
28
29 const handleContinue = () => {
30 if (validateEmptyField(discount) === false) {
31 return;
32 }
33
34 // Reset editor state before navigating
35 dispatch(setShowEditor(false));
36 dispatch(setComponentToEdit(''));
37
38 if (searchParams.get('edit')) {
39 const dataForRequest = { ...discount };
40
41 delete dataForRequest.created_by;
42 delete dataForRequest.modified_by;
43
44 dataForRequest.conditions = cleanFilters(discount.conditions);
45
46 updateCampaign({
47 id: discount.id,
48 data: {
49 ...dataForRequest,
50 priority: String(dataForRequest.priority),
51 ui: [discount.ui[0] + 1, 0],
52 },
53 });
54 }
55
56 dispatch(setTab(2));
57 };
58 const handleBack = () => {
59 // Reset editor state before navigating back
60 dispatch(setShowEditor(false));
61 dispatch(setComponentToEdit(''));
62 dispatch(setTab(0));
63 };
64
65 useEffect(() => {
66 window.scrollTo({ top: 0, left: 0, behavior: 'smooth' });
67 }, []);
68
69 return (
70 <>
71 <div className="disco-mx-3">
72 {!showEditor ? (
73 <RenderBlocks discount_intent={discount_intent} />
74 ) : (
75 <RenderEditor componentName={componentToEdit} />
76 )}
77 </div>
78
79 <FooterButtons
80 handleContinue={handleContinue}
81 handleBack={handleBack}
82 disabled={showEditor}
83 />
84 </>
85 );
86 };
87 export default DesignBlock;
88