| 
1 |  | -import { FormTokenField, ToggleControl } from '@wordpress/components';  | 
 | 1 | +import { isWpcomPlatformSite } from '@automattic/jetpack-script-data';  | 
 | 2 | +import { hasFeatureFlag } from '@automattic/jetpack-shared-extension-utils';  | 
 | 3 | +import { FormTokenField, ToggleControl, ExternalLink } from '@wordpress/components';  | 
2 | 4 | import { store as coreStore } from '@wordpress/core-data';  | 
3 | 5 | import { useSelect } from '@wordpress/data';  | 
4 | 6 | import { store as editorStore } from '@wordpress/editor';  | 
5 |  | -import { useState } from '@wordpress/element';  | 
 | 7 | +import { useState, createInterpolateElement } from '@wordpress/element';  | 
6 | 8 | import { __ } from '@wordpress/i18n';  | 
7 |  | -import InspectorHint from '../../shared/components/inspector-hint';  | 
 | 9 | +import JetpackEmailConnectionSettings from './jetpack-email-connection-settings';  | 
8 | 10 | 
 
  | 
9 |  | -const NotificationsSettings = ( { setAttributes, notificationRecipients } ) => {  | 
 | 11 | +const NotificationsSettings = ( {  | 
 | 12 | +	setAttributes,  | 
 | 13 | +	notificationRecipients,  | 
 | 14 | +	emailAddress,  | 
 | 15 | +	emailSubject,  | 
 | 16 | +	emailNotifications,  | 
 | 17 | +	instanceId,  | 
 | 18 | +	postAuthorEmail,  | 
 | 19 | +} ) => {  | 
10 | 20 | 	const [ localNotificationRecipients, setLocalNotificationRecipients ] =  | 
11 | 21 | 		useState( notificationRecipients );  | 
12 | 22 | 	const [ localFormNotifications, setLocalFormNotifications ] = useState(  | 
@@ -47,57 +57,79 @@ const NotificationsSettings = ( { setAttributes, notificationRecipients } ) => {  | 
47 | 57 | 	// All available user names for suggestions  | 
48 | 58 | 	const allUserNames = eligibleUsers.map( user => user.name || user.slug );  | 
49 | 59 | 
 
  | 
 | 60 | +	const supportNotificationsLink = isWpcomPlatformSite()  | 
 | 61 | +		? 'https://jetpack.com/support/notifications/'  | 
 | 62 | +		: 'https://wordpress.com/support/notifications/';  | 
 | 63 | + | 
50 | 64 | 	return (  | 
51 | 65 | 		<>  | 
52 |  | -			<ToggleControl  | 
53 |  | -				label={ __( 'Enable form response notifications', 'jetpack-forms' ) }  | 
54 |  | -				checked={ localFormNotifications }  | 
55 |  | -				onChange={ value => {  | 
56 |  | -					if ( value ) {  | 
57 |  | -						// Auto-select post author when enabling notifications  | 
58 |  | -						const authorIdStr = postAuthorId?.toString();  | 
59 |  | -						let recipientsToSet = localNotificationRecipients;  | 
60 |  | - | 
61 |  | -						if (  | 
62 |  | -							recipientsToSet.length === 0 &&  | 
63 |  | -							authorIdStr &&  | 
64 |  | -							eligibleUsers.some( user => user.id === postAuthorId )  | 
65 |  | -						) {  | 
66 |  | -							recipientsToSet = [ authorIdStr ];  | 
67 |  | -						}  | 
68 |  | - | 
69 |  | -						setLocalNotificationRecipients( recipientsToSet );  | 
70 |  | -						setAttributes( { notificationRecipients: recipientsToSet } );  | 
71 |  | -					} else {  | 
72 |  | -						setAttributes( { notificationRecipients: [] } );  | 
73 |  | -					}  | 
74 |  | -					setLocalFormNotifications( value );  | 
75 |  | -				} }  | 
76 |  | -				__nextHasNoMarginBottom={ true }  | 
 | 66 | +			<JetpackEmailConnectionSettings  | 
 | 67 | +				emailAddress={ emailAddress }  | 
 | 68 | +				emailSubject={ emailSubject }  | 
 | 69 | +				emailNotifications={ emailNotifications }  | 
 | 70 | +				instanceId={ instanceId }  | 
 | 71 | +				postAuthorEmail={ postAuthorEmail }  | 
 | 72 | +				setAttributes={ setAttributes }  | 
77 | 73 | 			/>  | 
78 |  | -			{ localFormNotifications && (  | 
 | 74 | +			{ hasFeatureFlag( 'form-notifications' ) && (  | 
79 | 75 | 				<>  | 
80 |  | -					<InspectorHint>  | 
81 |  | -						{ __( 'Select users who can receive form response notifications:', 'jetpack-forms' ) }  | 
82 |  | -					</InspectorHint>  | 
83 |  | -					<FormTokenField  | 
84 |  | -						label={ __( 'Send notifications to', 'jetpack-forms' ) }  | 
85 |  | -						value={ selectedUserNames }  | 
86 |  | -						suggestions={ allUserNames }  | 
87 |  | -						onChange={ selectedNames => {  | 
88 |  | -							// Convert user names back to IDs  | 
89 |  | -							const newRecipients = selectedNames  | 
90 |  | -								.map( name => {  | 
91 |  | -									const user = eligibleUsers.find( u => ( u.name || u.slug ) === name );  | 
92 |  | -									return user ? user.id.toString() : null;  | 
93 |  | -								} )  | 
94 |  | -								.filter( Boolean );  | 
95 |  | -							setLocalNotificationRecipients( newRecipients );  | 
96 |  | -							setAttributes( { notificationRecipients: newRecipients } );  | 
 | 76 | +					<ToggleControl  | 
 | 77 | +						label={ __( 'Enable notifications for responses', 'jetpack-forms' ) }  | 
 | 78 | +						help={ createInterpolateElement(  | 
 | 79 | +							__(  | 
 | 80 | +								'Receive push notifications when someone fills out your form. <pushNotificationsLink>Learn more.</pushNotificationsLink>',  | 
 | 81 | +								'jetpack-forms'  | 
 | 82 | +							),  | 
 | 83 | +							{  | 
 | 84 | +								pushNotificationsLink: <ExternalLink href={ supportNotificationsLink } />,  | 
 | 85 | +							}  | 
 | 86 | +						) }  | 
 | 87 | +						checked={ localFormNotifications }  | 
 | 88 | +						onChange={ value => {  | 
 | 89 | +							if ( value ) {  | 
 | 90 | +								// Auto-select post author when enabling notifications  | 
 | 91 | +								const authorIdStr = postAuthorId?.toString();  | 
 | 92 | +								let recipientsToSet = localNotificationRecipients;  | 
 | 93 | + | 
 | 94 | +								if (  | 
 | 95 | +									recipientsToSet.length === 0 &&  | 
 | 96 | +									authorIdStr &&  | 
 | 97 | +									eligibleUsers.some( user => user.id === postAuthorId )  | 
 | 98 | +								) {  | 
 | 99 | +									recipientsToSet = [ authorIdStr ];  | 
 | 100 | +								}  | 
 | 101 | + | 
 | 102 | +								setLocalNotificationRecipients( recipientsToSet );  | 
 | 103 | +								setAttributes( { notificationRecipients: recipientsToSet } );  | 
 | 104 | +							} else {  | 
 | 105 | +								setAttributes( { notificationRecipients: [] } );  | 
 | 106 | +							}  | 
 | 107 | +							setLocalFormNotifications( value );  | 
97 | 108 | 						} }  | 
98 | 109 | 						__nextHasNoMarginBottom={ true }  | 
99 |  | -						__next40pxDefaultSize={ true }  | 
100 | 110 | 					/>  | 
 | 111 | +					{ localFormNotifications && (  | 
 | 112 | +						<>  | 
 | 113 | +							<FormTokenField  | 
 | 114 | +								label={ __( 'Send notifications to', 'jetpack-forms' ) }  | 
 | 115 | +								value={ selectedUserNames }  | 
 | 116 | +								suggestions={ allUserNames }  | 
 | 117 | +								onChange={ selectedNames => {  | 
 | 118 | +									// Convert user names back to IDs  | 
 | 119 | +									const newRecipients = selectedNames  | 
 | 120 | +										.map( name => {  | 
 | 121 | +											const user = eligibleUsers.find( u => ( u.name || u.slug ) === name );  | 
 | 122 | +											return user ? user.id.toString() : null;  | 
 | 123 | +										} )  | 
 | 124 | +										.filter( Boolean );  | 
 | 125 | +									setLocalNotificationRecipients( newRecipients );  | 
 | 126 | +									setAttributes( { notificationRecipients: newRecipients } );  | 
 | 127 | +								} }  | 
 | 128 | +								__nextHasNoMarginBottom={ true }  | 
 | 129 | +								__next40pxDefaultSize={ true }  | 
 | 130 | +							/>  | 
 | 131 | +						</>  | 
 | 132 | +					) }  | 
101 | 133 | 				</>  | 
102 | 134 | 			) }  | 
103 | 135 | 		</>  | 
 | 
0 commit comments