Skip to content

Commit

Permalink
Add check for VIP sites
Browse files Browse the repository at this point in the history
  • Loading branch information
a8ck3n committed Dec 6, 2024
1 parent 2124e97 commit 27211a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
10 changes: 3 additions & 7 deletions client/my-sites/stats/feedback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { useTranslate } from 'i18n-calypso';
import { useEffect, useMemo, useState } from 'react';
import useNoticeVisibilityMutation from 'calypso/my-sites/stats/hooks/use-notice-visibility-mutation';
import { trackStatsAnalyticsEvent } from 'calypso/my-sites/stats/utils';
import { useSelector } from 'calypso/state';
import { isJetpackSite } from 'calypso/state/sites/selectors';
import {
NOTICES_KEY_SHOW_FLOATING_USER_FEEDBACK_PANEL,
useNoticeVisibilityQuery,
} from '../hooks/use-notice-visibility-query';
import useStatsPurchases from '../hooks/use-stats-purchases';
import FeedbackModal from './modal';
import useFetchTrafficHook from './use-fetch-traffic-hook';
import useSiteTypes from './use-site-types';

// eslint-disable-next-line import/no-extraneous-dependencies
import 'animate.css';
Expand Down Expand Up @@ -271,18 +270,15 @@ interface FeedbackPresentorProps {

function StatsFeedbackPresentor( { siteId }: FeedbackPresentorProps ) {
const { supportCommercialUse } = useStatsPurchases( siteId );
const { isJetpackNotAtomic, isVip } = useSiteTypes( siteId );
const { data, isSuccess } = useFetchTrafficHook( siteId );

const views = data?.past_thirty_days.views ?? 0;
const highTrafficThreshold = useMemo( () => getHighTrafficThreshold(), [] );

const isHighTrafficSite = isSuccess && views > highTrafficThreshold;
logFeedbackPresentationStatus( 'StatsHighTrafficSite', isHighTrafficSite );

const isJetpackNotAtomic = useSelector(
( state ) => !! isJetpackSite( state, siteId, { treatAtomicAsJetpackSite: false } )
);
const presentForHighTrafficSite = isJetpackNotAtomic && isHighTrafficSite;
const presentForHighTrafficSite = isHighTrafficSite && isJetpackNotAtomic && ! isVip;

if ( ! supportCommercialUse && ! presentForHighTrafficSite ) {
return null;
Expand Down
19 changes: 19 additions & 0 deletions client/my-sites/stats/feedback/use-site-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useSelector } from 'calypso/state';
import isVipSite from 'calypso/state/selectors/is-vip-site';
import { isJetpackSite } from 'calypso/state/sites/selectors';
import getSiteOption from 'calypso/state/sites/selectors/get-site-option';

function useSiteTypes( siteId: number ) {
const isJetpackNotAtomic = useSelector(
( state ) => !! isJetpackSite( state, siteId, { treatAtomicAsJetpackSite: false } )
);
const isVip = useSelector(
( state ) =>
!! isVipSite( state as object, siteId as number ) ||
!! getSiteOption( state, siteId, 'is_vip' )
);

return { isJetpackNotAtomic, isVip };
}

export default useSiteTypes;

0 comments on commit 27211a6

Please sign in to comment.