Skip to content

Commit

Permalink
Stats: Add modal close event for form submission (#94574)
Browse files Browse the repository at this point in the history
* Add modal close event for form submission

* Add event stats_feedback_action_directly_close_form_modal only
  • Loading branch information
dognose24 authored Sep 20, 2024
1 parent 31c9dec commit ff7cc13
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
2 changes: 0 additions & 2 deletions client/my-sites/stats/feedback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ function StatsFeedbackController( { siteId }: FeedbackProps ) {

const onModalClose = () => {
setIsOpen( false );

trackStatsAnalyticsEvent( 'stats_feedback_action_close_form_modal' );
};

if ( ! supportCommercialUse ) {
Expand Down
39 changes: 27 additions & 12 deletions client/my-sites/stats/feedback/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,36 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
const { isSubmittingFeedback, submitFeedback, isSubmissionSuccessful } =
useSubmitProductFeedback( siteId );

const handleClose = useCallback( () => {
setTimeout( () => {
onClose();
}, 200 );
}, [ onClose ] );
const handleClose = useCallback(
( isDirectClose: boolean = false ) => {
setTimeout( () => {
onClose();

if ( isDirectClose ) {
trackStatsAnalyticsEvent( 'stats_feedback_action_directly_close_form_modal' );
}
}, 200 );
},
[ onClose ]
);

const onFormSubmit = useCallback( () => {
if ( ! content ) {
return;
}

trackStatsAnalyticsEvent( 'stats_feedback_action_submit_form', {
feedback: content,
} );

const sourceUrl = `${ window.location.origin }${ window.location.pathname }`;
submitFeedback( {
source_url: sourceUrl,
product_name: 'Jetpack Stats',
feedback: content,
is_testing: false,
} );
}, [ dispatch, content, submitFeedback ] );

trackStatsAnalyticsEvent( 'stats_feedback_action_submit_form', {
feedback: content,
} );
}, [ content, submitFeedback ] );

useEffect( () => {
if ( isSubmissionSuccessful ) {
Expand Down Expand Up @@ -104,10 +111,18 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
] );

return (
<Modal className="stats-feedback-modal" onRequestClose={ handleClose } __experimentalHideHeader>
<Modal
className="stats-feedback-modal"
onRequestClose={ () => {
handleClose( true );
} }
__experimentalHideHeader
>
<Button
className="stats-feedback-modal__close-button"
onClick={ handleClose }
onClick={ () => {
handleClose( true );
} }
icon={ close }
label={ translate( 'Close' ) }
/>
Expand Down

0 comments on commit ff7cc13

Please sign in to comment.