File size: 3,741 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
import config from '@automattic/calypso-config';
import { localize } from 'i18n-calypso';
import { times } from 'lodash';
import PropTypes from 'prop-types';
import { Fragment, PureComponent } from 'react';
import { connect } from 'react-redux';
import DocumentHead from 'calypso/components/data/document-head';
import QueryConnectedApplications from 'calypso/components/data/query-connected-applications';
import EmptyContent from 'calypso/components/empty-content';
import HeaderCake from 'calypso/components/header-cake';
import Main from 'calypso/components/main';
import NavigationHeader from 'calypso/components/navigation-header';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import twoStepAuthorization from 'calypso/lib/two-step-authorization';
import ConnectedAppItem from 'calypso/me/connected-application-item';
import ReauthRequired from 'calypso/me/reauth-required';
import SecuritySectionNav from 'calypso/me/security-section-nav';
import getConnectedApplications from 'calypso/state/selectors/get-connected-applications';
import getCurrentIntlCollator from 'calypso/state/selectors/get-current-intl-collator';
import './style.scss';
class ConnectedApplications extends PureComponent {
static propTypes = {
translate: PropTypes.func.isRequired,
};
renderEmptyContent() {
const { translate } = this.props;
return (
<EmptyContent
title={ translate( "You haven't connected any apps yet." ) }
line={ translate( 'You can get started with the {{link}}WordPress mobile apps!{{/link}}', {
components: {
link: (
<a
href="https://apps.wordpress.org/"
target="_blank"
rel="noopener noreferrer"
title="WordPress Mobile Apps"
/>
),
},
} ) }
/>
);
}
renderPlaceholders() {
const { translate } = this.props;
return times( 5, ( index ) => (
<ConnectedAppItem
connection={ {
ID: index,
title: translate( 'Loading Connected Applications' ),
} }
key={ index }
isPlaceholder
/>
) );
}
renderConnectedApps() {
const { apps, intlCollator } = this.props;
if ( apps === null ) {
return this.renderPlaceholders();
}
if ( ! apps.length ) {
return this.renderEmptyContent();
}
// Sorts the list into alphabetical order then displays them.
return apps
.sort( ( a, b ) => {
return intlCollator.compare( a.title, b.title );
} )
.map( ( connection ) => (
<ConnectedAppItem connection={ connection } key={ connection.ID } />
) );
}
renderConnectedAppsList() {
const { path, translate } = this.props;
const useCheckupMenu = config.isEnabled( 'security/security-checkup' );
return (
<Fragment>
{ ! useCheckupMenu && <SecuritySectionNav path={ path } /> }
{ useCheckupMenu && (
<HeaderCake backText={ translate( 'Back' ) } backHref="/me/security">
{ translate( 'Connected Applications' ) }
</HeaderCake>
) }
{ this.renderConnectedApps() }
</Fragment>
);
}
render() {
const { translate } = this.props;
return (
<Main wideLayout className="security connected-applications">
<QueryConnectedApplications />
<PageViewTracker
path="/me/security/connected-applications"
title="Me > Connected Applications"
/>
<ReauthRequired twoStepAuthorization={ twoStepAuthorization } />
<NavigationHeader navigationItems={ [] } title={ translate( 'Security' ) } />
<DocumentHead title={ translate( 'Connected Applications' ) } />
{ this.renderConnectedAppsList() }
</Main>
);
}
}
export default connect( ( state ) => ( {
apps: getConnectedApplications( state ),
intlCollator: getCurrentIntlCollator( state ),
} ) )( localize( ConnectedApplications ) );
|