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

Split PublicizeForm component #34612

Merged
merged 18 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1,029 changes: 539 additions & 490 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

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

Splitted PublicizeForm component into smaller ones
1 change: 1 addition & 0 deletions projects/js-packages/publicize-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@testing-library/dom": "8.20.1",
"@testing-library/react": "13.4.0",
"@testing-library/user-event": "14.5.1",
"@types/jest": "29.5.10",
"@types/react": "18.2.33",
"@wordpress/babel-plugin-import-jsx-pragma": "4.30.0",
"@wordpress/core-data": "6.24.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { getRedirectUrl } from '@automattic/jetpack-components';
import { getSiteFragment } from '@automattic/jetpack-shared-extension-utils';
import { ExternalLink } from '@wordpress/components';
import { createInterpolateElement, useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { usePublicizeConfig } from '../../..';
import useDismissNotice from '../../hooks/use-dismiss-notice';
import Notice from '../notice';

const MONTH_IN_SECONDS = 30 * 24 * 60 * 60;

export const AdvancedPlanNudge: React.FC = () => {
manzoorwanijk marked this conversation as resolved.
Show resolved Hide resolved
const { shouldShowAdvancedPlanNudge } = usePublicizeConfig();

const { dismissNotice, shouldShowNotice, NOTICES } = useDismissNotice();
const onAdvancedNudgeDismiss = useCallback(
() => dismissNotice( NOTICES.advancedUpgradeEditor, 3 * MONTH_IN_SECONDS ),
[ dismissNotice, NOTICES ]
);

return (
shouldShowAdvancedPlanNudge &&
shouldShowNotice( NOTICES.advancedUpgradeEditor ) && (
<Notice onDismiss={ onAdvancedNudgeDismiss } type={ 'highlight' }>
{ createInterpolateElement(
__(
'Need more reach? Unlock custom media sharing with the <upgradeLink>Advanced Plan</upgradeLink>',
'jetpack'
),
{
upgradeLink: (
<ExternalLink
href={ getRedirectUrl( 'jetpack-social-advanced-site-checkout', {
site: getSiteFragment(),
query: 'redirect_to=' + encodeURIComponent( window.location.href ),
} ) }
/>
),
}
) }
</Notice>
)
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Button } from '@wordpress/components';
import { useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { usePublicizeConfig } from '../../..';
import useDismissNotice from '../../hooks/use-dismiss-notice';
import Notice from '../notice';
import styles from './styles.module.scss';

export const AutoConversionNotice: React.FC = () => {
const { dismissNotice, shouldShowNotice, NOTICES } = useDismissNotice();

const onAutoConversionNoticeDismiss = useCallback(
() => dismissNotice( NOTICES.autoConversion ),
[ dismissNotice, NOTICES ]
);
const { adminUrl, jetpackSharingSettingsUrl } = usePublicizeConfig();

return (
shouldShowNotice( NOTICES.autoConversion ) && (
<Notice
type={ 'warning' }
actions={ [
<Button onClick={ onAutoConversionNoticeDismiss } key="dismiss" variant="primary">
{ __( 'Got it', 'jetpack' ) }
</Button>,
<Button
className={ styles[ 'change-settings-button' ] }
key="change-settings"
href={ adminUrl || jetpackSharingSettingsUrl }
target="_blank"
rel="noreferrer noopener"
>
{ __( 'Change settings', 'jetpack' ) }
</Button>,
] }
>
{ __(
'When your post is published, the selected image will be converted for maximum compatibility across your connected social networks.',
'jetpack'
) }
</Notice>
)
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ExternalLink } from '@wordpress/components';
import { createInterpolateElement } from '@wordpress/element';
import { _n } from '@wordpress/i18n';
import { usePublicizeConfig } from '../../..';
import useSocialMediaConnections from '../../hooks/use-social-media-connections';
import Notice from '../notice';
import { checkConnectionCode } from './utils';

export const BrokenConnectionsNotice: React.FC = () => {
const { connections } = useSocialMediaConnections();

const brokenConnections = connections.filter( connection =>
checkConnectionCode( connection, 'broken' )
);

const { connectionsAdminUrl } = usePublicizeConfig();
return (
brokenConnections.length > 0 && (
<Notice type={ 'error' }>
{ createInterpolateElement(
_n(
'One of your social connections is broken. Reconnect them on the <fixLink>connection management</fixLink> page.',
'Some of your social connections are broken. Reconnect them on the <fixLink>connection management</fixLink> page.',
brokenConnections.length,
'jetpack'
),
{
fixLink: <ExternalLink href={ connectionsAdminUrl } />,
}
) }
</Notice>
)
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { useSelect } from '@wordpress/data';
import { useCallback } from '@wordpress/element';
import { usePublicizeConfig } from '../../..';
import useAttachedMedia from '../../hooks/use-attached-media';
import useFeaturedImage from '../../hooks/use-featured-image';
import useImageGeneratorConfig from '../../hooks/use-image-generator-config';
import useMediaDetails from '../../hooks/use-media-details';
import useMediaRestrictions, { NO_MEDIA_ERROR } from '../../hooks/use-media-restrictions';
import useSocialMediaConnections from '../../hooks/use-social-media-connections';
import { store as socialStore } from '../../social-store';
import PublicizeConnection from '../connection';
import PublicizeSettingsButton from '../settings-button';
import styles from './styles.module.scss';

export const ConnectionsList: React.FC = () => {
const { connections, toggleById, enabledConnections } = useSocialMediaConnections();
const { isPublicizeEnabled, isPublicizeDisabledBySitePlan } = usePublicizeConfig();
const { isEnabled: isSocialImageGeneratorEnabledForPost } = useImageGeneratorConfig();
const { showShareLimits, numberOfSharesRemaining } = useSelect( select => {
return {
showShareLimits: select( socialStore ).showShareLimits(),
numberOfSharesRemaining: select( socialStore ).numberOfSharesRemaining(),
};
}, [] );

const outOfConnections = showShareLimits && numberOfSharesRemaining <= enabledConnections.length;

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

const { attachedMedia, shouldUploadAttachedMedia } = useAttachedMedia();
const featuredImageId = useFeaturedImage();
const mediaId = attachedMedia[ 0 ]?.id || featuredImageId;

const { validationErrors, isConvertible } = useMediaRestrictions(
connections,
useMediaDetails( mediaId )[ 0 ],
{
isSocialImageGeneratorEnabledForPost,
shouldUploadAttachedMedia,
}
);
const shouldAutoConvert = isAutoConversionEnabled && isConvertible;

const isConnectionEnabled = useCallback(
( { enabled, is_healthy = true, connection_id } ) =>
enabled &&
! isPublicizeDisabledBySitePlan &&
false !== is_healthy &&
( ! validationErrors[ connection_id ] || shouldAutoConvert ) &&
validationErrors[ connection_id ] !== NO_MEDIA_ERROR,
[ isPublicizeDisabledBySitePlan, validationErrors, shouldAutoConvert ]
);

return (
<ul className={ styles[ 'connections-list' ] }>
{ connections.map( conn => {
const {
display_name,
enabled,
id,
service_name,
toggleable,
profile_picture,
is_healthy,
connection_id,
} = conn;
const currentId = connection_id ? connection_id : id;
return (
<PublicizeConnection
disabled={
! isPublicizeEnabled ||
( ! enabled && toggleable && outOfConnections ) ||
false === is_healthy ||
( validationErrors[ currentId ] !== undefined && ! shouldAutoConvert ) ||
validationErrors[ currentId ] === NO_MEDIA_ERROR
}
enabled={ isConnectionEnabled( conn ) }
key={ currentId }
id={ currentId }
label={ display_name }
name={ service_name }
toggleConnection={ toggleById }
profilePicture={ profile_picture }
/>
);
} ) }
<li>
<PublicizeSettingsButton />
</li>
</ul>
);
};
Loading
Loading