Use API for eligibility check

Summary: Change flipper from using the dodgy webview check that requires auth, to using the interngraph api for eligibility checking.

Reviewed By: passy

Differential Revision: D17498724

fbshipit-source-id: b81fd8b7b0bd36a7fcf73ba05d9885b61e420c61
This commit is contained in:
John Knox
2019-09-23 06:41:57 -07:00
committed by Facebook Github Bot
parent 4e5ede6d37
commit e871822a05
2 changed files with 14 additions and 29 deletions

View File

@@ -20,8 +20,6 @@ import GK from '../fb-stubs/GK';
import * as UserFeedback from '../fb-stubs/UserFeedback';
import {FeedbackPrompt} from '../fb-stubs/UserFeedback';
const useEligibilityCheck = GK.get('flipper_use_itsr_eligibility_check');
type Props = {
onRatingChanged: (rating: number) => void;
};
@@ -29,7 +27,6 @@ type Props = {
type State = {
promptData: FeedbackPrompt | null;
isShown: boolean;
userIsEligible: boolean;
hasTriggered: boolean;
};
@@ -254,24 +251,26 @@ class FeedbackComponent extends Component<
}
export default class RatingButton extends Component<Props, State> {
state = {
state: State = {
promptData: null,
isShown: false,
userIsEligible: !useEligibilityCheck,
hasTriggered: false,
};
constructor(props: Props) {
super(props);
UserFeedback.getPrompt().then(prompt =>
this.setState({promptData: prompt}),
);
if (GK.get('flipper_rating')) {
UserFeedback.getPrompt().then(prompt => {
this.setState({promptData: prompt});
setTimeout(this.triggerPopover.bind(this), 30000);
});
}
}
onClick() {
const willBeShown = !this.state.isShown;
this.setState({isShown: willBeShown, hasTriggered: true});
if (!willBeShown && useEligibilityCheck) {
if (!willBeShown) {
UserFeedback.dismiss();
}
}
@@ -300,28 +299,17 @@ export default class RatingButton extends Component<Props, State> {
}
}
setIsEligible(isEligible: boolean) {
this.setState({userIsEligible: isEligible});
if (isEligible) {
setTimeout(this.triggerPopover.bind(this), 30000);
}
}
render() {
if (!GK.get('flipper_rating')) {
return null;
}
if (!this.state.userIsEligible) {
return (
<UserFeedback.StarRatingsEligibilityChecker
callback={this.setIsEligible.bind(this)}
/>
);
}
const promptData = this.state.promptData;
if (!promptData) {
return null;
}
if (
!promptData.shouldPopup ||
(this.state.hasTriggered && !this.state.isShown)
) {
return null;
}
return (
<div style={{position: 'relative'}}>
<div onClick={this.onClick.bind(this)}>

View File

@@ -33,6 +33,3 @@ export async function dismiss(): Promise<void> {
export async function getPrompt(): Promise<FeedbackPrompt> {
throw new Error('Method not implemented.');
}
export class StarRatingsEligibilityChecker extends Component<{
callback: (userIsEligible: boolean) => void;
}> {}