import { Gridicon, ExternalLink } from '@automattic/components'; import { GravatarQuickEditorCore } from '@gravatar-com/quick-editor'; import { Icon, Button } from '@wordpress/components'; import { caution } from '@wordpress/icons'; import { addQueryArgs } from '@wordpress/url'; import clsx from 'clsx'; import { localize } from 'i18n-calypso'; import PropTypes from 'prop-types'; import { Component } from 'react'; import { connect } from 'react-redux'; import VerifyEmailDialog from 'calypso/components/email-verification/email-verification-dialog'; import Gravatar from 'calypso/components/gravatar'; import InfoPopover from 'calypso/components/info-popover'; import { recordTracksEvent, recordGoogleEvent, composeAnalytics, } from 'calypso/state/analytics/actions'; import { setCurrentUser } from 'calypso/state/current-user/actions'; import { getCurrentUser } from 'calypso/state/current-user/selectors'; import { receiveGravatarDetails } from 'calypso/state/gravatar-status/actions'; import getUserSetting from 'calypso/state/selectors/get-user-setting'; import { isFetchingUserSettings } from 'calypso/state/user-settings/selectors'; import './style.scss'; // use imgSize = 400 for caching // it's the popular value for large Gravatars in Calypso const GRAVATAR_IMG_SIZE = 400; export class EditGravatar extends Component { state = { showEmailVerificationNotice: false, }; static propTypes = { translate: PropTypes.func, user: PropTypes.object, recordClickButtonEvent: PropTypes.func, recordAvatarUpdatedEvent: PropTypes.func, receiveGravatarDetails: PropTypes.func, }; quickEditor = null; componentDidMount() { const { user, setCurrentUser: setUser, recordAvatarUpdatedEvent, receiveGravatarDetails: updateGravatarDetails, } = this.props; this.quickEditor = new GravatarQuickEditorCore( { email: user.email, scope: [ 'avatars' ], utm: 'wpcomme', onProfileUpdated: () => { recordAvatarUpdatedEvent(); // Update the avatar URL to force a refresh. setUser( { ...user, avatar_URL: addQueryArgs( user.avatar_URL, { ver: Date.now() } ) } ); // Update Gravatar details updateGravatarDetails( { has_gravatar: true } ); }, } ); // Close the quick editor on any pagehide event (refresh, tab close, or navigation away). window.addEventListener( 'pagehide', this.maybeCloseQuickEditor ); } componentWillUnmount() { // Close the quick editor when the component unmounts (e.g. client-side nav). this.maybeCloseQuickEditor(); window.removeEventListener( 'pagehide', this.maybeCloseQuickEditor ); } maybeCloseQuickEditor = () => { if ( this.quickEditor?.isOpen() === true ) { this.quickEditor.close(); } }; renderEditGravatarIsLoading = () => { return (
{ this.props.translate( 'Your avatar is hidden.' ) }