Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriptions: Adapt message based on Publicize status #28867

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: enhancement

Newsletter Panel message now adapts based on Publicize status.
99 changes: 71 additions & 28 deletions projects/plugins/jetpack/extensions/blocks/subscriptions/panel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { JetpackLogo, numberFormat } from '@automattic/jetpack-components';
import {
usePublicizeConfig,
useSocialMediaConnections,
} from '@automattic/jetpack-publicize-components';
import { isComingSoon, isPrivateSite } from '@automattic/jetpack-shared-extension-utils';
import { useEntityProp } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
Expand All @@ -24,6 +28,9 @@ export default function SubscribePanels() {
const accessLevel =
postMeta[ META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS ] ?? Object.keys( accessOptions )[ 0 ];

const { hasConnections, hasEnabledConnections } = useSocialMediaConnections();
const { isPublicizeEnabled } = usePublicizeConfig();

const [ followerCount, setFollowerCount ] = useState( null );
useEffect( () => {
getSubscriberCounts( counts => {
Expand Down Expand Up @@ -63,6 +70,8 @@ export default function SubscribePanels() {
return null;
}

const willShareToSocialMedia = isPublicizeEnabled && hasConnections && hasEnabledConnections;

const showNotices = Number.isFinite( subscriberCount ) && subscriberCount > 0;
return (
<>
Expand All @@ -80,23 +89,40 @@ export default function SubscribePanels() {
>
{ showNotices && (
<InspectorNotice>
{ createInterpolateElement(
sprintf(
/* translators: 1$s will be subscribers, %2$s will be social followers */
__( 'This post will reach <span>%1$s</span> and <span>%2$s</span>.', 'jetpack' ),
{ willShareToSocialMedia &&
createInterpolateElement(
sprintf(
/* translators: %s will be a number of subscribers */
_n( '%s subscriber', '%s subscribers', subscriberCount, 'jetpack' ),
numberFormat( subscriberCount )
/* translators: 1$s will be subscribers, %2$s will be social followers */
jeherve marked this conversation as resolved.
Show resolved Hide resolved
__( 'This post will reach <span>%1$s</span> and <span>%2$s</span>.', 'jetpack' ),
sprintf(
/* translators: %s will be a number of subscribers */
_n( '%s subscriber', '%s subscribers', subscriberCount, 'jetpack' ),
numberFormat( subscriberCount )
),
sprintf(
/* translators: %s will be a number of social followers */
_n( '%s social follower', '%s social followers', followerCount, 'jetpack' ),
numberFormat( followerCount )
)
),
{ span: <span className="jetpack-subscribe-reader-count" /> }
) }
{ ! willShareToSocialMedia &&
createInterpolateElement(
sprintf(
/* translators: %s will be a number of social followers */
_n( '%s social follower', '%s social followers', followerCount, 'jetpack' ),
numberFormat( followerCount )
)
),
{ span: <span className="jetpack-subscribe-reader-count" /> }
) }
/* translators: 1$s will be subscribers, %2$s will be social followers */
jeherve marked this conversation as resolved.
Show resolved Hide resolved
__(
'This post will reach <span>%1$s</span> and wonʼt be shared on social.',
danielbachhuber marked this conversation as resolved.
Show resolved Hide resolved
'jetpack'
),
sprintf(
/* translators: %s will be a number of subscribers */
_n( '%s subscriber', '%s subscribers', subscriberCount, 'jetpack' ),
numberFormat( subscriberCount )
)
),
{ span: <span className="jetpack-subscribe-reader-count" /> }
) }
</InspectorNotice>
) }

Expand All @@ -107,23 +133,40 @@ export default function SubscribePanels() {
<PluginPostPublishPanel className="jetpack-subscribe-post-publish-panel" initialOpen>
{ showNotices && (
<InspectorNotice>
{ createInterpolateElement(
sprintf(
/* translators: 1$s will be subscribers, %2$s will be social followers */
__( 'This post was shared to <span>%1$s</span> and <span>%2$s</span>.', 'jetpack' ),
{ willShareToSocialMedia &&
createInterpolateElement(
sprintf(
/* translators: %s will be a number of subscribers */
_n( '%s subscriber', '%s subscribers', subscriberCount, 'jetpack' ),
numberFormat( subscriberCount )
/* translators: 1$s will be subscribers, %2$s will be social followers */
__(
'This post was shared to <span>%1$s</span> and <span>%2$s</span>.',
'jetpack'
),
sprintf(
/* translators: %s will be a number of subscribers */
_n( '%s subscriber', '%s subscribers', subscriberCount, 'jetpack' ),
numberFormat( subscriberCount )
),
sprintf(
/* translators: %s will be a number of social followers */
_n( '%s social follower', '%s social followers', followerCount, 'jetpack' ),
numberFormat( followerCount )
)
),
{ span: <span className="jetpack-subscribe-reader-count" /> }
) }
{ ! willShareToSocialMedia &&
createInterpolateElement(
sprintf(
/* translators: %s will be a number of social followers */
_n( '%s social follower', '%s social followers', followerCount, 'jetpack' ),
numberFormat( followerCount )
)
),
{ span: <span className="jetpack-subscribe-reader-count" /> }
) }
/* translators: 1$s will be subscribers, %2$s will be social followers */
__( 'This post was shared to <span>%1$s</span>.', 'jetpack' ),
sprintf(
/* translators: %s will be a number of subscribers */
_n( '%s subscriber', '%s subscribers', subscriberCount, 'jetpack' ),
numberFormat( subscriberCount )
)
),
{ span: <span className="jetpack-subscribe-reader-count" /> }
) }
</InspectorNotice>
) }
</PluginPostPublishPanel>
Expand Down