Skip to content

Commit

Permalink
Stats: Update hibernation value on feedback submission (#94398)
Browse files Browse the repository at this point in the history
* Update hibernation period on successful submission
* Update hibernation value on panel dismissal
  • Loading branch information
a8ck3n authored Sep 12, 2024
1 parent e8a07cb commit 57688b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 1 addition & 4 deletions client/my-sites/stats/feedback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ const FEEDBACK_PANEL_PRESENTATION_DELAY = 3000;
const FEEDBACK_LEAVE_REVIEW_URL = 'https://wordpress.org/support/plugin/jetpack/reviews/';

const FEEDBACK_SHOULD_SHOW_PANEL_API_KEY = NOTICES_KEY_SHOW_FLOATING_USER_FEEDBACK_PANEL;
const FEEDBACK_SHOULD_SHOW_PANEL_API_HIBERNATION_DELAY = 30; // 30 seconds for now
// Examples values:
// 30 minutes = 60 * 30;
// 30 days = 3600 * 24 * 30;
const FEEDBACK_SHOULD_SHOW_PANEL_API_HIBERNATION_DELAY = 3600 * 24 * 30 * 6; // 6 months

function useNoticeVisibilityHooks( siteId: number ) {
const { data: shouldShowFeedbackPanel, refetch } = useNoticeVisibilityQuery(
Expand Down
17 changes: 15 additions & 2 deletions client/my-sites/stats/feedback/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import StatsButton from 'calypso/my-sites/stats/components/stats-button';
import useNoticeVisibilityMutation from 'calypso/my-sites/stats/hooks/use-notice-visibility-mutation';
import {
NOTICES_KEY_ABLE_TO_SUBMIT_FEEDBACK,
NOTICES_KEY_SHOW_FLOATING_USER_FEEDBACK_PANEL,
useNoticeVisibilityQuery,
} from 'calypso/my-sites/stats/hooks/use-notice-visibility-query';
import { useDispatch } from 'calypso/state';
Expand All @@ -20,6 +21,10 @@ interface ModalProps {
onClose: () => void;
}

const FEEDBACK_SHOULD_SHOW_PANEL_API_KEY = NOTICES_KEY_SHOW_FLOATING_USER_FEEDBACK_PANEL;
const FEEDBACK_SHOULD_SHOW_PANEL_API_HIBERNATION_DELAY = 3600 * 24 * 30 * 12; // 12 months
const FEEDBACK_THROTTLE_SUBMISSION_DELAY = 60 * 5; // 5 minutes

const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
const translate = useTranslate();
const dispatch = useDispatch();
Expand All @@ -31,12 +36,18 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
refetch: refetchNotices,
} = useNoticeVisibilityQuery( siteId, NOTICES_KEY_ABLE_TO_SUBMIT_FEEDBACK );

// Disable feedback submission for 24 hours.
const { mutateAsync: disableFeedbackSubmission } = useNoticeVisibilityMutation(
siteId,
NOTICES_KEY_ABLE_TO_SUBMIT_FEEDBACK,
'postponed',
5 * 60
FEEDBACK_THROTTLE_SUBMISSION_DELAY
);

const { mutateAsync: updateFeedbackHibernationPeriod } = useNoticeVisibilityMutation(
siteId,
FEEDBACK_SHOULD_SHOW_PANEL_API_KEY,
'postponed',
FEEDBACK_SHOULD_SHOW_PANEL_API_HIBERNATION_DELAY
);

const { isSubmittingFeedback, submitFeedback, isSubmissionSuccessful } =
Expand Down Expand Up @@ -77,6 +88,7 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
} )
);

updateFeedbackHibernationPeriod();
disableFeedbackSubmission().then( () => {
refetchNotices();
} );
Expand All @@ -89,6 +101,7 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
handleClose,
translate,
disableFeedbackSubmission,
updateFeedbackHibernationPeriod,
refetchNotices,
] );

Expand Down

0 comments on commit 57688b4

Please sign in to comment.