Use API to get prompt values
Summary: To keep it in sync with the JS implementation. Reviewed By: danielbuechele Differential Revision: D17208786 fbshipit-source-id: 8d89f33bfef22317266a0ad1e0c5689540d54f9e
This commit is contained in:
committed by
Facebook Github Bot
parent
612cfd81ae
commit
be22cc711a
@@ -9,17 +9,33 @@ import React, {Component, ReactElement} from 'react';
|
|||||||
import {Glyph, Popover, FlexColumn, FlexRow, Button, Checkbox} from 'flipper';
|
import {Glyph, Popover, FlexColumn, FlexRow, Button, Checkbox} from 'flipper';
|
||||||
import GK from '../fb-stubs/GK';
|
import GK from '../fb-stubs/GK';
|
||||||
import * as UserFeedback from '../fb-stubs/UserFeedback';
|
import * as UserFeedback from '../fb-stubs/UserFeedback';
|
||||||
|
import {FeedbackPrompt} from '../fb-stubs/UserFeedback';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onRatingChanged: (rating: number) => void;
|
onRatingChanged: (rating: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
|
promptData: FeedbackPrompt | null;
|
||||||
isShown: boolean;
|
isShown: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type NextAction = 'select-rating' | 'leave-comment' | 'finished';
|
type NextAction = 'select-rating' | 'leave-comment' | 'finished';
|
||||||
|
|
||||||
|
class PredefinedComment extends Component<{
|
||||||
|
comment: string;
|
||||||
|
selected: boolean;
|
||||||
|
onClick: (_: unknown) => unknown;
|
||||||
|
}> {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div onClick={this.props.onClick}>
|
||||||
|
{this.props.comment + (this.props.selected ? ' - Y' : ' - N')}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class FeedbackComponent extends Component<
|
class FeedbackComponent extends Component<
|
||||||
{
|
{
|
||||||
submitRating: (rating: number) => void;
|
submitRating: (rating: number) => void;
|
||||||
@@ -30,6 +46,7 @@ class FeedbackComponent extends Component<
|
|||||||
allowUserInfoSharing: boolean,
|
allowUserInfoSharing: boolean,
|
||||||
) => void;
|
) => void;
|
||||||
close(): void;
|
close(): void;
|
||||||
|
promptData: FeedbackPrompt;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rating: number | null;
|
rating: number | null;
|
||||||
@@ -44,7 +61,10 @@ class FeedbackComponent extends Component<
|
|||||||
hoveredRating: 0,
|
hoveredRating: 0,
|
||||||
allowUserInfoSharing: true,
|
allowUserInfoSharing: true,
|
||||||
nextAction: 'select-rating' as NextAction,
|
nextAction: 'select-rating' as NextAction,
|
||||||
predefinedComments: {'Too slow': false, Rubbish: false},
|
predefinedComments: this.props.promptData.predefinedComments.reduce(
|
||||||
|
(acc, cv) => ({...acc, [cv]: false}),
|
||||||
|
{},
|
||||||
|
),
|
||||||
};
|
};
|
||||||
onSubmitRating(newRating: number) {
|
onSubmitRating(newRating: number) {
|
||||||
const nextAction = newRating <= 2 ? 'leave-comment' : 'finished';
|
const nextAction = newRating <= 2 ? 'leave-comment' : 'finished';
|
||||||
@@ -112,22 +132,36 @@ class FeedbackComponent extends Component<
|
|||||||
switch (this.state.nextAction) {
|
switch (this.state.nextAction) {
|
||||||
case 'select-rating':
|
case 'select-rating':
|
||||||
body = [
|
body = [
|
||||||
<FlexRow>
|
<FlexRow>{this.props.promptData.bodyText}</FlexRow>,
|
||||||
How would you rate your overall satisfaction with Flipper?
|
|
||||||
</FlexRow>,
|
|
||||||
<FlexRow>{stars}</FlexRow>,
|
<FlexRow>{stars}</FlexRow>,
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 'leave-comment':
|
case 'leave-comment':
|
||||||
|
const predefinedComments = Object.entries(
|
||||||
|
this.state.predefinedComments,
|
||||||
|
).map((c: [string, unknown]) => (
|
||||||
|
<PredefinedComment
|
||||||
|
comment={c[0]}
|
||||||
|
selected={Boolean(c[1])}
|
||||||
|
onClick={() =>
|
||||||
|
this.setState({
|
||||||
|
predefinedComments: {
|
||||||
|
...this.state.predefinedComments,
|
||||||
|
[c[0]]: !c[1],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
));
|
||||||
body = [
|
body = [
|
||||||
<FlexRow>Predefined comment buttons here...</FlexRow>,
|
<FlexRow>{predefinedComments}</FlexRow>,
|
||||||
<FlexRow>Comment input box here...</FlexRow>,
|
<FlexRow>{this.props.promptData.commentPlaceholder}</FlexRow>,
|
||||||
<FlexRow>
|
<FlexRow>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={this.state.allowUserInfoSharing}
|
checked={this.state.allowUserInfoSharing}
|
||||||
onChange={this.onAllowUserSharingChanged.bind(this)}
|
onChange={this.onAllowUserSharingChanged.bind(this)}
|
||||||
/>
|
/>
|
||||||
Can contact me.{' '}
|
{'Tool owner can contact me '}
|
||||||
<Button onClick={() => this.onCommentSubmitted('some comment')}>
|
<Button onClick={() => this.onCommentSubmitted('some comment')}>
|
||||||
Submit
|
Submit
|
||||||
</Button>
|
</Button>
|
||||||
@@ -146,8 +180,8 @@ class FeedbackComponent extends Component<
|
|||||||
<FlexColumn>
|
<FlexColumn>
|
||||||
<FlexRow>
|
<FlexRow>
|
||||||
{this.state.nextAction === 'finished'
|
{this.state.nextAction === 'finished'
|
||||||
? 'Feedback Received'
|
? this.props.promptData.postSubmitHeading
|
||||||
: "We'd love your feedback"}
|
: this.props.promptData.preSubmitHeading}
|
||||||
</FlexRow>
|
</FlexRow>
|
||||||
{body}
|
{body}
|
||||||
</FlexColumn>
|
</FlexColumn>
|
||||||
@@ -157,9 +191,17 @@ class FeedbackComponent extends Component<
|
|||||||
|
|
||||||
export default class RatingButton extends Component<Props, State> {
|
export default class RatingButton extends Component<Props, State> {
|
||||||
state = {
|
state = {
|
||||||
|
promptData: null,
|
||||||
isShown: false,
|
isShown: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
UserFeedback.getPrompt().then(prompt =>
|
||||||
|
this.setState({promptData: prompt}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
onClick() {
|
onClick() {
|
||||||
this.setState({isShown: !this.state.isShown});
|
this.setState({isShown: !this.state.isShown});
|
||||||
}
|
}
|
||||||
@@ -186,6 +228,10 @@ export default class RatingButton extends Component<Props, State> {
|
|||||||
if (!GK.get('flipper_rating')) {
|
if (!GK.get('flipper_rating')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
const promptData = this.state.promptData;
|
||||||
|
if (!promptData) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const stars = (
|
const stars = (
|
||||||
<div onClick={this.onClick.bind(this)}>
|
<div onClick={this.onClick.bind(this)}>
|
||||||
<Glyph
|
<Glyph
|
||||||
@@ -207,6 +253,7 @@ export default class RatingButton extends Component<Props, State> {
|
|||||||
close={() => {
|
close={() => {
|
||||||
this.setState({isShown: false});
|
this.setState({isShown: false});
|
||||||
}}
|
}}
|
||||||
|
promptData={promptData}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ export type FeedbackPrompt = {
|
|||||||
postSubmitHeading: string;
|
postSubmitHeading: string;
|
||||||
commentPlaceholder: string;
|
commentPlaceholder: string;
|
||||||
bodyText: string;
|
bodyText: string;
|
||||||
|
predefinedComments: Array<string>;
|
||||||
|
shouldPopup: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function submitRating(rating: number): Promise<void> {
|
export async function submitRating(rating: number): Promise<void> {
|
||||||
@@ -26,6 +28,3 @@ export async function submitComment(
|
|||||||
export async function getPrompt(): Promise<FeedbackPrompt> {
|
export async function getPrompt(): Promise<FeedbackPrompt> {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
export async function shouldShowPrompt(): Promise<boolean> {
|
|
||||||
throw new Error('Method not implemented.');
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user