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

Happychat: Rework selected site logic to send proper site info to happychat and kayako #15013

Merged
merged 3 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 3 additions & 10 deletions client/me/help/help-contact-form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ 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';

export const HelpContactForm = React.createClass( {
Expand All @@ -38,6 +36,7 @@ export const HelpContactForm = React.createClass( {
showSubjectField: PropTypes.bool,
showSiteField: PropTypes.bool,
showHelpLanguagePrompt: PropTypes.bool,
selectedSite: PropTypes.object,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're only using the ID can we just pass selectedSiteId instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that if we ever need any other site details in the future they'll be there, I guess I could just send the id for now and we could rework it later.

siteFilter: PropTypes.func,
siteList: PropTypes.object,
disabled: PropTypes.bool,
Expand Down Expand Up @@ -224,7 +223,7 @@ export const HelpContactForm = React.createClass( {
<div className="help-contact-form__site-selection">
<FormLabel>{ translate( 'Which site do you need help with?' ) }</FormLabel>
<SitesDropdown
selectedSiteId={ this.props.selectedSiteId }
selectedSiteId={ this.props.selectedSite.ID }
onSiteSelect={ this.props.onChangeSite } />
</div>
) }
Expand All @@ -250,14 +249,8 @@ export const HelpContactForm = React.createClass( {
}
} );

const mapStateToProps = ( state ) => {
return {
selectedSiteId: getHelpSelectedSiteId( state ) || getSelectedOrPrimarySiteId( state )
};
};

const mapDispatchToProps = {
onChangeSite: selectSiteId
};

export default connect( mapStateToProps, mapDispatchToProps )( localize( HelpContactForm ) );
export default connect( null, mapDispatchToProps )( localize( HelpContactForm ) );
18 changes: 10 additions & 8 deletions client/me/help/help-contact/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import QueryTicketSupportConfiguration from 'components/data/query-ticket-suppor
import HelpUnverifiedWarning from '../help-unverified-warning';
import { sendChatMessage as sendHappychatMessage, sendUserInfo } from 'state/happychat/actions';
import { openChat as openHappychat } from 'state/ui/happychat/actions';
import { getHelpSelectedSite } from 'state/help/selectors';
import { getCurrentUser, getCurrentUserLocale } from 'state/current-user/selectors';
import { askQuestion as askDirectlyQuestion, initialize as initializeDirectly } from 'state/help/directly/actions';
import {
Expand Down Expand Up @@ -132,8 +133,8 @@ const HelpContact = React.createClass( {

startHappychat: function( contactForm ) {
this.props.openHappychat();
const { message, siteId } = contactForm;
const site = sites.getSite( siteId );
const { message } = contactForm;
const { selectedSite: site } = this.props;

this.props.sendUserInfo( site.URL );
this.props.sendHappychatMessage( message );
Expand All @@ -147,8 +148,8 @@ const HelpContact = React.createClass( {
},

startChat: function( contactForm ) {
const { message, howCanWeHelp, howYouFeel, siteId } = contactForm;
const site = sites.getSite( siteId );
const { message, howCanWeHelp, howYouFeel } = contactForm;
const { selectedSite: site } = this.props;

// Intentionally not translated since only HE's will see this in the olark console as a notification.
const notifications = [
Expand Down Expand Up @@ -194,9 +195,8 @@ const HelpContact = React.createClass( {
},

submitKayakoTicket: function( contactForm ) {
const { subject, message, howCanWeHelp, howYouFeel, siteId } = contactForm;
const { currentUserLocale } = this.props;
const site = sites.getSite( siteId );
const { subject, message, howCanWeHelp, howYouFeel } = contactForm;
const { currentUserLocale, selectedSite: site } = this.props;

const ticketMeta = [
'How can you help: ' + howCanWeHelp,
Expand Down Expand Up @@ -537,7 +537,7 @@ const HelpContact = React.createClass( {

getContactFormCommonProps: function( variationSlug ) {
const { isSubmitting } = this.state;
const { currentUserLocale } = this.props;
const { currentUserLocale, selectedSite } = this.props;

// Let the user know we only offer support in English.
// We only need to show the message if:
Expand All @@ -552,6 +552,7 @@ const HelpContact = React.createClass( {
return {
disabled: isSubmitting,
showHelpLanguagePrompt: showHelpLanguagePrompt,
selectedSite: selectedSite,
valueLink: { value: savedContactForm, requestChange: ( contactForm ) => savedContactForm = contactForm }
};
},
Expand Down Expand Up @@ -697,6 +698,7 @@ export default connect(
ticketSupportConfigurationReady: isTicketSupportConfigurationReady( state ),
ticketSupportEligible: isTicketSupportEligible( state ),
ticketSupportRequestError: getTicketSupportRequestError( state ),
selectedSite: getHelpSelectedSite( state ),
};
},
{
Expand Down
8 changes: 8 additions & 0 deletions client/state/help/selectors.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
/**
* Internal dependencies
*/
import { getPrimarySiteId } from 'state/selectors';
import { getRawSite } 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 ) || getPrimarySiteId( state );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be using getSelectedOrPrimarySiteId here instead of getPrimarySiteId. Without the form will always default to the users primary site instead of the site they currently have selected

Copy link
Contributor Author

@unDemian unDemian Jun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I didn't notice that it was added. Updated, thanks.


return getRawSite( state, siteId );
};