Skip to content

Commit

Permalink
Merge pull request #1085 from Automattic/update/unpaid-help-contact
Browse files Browse the repository at this point in the history
Help: Handle chat ineligible users with the support forums
  • Loading branch information
omarjackman committed Dec 3, 2015
2 parents 855fc89 + dfa333f commit 87a2855
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 20 deletions.
28 changes: 16 additions & 12 deletions client/me/help/help-contact-form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = React.createClass( {
mixins: [ React.addons.LinkedStateMixin, React.addons.PureRenderMixin ],

propTypes: {
formDescription: React.PropTypes.node,
buttonLabel: React.PropTypes.string.isRequired,
onSubmit: React.PropTypes.func.isRequired,
showHowCanWeHelpField: React.PropTypes.bool,
Expand All @@ -35,6 +36,7 @@ module.exports = React.createClass( {

getDefaultProps: function() {
return {
formDescription: '',
showHowCanWeHelpField: false,
showHowYouFeelField: false,
showSubjectField: false,
Expand Down Expand Up @@ -137,9 +139,9 @@ module.exports = React.createClass( {
*/
render: function() {
var howCanWeHelpOptions = [
{ value: 'gettingStarted', label: this.translate( 'Help getting started' ), subtext: this.translate( 'Can you show me how to...' ) },
{ value: 'somethingBroken', label: this.translate( 'Something is broken' ), subtext: this.translate( 'Can you check this out...' ) },
{ value: 'suggestion', label: this.translate( 'I have a suggestion' ), subtext: this.translate( 'I think it would be cool if...' ) }
{ value: 'gettingStarted', label: this.translate( 'Help getting started' ), subtext: this.translate( 'Can you show me how to' ) },
{ value: 'somethingBroken', label: this.translate( 'Something is broken' ), subtext: this.translate( 'Can you check this out' ) },
{ value: 'suggestion', label: this.translate( 'I have a suggestion' ), subtext: this.translate( 'I think it would be cool if' ) }
],
howYouFeelOptions = [
{ value: 'unspecified', label: this.translate( "I'd rather not" ) },
Expand All @@ -150,25 +152,27 @@ module.exports = React.createClass( {
{ value: 'panicked', label: this.translate( 'Panicked' ) }
];

const { buttonLabel, showHowCanWeHelpField, showHowYouFeelField, showSubjectField, showSiteField, siteList, siteFilter } = this.props;
const { formDescription, buttonLabel, showHowCanWeHelpField, showHowYouFeelField, showSubjectField, showSiteField, siteList, siteFilter } = this.props;

return (
<div className="help-contact-form">
{ showHowCanWeHelpField ? (
{ formDescription && ( <p>{ formDescription }</p> ) }

{ showHowCanWeHelpField && (
<div>
<FormLabel>{ this.translate( 'How can we help?' ) }</FormLabel>
{ this.renderFormSelection( 'howCanWeHelp', howCanWeHelpOptions ) }
</div>
) : null }
) }

{ showHowYouFeelField ? (
{ showHowYouFeelField && (
<div>
<FormLabel>{ this.translate( 'Mind sharing how you feel?' ) }</FormLabel>
{ this.renderFormSelection( 'howYouFeel', howYouFeelOptions ) }
</div>
) : null }
) }

{ showSiteField ? (
{ showSiteField && (
<div>
<FormLabel>{ this.translate( 'Which site do you need help with?' ) }</FormLabel>
<SelectSite
Expand All @@ -178,14 +182,14 @@ module.exports = React.createClass( {
value={ this.state.site.ID }
onChange={ this.setSite } />
</div>
) : null }
) }

{ showSubjectField ? (
{ showSubjectField && (
<div className="help-contact-form__subject">
<FormLabel>{ this.translate( 'Subject' ) }</FormLabel>
<FormTextInput valueLink={ this.linkState( 'subject' ) } />
</div>
) : null }
) }

<FormLabel>{ this.translate( 'What are you trying to do?' ) }</FormLabel>
<FormTextarea valueLink={ this.linkState( 'message' ) } placeholder={ this.translate( 'Please be descriptive' ) }></FormTextarea>
Expand Down
81 changes: 73 additions & 8 deletions client/me/help/help-contact/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const noticeOptions = {
duration: 10000,
showDismiss: false
};

const wpcom = wpcomLib.undocumented();
const sites = siteList();

Expand Down Expand Up @@ -68,7 +67,7 @@ module.exports = React.createClass( {
return {
olark: olarkStore.get(),
isSubmitting: false,
confirmationMessage: null,
confirmation: null,
sitesInitialized: sites.initialized
};
},
Expand Down Expand Up @@ -124,7 +123,44 @@ module.exports = React.createClass( {

this.setState( {
isSubmitting: false,
confirmationMessage: this.translate( "We've received your message, and you'll hear back from one of our Happiness Engineers shortly." )
confirmation: {
title: this.translate( 'We\'re on it!' ),
message: this.translate(
'We\'ve received your message, and you\'ll hear back from ' +
'one of our Happiness Engineers shortly.' )
}
} );
} );
},

submitSupportForumsTopic: function( contactForm ) {
const { subject, message } = contactForm;

this.setState( { isSubmitting: true } );

wpcom.submitSupportForumsTopic( subject, message, ( error, data ) => {
if ( error ) {
// TODO: bump a stat here
notices.error( error.message );

this.setState( { isSubmitting: false } );
return;
}

this.setState( {
isSubmitting: false,
confirmation: {
title: this.translate( 'Got it!' ),
message: this.translate(
'Your message has been submitted to our ' +
'{{a}}community forums{{/a}}',
{
components: {
a: <a href={ data.topic_URL } />
}
}
)
}
} );
} );
},
Expand Down Expand Up @@ -230,15 +266,40 @@ module.exports = React.createClass( {
return site.visible && ! site.jetpack;
},

getPublicForumsForm: function() {
const { isSubmitting } = this.state;
const formDescription = this.translate(
'Post a new question in our {{strong}}public forums{{/strong}}, ' +
'where it may be answered by helpful community members, ' +
'by submitting the form below. ' +
'{{strong}}Please do not{{/strong}} provide financial or ' +
'contact information when submitting this form.',
{
components: {
strong: <strong />
}
}
);

return (
<HelpContactForm
onSubmit={ this.submitSupportForumsTopic }
formDescription={ formDescription }
buttonLabel={ isSubmitting ? this.translate( 'Asking in the forums' ) : this.translate( 'Ask in the forums' ) }
showSubjectField={ true }
disabled={ isSubmitting }/>
);
},

/**
* Get the view for the contact page. This could either be the olark chat widget if a chat is in progress or a contact form.
* @return {object} A JSX object that should be rendered
*/
getView: function() {
const { olark, confirmationMessage, sitesInitialized } = this.state;
const { olark, confirmation, sitesInitialized } = this.state;

if ( confirmationMessage ) {
return <HelpContactConfirmation title={ this.translate( "We're on it!" ) } message={ confirmationMessage }/>;
if ( confirmation ) {
return <HelpContactConfirmation { ...confirmation } />;
}

if ( ! ( olark.isOlarkReady && sitesInitialized ) ) {
Expand All @@ -249,11 +310,15 @@ module.exports = React.createClass( {
return <OlarkChatbox />;
}

if ( olark.isOperatorAvailable ) {
if ( olark.isUserEligible && olark.isOperatorAvailable ) {
return this.getChatForm();
}

return this.getKayakoTicketForm();
if ( olark.isUserEligible || olark.details.isConversing ) {
return this.getKayakoTicketForm();
}

return this.getPublicForumsForm();
},

render: function() {
Expand Down
7 changes: 7 additions & 0 deletions shared/lib/wpcom-undocumented/lib/undocumented.js
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,13 @@ Undocumented.prototype.getOlarkConfiguration = function( fn ) {
}, fn );
};

Undocumented.prototype.submitSupportForumsTopic = function( subject, message, fn ) {
this.wpcom.req.post( {
path: '/help/forums/support/topics/new',
body: { subject, message }
}, fn );
};

/**
* Expose `Undocumented` module
*/
Expand Down

0 comments on commit 87a2855

Please sign in to comment.