diff --git a/client/me/help/help-contact-form/index.jsx b/client/me/help/help-contact-form/index.jsx index 1171bdf07031e7..f044632ed8a313 100644 --- a/client/me/help/help-contact-form/index.jsx +++ b/client/me/help/help-contact-form/index.jsx @@ -22,9 +22,8 @@ import FormTextInput from 'components/forms/form-text-input'; import FormButton from 'components/forms/form-button'; import SitesDropdown from 'components/sites-dropdown'; import ChatClosureNotice from '../chat-closure-notice'; -import { getSelectedOrPrimarySiteId } from 'state/selectors'; -import { getHelpSelectedSiteId } from 'state/help/selectors'; import { selectSiteId } from 'state/help/actions'; +import { getHelpSelectedSite } from 'state/help/selectors'; export const HelpContactForm = React.createClass( { mixins: [ LinkedStateMixin, PureRenderMixin ], @@ -38,6 +37,7 @@ export const HelpContactForm = React.createClass( { showSubjectField: PropTypes.bool, showSiteField: PropTypes.bool, showHelpLanguagePrompt: PropTypes.bool, + selectedSite: PropTypes.object, siteFilter: PropTypes.func, siteList: PropTypes.object, disabled: PropTypes.bool, @@ -165,7 +165,20 @@ export const HelpContactForm = React.createClass( { * @param {object} event Event object */ submitForm() { - this.props.onSubmit( this.state ); + const { + howCanWeHelp, + howYouFeel, + message, + subject + } = this.state; + + this.props.onSubmit( { + howCanWeHelp, + howYouFeel, + message, + subject, + site: this.props.selectedSite, + } ); }, /** @@ -224,7 +237,7 @@ export const HelpContactForm = React.createClass( {
{ translate( 'Which site do you need help with?' ) }
) } @@ -250,11 +263,9 @@ export const HelpContactForm = React.createClass( { } } ); -const mapStateToProps = ( state ) => { - return { - selectedSiteId: getHelpSelectedSiteId( state ) || getSelectedOrPrimarySiteId( state ) - }; -}; +const mapStateToProps = ( state ) => ( { + selectedSite: getHelpSelectedSite( state ), +} ); const mapDispatchToProps = { onChangeSite: selectSiteId diff --git a/client/me/help/help-contact/index.jsx b/client/me/help/help-contact/index.jsx index bee94a9c2a4b59..d273528f34658c 100644 --- a/client/me/help/help-contact/index.jsx +++ b/client/me/help/help-contact/index.jsx @@ -132,8 +132,7 @@ const HelpContact = React.createClass( { startHappychat: function( contactForm ) { this.props.openHappychat(); - const { message, siteId } = contactForm; - const site = sites.getSite( siteId ); + const { message, site } = contactForm; this.props.sendUserInfo( site.URL ); this.props.sendHappychatMessage( message ); @@ -147,8 +146,7 @@ const HelpContact = React.createClass( { }, startChat: function( contactForm ) { - const { message, howCanWeHelp, howYouFeel, siteId } = contactForm; - const site = sites.getSite( siteId ); + const { message, howCanWeHelp, howYouFeel, site } = contactForm; // Intentionally not translated since only HE's will see this in the olark console as a notification. const notifications = [ @@ -194,9 +192,8 @@ const HelpContact = React.createClass( { }, submitKayakoTicket: function( contactForm ) { - const { subject, message, howCanWeHelp, howYouFeel, siteId } = contactForm; + const { subject, message, howCanWeHelp, howYouFeel, site } = contactForm; const { currentUserLocale } = this.props; - const site = sites.getSite( siteId ); const ticketMeta = [ 'How can you help: ' + howCanWeHelp, diff --git a/client/state/happychat/middleware.js b/client/state/happychat/middleware.js index c6761d0ee8fcfb..63c077be2c3d72 100644 --- a/client/state/happychat/middleware.js +++ b/client/state/happychat/middleware.js @@ -64,6 +64,7 @@ import { getCurrentUser, getCurrentUserLocale, } from 'state/current-user/selectors'; +import { getHelpSelectedSite } from 'state/help/selectors'; const debug = require( 'debug' )( 'calypso:happychat:actions' ); @@ -99,9 +100,10 @@ export const connectChat = ( connection, { getState, dispatch } ) => { return; } + const selectedSite = getHelpSelectedSite( state ); const user = getCurrentUser( state ); const locale = getCurrentUserLocale( state ); - const groups = getGroups( state ); + const groups = getGroups( state, selectedSite.ID ); // Notify that a new connection is being established dispatch( setConnecting() ); @@ -136,7 +138,6 @@ export const connectChat = ( connection, { getState, dispatch } ) => { .catch( e => debug( 'failed to start happychat session', e, e.stack ) ); }; - export const updateChatPreferences = ( connection, { getState }, siteId ) => { const state = getState(); diff --git a/client/state/help/selectors.js b/client/state/help/selectors.js index b9933657f01883..8b339b8ad44bd9 100644 --- a/client/state/help/selectors.js +++ b/client/state/help/selectors.js @@ -1,8 +1,16 @@ /** * Internal dependencies */ +import { getSelectedOrPrimarySiteId } from 'state/selectors'; +import { getSite } from 'state/sites/selectors'; import createSelector from 'lib/create-selector'; export const getHelpSelectedSiteId = createSelector( state => state.help.selectedSiteId ); + +export const getHelpSelectedSite = ( state ) => { + const siteId = getHelpSelectedSiteId( state ) || getSelectedOrPrimarySiteId( state ); + + return getSite( state, siteId ); +};