PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.2.1
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.2.1
2.4.1 2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 All 68 releases
better-payment / src / blocks / user-dashboard / src / components / edit.js

edit.js in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.2.1, at src/blocks/user-dashboard/src/components/edit.js

72 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Edit component for User Dashboard block.
3 *
4 * @package Better_Payment
5 */
6
7 import { __ } from '@wordpress/i18n';
8 import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
9 import { memo, useEffect } from '@wordpress/element';
10 import { withBlockContext, BlockProps } from '@better-payment/controls';
11 import classnames from 'classnames';
12
13 // Import components
14 import Inspector from './inspector';
15 import DashboardPreview from './preview';
16 import Style from './style';
17 import defaultAttributes from './attributes';
18
19 /**
20 * Edit component - displayed in the block editor.
21 *
22 * @param {Object} props Block properties
23 * @param {Object} props.attributes Block attributes
24 * @param {Function} props.setAttributes Function to update attributes
25 * @param {string} props.clientId Block client ID
26 * @param {boolean} props.isSelected Whether block is selected
27 * @returns {JSX.Element} Edit component
28 */
29 function Edit(props) {
30 const { attributes, setAttributes, clientId, isSelected } = props;
31 const { blockId, dashboardLayout } = attributes;
32
33 // Set blockId from clientId on first insert
34 useEffect(() => {
35 if (!blockId) {
36 setAttributes({ blockId: clientId });
37 }
38 }, []);
39
40 // Build block props with custom classes
41 const blockProps = useBlockProps({
42 className: classnames(
43 'better-payment-user-dashboard',
44 blockId && `bp-${blockId}`,
45 `bp-dashboard-${dashboardLayout}`
46 ),
47 });
48
49 // Wire Style component into BlockProps.Edit via enhancedProps
50 const enhancedProps = {
51 ...props,
52 style: <Style {...props} />,
53 };
54
55 return (
56 <>
57 {isSelected && (
58 <InspectorControls>
59 <Inspector attributes={attributes} setAttributes={setAttributes} />
60 </InspectorControls>
61 )}
62 <BlockProps.Edit {...enhancedProps}>
63 <div {...blockProps}>
64 <DashboardPreview attributes={attributes} />
65 </div>
66 </BlockProps.Edit>
67 </>
68 );
69 }
70
71 export default memo(withBlockContext(defaultAttributes)(Edit));
72