From 5ada166c2212d931a3fa4127e4d49b48132bae66 Mon Sep 17 00:00:00 2001 From: Chris Holder Date: Fri, 24 Jan 2025 12:52:13 -0600 Subject: [PATCH] Hide poll from users with accounts older than 2025-01-01 --- client/reader/components/crowdsignal-poll/index.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/reader/components/crowdsignal-poll/index.tsx b/client/reader/components/crowdsignal-poll/index.tsx index 21f29fcf46b4b..e2542dcc571c9 100644 --- a/client/reader/components/crowdsignal-poll/index.tsx +++ b/client/reader/components/crowdsignal-poll/index.tsx @@ -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'; @@ -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; }