Proactively ask users for feedback based on ITSREligibilityCheck

Summary:
Gets the rating popover to appear automatically after 30s for selected users, according to ITSR constraints.

The ITSR constraints are to stop it annoying people, such as only happening once a month, and global throttling.

Reviewed By: passy

Differential Revision: D17343435

fbshipit-source-id: c06aa10263a64249f7e2c48b8752c37e4314ac24
This commit is contained in:
John Knox
2019-09-12 08:19:45 -07:00
committed by Facebook Github Bot
parent d3be6357ef
commit 9ee487cf43

View File

@@ -30,6 +30,7 @@ type State = {
promptData: FeedbackPrompt | null; promptData: FeedbackPrompt | null;
isShown: boolean; isShown: boolean;
userIsEligible: boolean; userIsEligible: boolean;
hasTriggered: boolean;
}; };
type NextAction = 'select-rating' | 'leave-comment' | 'finished'; type NextAction = 'select-rating' | 'leave-comment' | 'finished';
@@ -257,6 +258,7 @@ export default class RatingButton extends Component<Props, State> {
promptData: null, promptData: null,
isShown: false, isShown: false,
userIsEligible: !useEligibilityCheck, userIsEligible: !useEligibilityCheck,
hasTriggered: false,
}; };
constructor(props: Props) { constructor(props: Props) {
@@ -268,7 +270,7 @@ export default class RatingButton extends Component<Props, State> {
onClick() { onClick() {
const willBeShown = !this.state.isShown; const willBeShown = !this.state.isShown;
this.setState({isShown: willBeShown}); this.setState({isShown: willBeShown, hasTriggered: true});
if (!willBeShown && useEligibilityCheck) { if (!willBeShown && useEligibilityCheck) {
UserFeedback.dismiss(); UserFeedback.dismiss();
} }
@@ -292,6 +294,19 @@ export default class RatingButton extends Component<Props, State> {
); );
} }
triggerPopover() {
if (!this.state.hasTriggered) {
this.setState({isShown: true, hasTriggered: true});
}
}
setIsEligible(isEligible: boolean) {
this.setState({userIsEligible: isEligible});
if (isEligible) {
setTimeout(this.triggerPopover.bind(this), 30000);
}
}
render() { render() {
if (!GK.get('flipper_rating')) { if (!GK.get('flipper_rating')) {
return null; return null;
@@ -299,7 +314,7 @@ export default class RatingButton extends Component<Props, State> {
if (!this.state.userIsEligible) { if (!this.state.userIsEligible) {
return ( return (
<UserFeedback.StarRatingsEligibilityChecker <UserFeedback.StarRatingsEligibilityChecker
callback={isEligible => this.setState({userIsEligible: isEligible})} callback={this.setIsEligible.bind(this)}
/> />
); );
} }