Skip to content

Commit

Permalink
Hide poll from users with accounts older than 2025-01-01
Browse files Browse the repository at this point in the history
  • Loading branch information
holdercp committed Jan 24, 2025
1 parent f6a3f95 commit 5ada166
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client/reader/components/crowdsignal-poll/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useRef } from 'react';
import { useDispatch, useSelector } from 'calypso/state';
import { getCurrentUserDate } from 'calypso/state/current-user/selectors';
import { savePreference } from 'calypso/state/preferences/actions';
import { getPreference, hasReceivedRemotePreferences } from 'calypso/state/preferences/selectors';
import { isA8cTeamMember } from 'calypso/state/teams/selectors';
Expand All @@ -9,24 +10,31 @@ import CrowdsignalPollComponent from './main';
import './style.scss';

const READER_CROWDSIGNAL_POLL_VIEWED_PREFERENCE = 'reader-crowdsignal-poll-viewed';
const REGISTRATION_CUTOFF_DATE = new Date( '2025-01-01T00:00:00Z' );

const CrowdsignalPoll = () => {
const dispatch = useDispatch();

const remotePrefsLoaded = useSelector( hasReceivedRemotePreferences );
const isAutomattician = useSelector( isA8cTeamMember );
const userRegistrationDate = useSelector( getCurrentUserDate );
const hasViewedPollPref = useSelector( ( state ): boolean | undefined | null =>
getPreference( state, READER_CROWDSIGNAL_POLL_VIEWED_PREFERENCE )
);
const hasViewedPoll = useRef( hasViewedPollPref ); // Show the poll when the component first mounts, but not subsequently

const shouldNotRender =
( remotePrefsLoaded && hasViewedPoll.current ) ||
new Date( userRegistrationDate ) < REGISTRATION_CUTOFF_DATE ||
isAutomattician;

useEffect( () => {
if ( ! hasViewedPoll.current ) {
dispatch( savePreference( READER_CROWDSIGNAL_POLL_VIEWED_PREFERENCE, true ) );
}
}, [ dispatch ] );

if ( ( remotePrefsLoaded && hasViewedPoll.current ) || isAutomattician ) {
if ( shouldNotRender ) {
return null;
}

Expand Down

0 comments on commit 5ada166

Please sign in to comment.