|
1 | 1 | import { isWpcomPlatformSite } from '@automattic/jetpack-script-data'; |
2 | | -import { hasFeatureFlag } from '@automattic/jetpack-shared-extension-utils'; |
3 | 2 | import { FormTokenField, ToggleControl, ExternalLink } from '@wordpress/components'; |
4 | 3 | import { store as coreStore } from '@wordpress/core-data'; |
5 | 4 | import { useSelect } from '@wordpress/data'; |
@@ -71,78 +70,76 @@ const NotificationsSettings = ( { |
71 | 70 | postAuthorEmail={ postAuthorEmail } |
72 | 71 | setAttributes={ setAttributes } |
73 | 72 | /> |
74 | | - { hasFeatureFlag( 'form-notifications' ) && ( |
75 | | - <> |
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 | | - } |
| 73 | + <> |
| 74 | + <ToggleControl |
| 75 | + label={ __( 'Enable notifications for responses', 'jetpack-forms' ) } |
| 76 | + help={ createInterpolateElement( |
| 77 | + __( |
| 78 | + 'Receive push notifications when someone fills out your form. <pushNotificationsLink>Learn more.</pushNotificationsLink>', |
| 79 | + 'jetpack-forms' |
| 80 | + ), |
| 81 | + { |
| 82 | + pushNotificationsLink: <ExternalLink href={ supportNotificationsLink } />, |
| 83 | + } |
| 84 | + ) } |
| 85 | + checked={ localFormNotifications } |
| 86 | + onChange={ value => { |
| 87 | + if ( value ) { |
| 88 | + // Auto-select post author when enabling notifications |
| 89 | + const authorIdStr = postAuthorId?.toString(); |
| 90 | + let recipientsToSet = localNotificationRecipients; |
101 | 91 |
|
102 | | - setLocalNotificationRecipients( recipientsToSet ); |
103 | | - setAttributes( { notificationRecipients: recipientsToSet } ); |
104 | | - } else { |
105 | | - setAttributes( { notificationRecipients: [] } ); |
| 92 | + if ( |
| 93 | + recipientsToSet.length === 0 && |
| 94 | + authorIdStr && |
| 95 | + eligibleUsers.some( user => user.id === postAuthorId ) |
| 96 | + ) { |
| 97 | + recipientsToSet = [ authorIdStr ]; |
106 | 98 | } |
107 | | - setLocalFormNotifications( value ); |
108 | | - } } |
109 | | - __nextHasNoMarginBottom={ true } |
110 | | - /> |
111 | | - { localFormNotifications && ( |
112 | | - <> |
113 | | - <FormTokenField |
114 | | - label={ __( 'Send notifications to', 'jetpack-forms' ) } |
115 | | - value={ selectedUserNames } |
116 | | - suggestions={ allUserNames } |
117 | | - onChange={ selectedNames => { |
118 | | - // If field is empty, default to post author |
119 | | - if ( selectedNames.length === 0 ) { |
120 | | - const authorIdStr = postAuthorId?.toString(); |
121 | | - if ( authorIdStr && eligibleUsers.some( user => user.id === postAuthorId ) ) { |
122 | | - const defaultRecipients = [ authorIdStr ]; |
123 | | - setLocalNotificationRecipients( defaultRecipients ); |
124 | | - setAttributes( { notificationRecipients: defaultRecipients } ); |
125 | | - return; |
126 | | - } |
| 99 | + |
| 100 | + setLocalNotificationRecipients( recipientsToSet ); |
| 101 | + setAttributes( { notificationRecipients: recipientsToSet } ); |
| 102 | + } else { |
| 103 | + setAttributes( { notificationRecipients: [] } ); |
| 104 | + } |
| 105 | + setLocalFormNotifications( value ); |
| 106 | + } } |
| 107 | + __nextHasNoMarginBottom={ true } |
| 108 | + /> |
| 109 | + { localFormNotifications && ( |
| 110 | + <> |
| 111 | + <FormTokenField |
| 112 | + label={ __( 'Send notifications to', 'jetpack-forms' ) } |
| 113 | + value={ selectedUserNames } |
| 114 | + suggestions={ allUserNames } |
| 115 | + onChange={ selectedNames => { |
| 116 | + // If field is empty, default to post author |
| 117 | + if ( selectedNames.length === 0 ) { |
| 118 | + const authorIdStr = postAuthorId?.toString(); |
| 119 | + if ( authorIdStr && eligibleUsers.some( user => user.id === postAuthorId ) ) { |
| 120 | + const defaultRecipients = [ authorIdStr ]; |
| 121 | + setLocalNotificationRecipients( defaultRecipients ); |
| 122 | + setAttributes( { notificationRecipients: defaultRecipients } ); |
| 123 | + return; |
127 | 124 | } |
| 125 | + } |
128 | 126 |
|
129 | | - // Convert user names back to IDs |
130 | | - const newRecipients = selectedNames |
131 | | - .map( name => { |
132 | | - const user = eligibleUsers.find( u => ( u.name || u.slug ) === name ); |
133 | | - return user ? user.id.toString() : null; |
134 | | - } ) |
135 | | - .filter( Boolean ); |
136 | | - setLocalNotificationRecipients( newRecipients ); |
137 | | - setAttributes( { notificationRecipients: newRecipients } ); |
138 | | - } } |
139 | | - __nextHasNoMarginBottom={ true } |
140 | | - __next40pxDefaultSize={ true } |
141 | | - /> |
142 | | - </> |
143 | | - ) } |
144 | | - </> |
145 | | - ) } |
| 127 | + // Convert user names back to IDs |
| 128 | + const newRecipients = selectedNames |
| 129 | + .map( name => { |
| 130 | + const user = eligibleUsers.find( u => ( u.name || u.slug ) === name ); |
| 131 | + return user ? user.id.toString() : null; |
| 132 | + } ) |
| 133 | + .filter( Boolean ); |
| 134 | + setLocalNotificationRecipients( newRecipients ); |
| 135 | + setAttributes( { notificationRecipients: newRecipients } ); |
| 136 | + } } |
| 137 | + __nextHasNoMarginBottom={ true } |
| 138 | + __next40pxDefaultSize={ true } |
| 139 | + /> |
| 140 | + </> |
| 141 | + ) } |
| 142 | + </> |
146 | 143 | </> |
147 | 144 | ); |
148 | 145 | }; |
|
0 commit comments