@@ -11,7 +11,6 @@ import { FeedbackForm } from "./FeedbackForm";
1111import styles from "./index.css?inline" ;
1212import { RadialProgress } from "./RadialProgress" ;
1313import {
14- FeedbackScoreSubmission ,
1514 FeedbackSubmission ,
1615 OpenFeedbackFormOptions ,
1716 WithRequired ,
@@ -25,26 +24,19 @@ export type FeedbackDialogProps = WithRequired<
2524const INACTIVE_DURATION_MS = 20 * 1000 ;
2625const SUCCESS_DURATION_MS = 3 * 1000 ;
2726
27+ export type FormState = "idle" | "submitting" | "submitted" | "error" ;
28+
2829export const FeedbackDialog : FunctionComponent < FeedbackDialogProps > = ( {
2930 key,
3031 title = DEFAULT_TRANSLATIONS . DefaultQuestionLabel ,
3132 position,
3233 translations = DEFAULT_TRANSLATIONS ,
33- openWithCommentVisible = false ,
34- requireSatisfactionScore = true ,
34+ inputMode = "comment-and-score" ,
3535 onClose,
3636 onDismiss,
3737 onSubmit,
38- onScoreSubmit,
3938} ) => {
40- // If requireSatisfactionScore is false, always show comment field
41- const effectiveOpenWithCommentVisible =
42- requireSatisfactionScore === false ? true : openWithCommentVisible ;
43-
44- const [ feedbackId , setFeedbackId ] = useState < string | undefined > ( undefined ) ;
45- const [ scoreState , setScoreState ] = useState <
46- "idle" | "submitting" | "submitted"
47- > ( "idle" ) ;
39+ const [ formState , setFormState ] = useState < FormState > ( "idle" ) ;
4840
4941 const { isOpen, close } = useDialog ( { onClose, initialValue : true } ) ;
5042
@@ -56,24 +48,21 @@ export const FeedbackDialog: FunctionComponent<FeedbackDialogProps> = ({
5648
5749 const submit = useCallback (
5850 async ( data : Omit < FeedbackSubmission , "feedbackId" > ) => {
59- await onSubmit ( { ...data , feedbackId } ) ;
60- autoClose . startWithDuration ( SUCCESS_DURATION_MS ) ;
61- } ,
62- [ autoClose , feedbackId , onSubmit ] ,
63- ) ;
64-
65- const submitScore = useCallback (
66- async ( data : Omit < FeedbackScoreSubmission , "feedbackId" > ) => {
67- if ( onScoreSubmit !== undefined ) {
68- setScoreState ( "submitting" ) ;
69-
70- const res = await onScoreSubmit ( { ...data , feedbackId } ) ;
71- setFeedbackId ( res . feedbackId ) ;
72- setScoreState ( "submitted" ) ;
51+ try {
52+ setFormState ( "submitting" ) ;
53+ const res = await onSubmit ( { ...data } ) ;
54+ if ( ! res ) throw new Error ( "Failed to submit feedback" ) ;
55+ setFormState ( "submitted" ) ;
56+ autoClose . startWithDuration ( SUCCESS_DURATION_MS ) ;
57+ } catch ( error ) {
58+ setFormState ( "error" ) ;
59+ console . error ( "Couldn't submit feedback with Reflag:" , error ) ;
60+ throw error ;
7361 }
7462 } ,
75- [ feedbackId , onScoreSubmit ] ,
63+ [ autoClose , onSubmit ] ,
7664 ) ;
65+
7766 const dismiss = useCallback ( ( ) => {
7867 autoClose . stop ( ) ;
7968 close ( ) ;
@@ -94,14 +83,12 @@ export const FeedbackDialog: FunctionComponent<FeedbackDialogProps> = ({
9483 < >
9584 < FeedbackForm
9685 key = { key }
97- openWithCommentVisible = { effectiveOpenWithCommentVisible }
86+ inputMode = { inputMode }
9887 question = { title }
99- requireSatisfactionScore = { requireSatisfactionScore }
100- scoreState = { scoreState }
10188 t = { { ...DEFAULT_TRANSLATIONS , ...translations } }
10289 onInteraction = { autoClose . stop }
103- onScoreSubmit = { submitScore }
10490 onSubmit = { submit }
91+ formState = { formState }
10592 />
10693
10794 < button class = "close" onClick = { dismiss } >
@@ -111,7 +98,7 @@ export const FeedbackDialog: FunctionComponent<FeedbackDialogProps> = ({
11198 progress = { 1.0 - autoClose . elapsedFraction }
11299 />
113100 ) }
114- < Close />
101+ < Close width = { 18 } height = { 18 } />
115102 </ button >
116103 </ >
117104 </ Dialog >
0 commit comments