Skip to content

Commit

Permalink
Jetpack Social | Direct non-admin authors to user connection if needed (
Browse files Browse the repository at this point in the history
#36976)

* Jetpack Social | Direct non-admin authors to user connection if needed

* Fix versions
  • Loading branch information
manzoorwanijk authored Apr 19, 2024
1 parent 26bfa7d commit 508c335
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Update the Social sidebar share post panel to direct non-admin authors to user connection if there is no user connection.
2 changes: 1 addition & 1 deletion projects/js-packages/publicize-components/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-publicize-components",
"version": "0.49.2",
"version": "0.49.3-alpha",
"description": "A library of JS components required by the Publicize editor plugin",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/publicize-components/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useConnection } from '@automattic/jetpack-connection';
import useSocialMediaConnections from '../../hooks/use-social-media-connections';
import PublicizeConnection from '../connection';
import PublicizeSettingsButton from '../settings-button';
Expand All @@ -9,6 +10,8 @@ export const ConnectionsList: React.FC = () => {

const { canBeTurnedOn, shouldBeDisabled } = useConnectionState();

const { isUserConnected } = useConnection();

return (
<ul className={ styles[ 'connections-list' ] }>
{ connections.map( conn => {
Expand All @@ -28,9 +31,11 @@ export const ConnectionsList: React.FC = () => {
/>
);
} ) }
<li>
<PublicizeSettingsButton />
</li>
{ isUserConnected ? (
<li>
<PublicizeSettingsButton />
</li>
) : null }
</ul>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* sharing message.
*/

import { useConnection } from '@automattic/jetpack-connection';
import { Disabled, ExternalLink, PanelRow } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { Fragment, useMemo } from '@wordpress/element';
Expand Down Expand Up @@ -45,6 +46,8 @@ export default function PublicizeForm() {
const { isPublicizeEnabled, isPublicizeDisabledBySitePlan, connectionsAdminUrl } =
usePublicizeConfig();

const useConnectionUrl = useSelect( select => select( socialStore ).userConnectionUrl(), [] );

const { numberOfSharesRemaining } = useSelect( select => {
return {
showShareLimits: select( socialStore ).showShareLimits(),
Expand Down Expand Up @@ -90,6 +93,8 @@ export default function PublicizeForm() {

refreshConnections();

const { isUserConnected } = useConnection();

return (
<Wrapper>
{ hasConnections ? (
Expand All @@ -113,13 +118,44 @@ export default function PublicizeForm() {
/>
) ) }
</>
) : (
<PanelRow>
<ExternalLink href={ connectionsAdminUrl }>
{ __( 'Connect an account', 'jetpack' ) }
</ExternalLink>
</PanelRow>
) }
) : null }
<PanelRow>
{
// Use IIFE make it more readable and avoid nested ternary operators.
( () => {
if ( ! isUserConnected ) {
return (
<p>
{ __(
'You must connect your WordPress.com account to be able to add social media connections.',
'jetpack'
) }
&nbsp;
<a href={ useConnectionUrl }>{ __( 'Connect now', 'jetpack' ) }</a>
</p>
);
}

if ( ! hasConnections ) {
return (
<p>
{ __(
'Sharing is disabled because there are no social media accounts connected.',
'jetpack'
) }
<br />
<ExternalLink href={ connectionsAdminUrl }>
{ __( 'Connect an account', 'jetpack' ) }
</ExternalLink>
</p>
);
}

return null;
} )()
}
</PanelRow>

{ ! isPublicizeDisabledBySitePlan && (
<Fragment>
{ isPublicizeEnabled && hasEnabledConnections && <SharePostForm /> }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const PublicizePanel = ( { prePublish, children } ) => {
)
}
onChange={ togglePublicizeFeature }
checked={ isPublicizeEnabled }
checked={ isPublicizeEnabled && hasConnections }
disabled={ ! hasConnections }
/>
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const reducer = combineReducers( {
socialImageGeneratorSettings,
autoConversionSettings,
hasPaidPlan: ( state = false ) => state,
userConnectionUrl: ( state = '' ) => state,
} );

export default reducer;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const selectors = {
...sharesData,
...socialImageGeneratorSettingsSelectors,
...autoConversionSettingsSelectors,
userConnectionUrl: state => state.userConnectionUrl,
};

export default selectors;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Add the userConnectionUrl to initial state to use in Social sidebar
1 change: 1 addition & 0 deletions projects/plugins/jetpack/class.jetpack-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ public static function enqueue_block_editor_assets() {
'supportedAdditionalConnections' => $publicize->get_supported_additional_connections(),
'autoConversionSettings' => $settings['autoConversionSettings'],
'jetpackSharingSettingsUrl' => esc_url_raw( admin_url( 'admin.php?page=jetpack#/sharing' ) ),
'userConnectionUrl' => esc_url_raw( admin_url( 'admin.php?page=my-jetpack#/connection' ) ),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Update the Social sidebar share post panel to direct non-admin authors to user connection if there is no user connection.
1 change: 1 addition & 0 deletions projects/plugins/social/src/class-jetpack-social.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class_exists( 'Jetpack' ) ||
'autoConversionSettings' => $settings['autoConversionSettings'],
'dismissedNotices' => Dismissed_Notices::get_dismissed_notices(),
'supportedAdditionalConnections' => $publicize->get_supported_additional_connections(),
'userConnectionUrl' => esc_url_raw( admin_url( 'admin.php?page=my-jetpack#/connection' ) ),
),
)
);
Expand Down

0 comments on commit 508c335

Please sign in to comment.