Skip to content

Commit

Permalink
Fix Key Metrics New badge for first time setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuasha420 committed Dec 4, 2023
1 parent fb4a0e9 commit d8680c3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion assets/js/components/KeyMetrics/KeyMetricsNewBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/**
* WordPress dependencies
*/
import { useState, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
Expand All @@ -30,10 +31,26 @@ const { useSelect } = Data;
export default function KeyMetricsNewBadge() {
// This is necessary to conditionally render the badge
// as this component is used in a context where `select` is not in scope.
const isNew = useSelect( ( select ) =>
const isKeyMetricsSetupNew = useSelect( ( select ) =>
select( CORE_SITE ).getKeyMetricsSetupNew()
);

const isKeyMetricsSetupCompleted = useSelect( ( select ) =>
select( CORE_SITE ).isKeyMetricsSetupCompleted()
);

const [ initialKeyMetricsSetupCompleted ] = useState(
isKeyMetricsSetupCompleted
);

const [ isNew, setIsNew ] = useState( isKeyMetricsSetupNew );

useEffect( () => {
if ( ! initialKeyMetricsSetupCompleted && isKeyMetricsSetupCompleted ) {
setIsNew( true );
}
}, [ initialKeyMetricsSetupCompleted, isKeyMetricsSetupCompleted ] );

return (
isNew && (
<Badge
Expand Down

0 comments on commit d8680c3

Please sign in to comment.