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 / campaign-builder / components / CampaignNameModal.js

CampaignNameModal.js in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.2.1, at src/campaign-builder/components/CampaignNameModal.js

58 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useState, useEffect, useRef } from '@wordpress/element';
2 import { __ } from '@wordpress/i18n';
3
4 /**
5 * Modal for editing the campaign name inline.
6 * Opens when user clicks the name in the top nav bar.
7 */
8 export default function CampaignNameModal( { currentName, onSave, onClose } ) {
9 const [ name, setName ] = useState( currentName || '' );
10 const inputRef = useRef( null );
11
12 useEffect( () => {
13 inputRef.current?.focus();
14 inputRef.current?.select();
15 }, [] );
16
17 const handleSubmit = ( e ) => {
18 e.preventDefault();
19 const trimmed = name.trim();
20 if ( trimmed ) {
21 onSave( trimmed );
22 }
23 onClose();
24 };
25
26 const handleKeyDown = ( e ) => {
27 if ( e.key === 'Escape' ) onClose();
28 };
29
30 return (
31 <div className="bp-name-modal-overlay" onClick={ onClose }>
32 <div className="bp-name-modal" onClick={ ( e ) => e.stopPropagation() }>
33 <h3 className="bp-name-modal__title">{ __( 'Edit Campaign Name', 'better-payment' ) }</h3>
34 <form onSubmit={ handleSubmit }>
35 <input
36 ref={ inputRef }
37 className="bp-name-modal__input"
38 type="text"
39 value={ name }
40 onChange={ ( e ) => setName( e.target.value ) }
41 onKeyDown={ handleKeyDown }
42 placeholder={ __( 'Campaign name…', 'better-payment' ) }
43 maxLength={ 200 }
44 />
45 <div className="bp-name-modal__actions">
46 <button type="button" className="bp-cb-btn bp-cb-btn--ghost-dark" onClick={ onClose }>
47 { __( 'Cancel', 'better-payment' ) }
48 </button>
49 <button type="submit" className="bp-cb-btn bp-cb-btn--blue" disabled={ ! name.trim() }>
50 { __( 'Update', 'better-payment' ) }
51 </button>
52 </div>
53 </form>
54 </div>
55 </div>
56 );
57 }
58