Skip to content

Commit

Permalink
Add modal close event for form submission
Browse files Browse the repository at this point in the history
  • Loading branch information
dognose24 committed Sep 16, 2024
1 parent 019a939 commit 740eade
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
8 changes: 6 additions & 2 deletions client/my-sites/stats/feedback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,14 @@ function StatsFeedbackController( { siteId }: FeedbackProps ) {
}
};

const onModalClose = () => {
const onModalClose = ( isAfterSubmission: boolean ) => {
setIsOpen( false );

trackStatsAnalyticsEvent( 'stats_feedback_action_close_form_modal' );
if ( isAfterSubmission ) {
trackStatsAnalyticsEvent( 'stats_feedback_action_close_form_modal_after_submission' );
} else {
trackStatsAnalyticsEvent( 'stats_feedback_action_close_form_modal' );
}
};

if ( ! supportCommercialUse ) {
Expand Down
31 changes: 21 additions & 10 deletions client/my-sites/stats/feedback/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import './style.scss';

interface ModalProps {
siteId: number;
onClose: () => void;
onClose: ( isAfterSubmission: boolean ) => void;
}

const FEEDBACK_SHOULD_SHOW_PANEL_API_KEY = NOTICES_KEY_SHOW_FLOATING_USER_FEEDBACK_PANEL;
Expand Down Expand Up @@ -53,11 +53,14 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
const { isSubmittingFeedback, submitFeedback, isSubmissionSuccessful } =
useSubmitProductFeedback( siteId );

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

const onFormSubmit = useCallback( () => {
if ( ! content ) {
Expand All @@ -75,7 +78,7 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
feedback: content,
is_testing: false,
} );
}, [ dispatch, content, submitFeedback ] );
}, [ content, submitFeedback ] );

useEffect( () => {
if ( isSubmissionSuccessful ) {
Expand All @@ -91,7 +94,7 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
refetchNotices();
} );

handleClose();
handleClose( true );
}
}, [
dispatch,
Expand All @@ -104,10 +107,18 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
] );

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

0 comments on commit 740eade

Please sign in to comment.