Skip to content

Commit 48bccc1

Browse files
author
Joel T
committed
Updating badge for tasks that complete with no page refresh
1 parent cc09e94 commit 48bccc1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

plugins/woocommerce-admin/client/tasks/task.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ export const Task: React.FC< TaskProps > = ( { query, task } ) => {
2525
optimisticallyCompleteTask,
2626
} = useDispatch( ONBOARDING_STORE_NAME );
2727

28+
const updateBadge = useCallback( () => {
29+
const badgeElement: HTMLElement | null = document.querySelector(
30+
'.toplevel_page_woocommerce .remaining-tasks-badge'
31+
);
32+
33+
if ( ! badgeElement ) {
34+
return;
35+
}
36+
37+
const currentBadgeCount = Number( badgeElement.innerText );
38+
badgeElement.innerHTML = String( currentBadgeCount - 1 );
39+
}, [] );
40+
2841
const onComplete = useCallback(
2942
( options ) => {
3043
optimisticallyCompleteTask( id );
@@ -34,6 +47,7 @@ export const Task: React.FC< TaskProps > = ( { query, task } ) => {
3447
: getNewPath( {}, '/', {} )
3548
);
3649
invalidateResolutionForStoreSelector( 'getTaskLists' );
50+
updateBadge();
3751
},
3852
[ id ]
3953
);

plugins/woocommerce/src/Admin/Features/OnboardingTasks/TaskLists.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public static function menu_task_count() {
507507

508508
foreach ( $submenu['woocommerce'] as $key => $menu_item ) {
509509
if ( 0 === strpos( $menu_item[0], _x( 'Home', 'Admin menu name', 'woocommerce' ) ) ) {
510-
$submenu['woocommerce'][ $key ][0] .= ' <span class="awaiting-mod update-plugins count-' . esc_attr( $tasks_count ) . '">' . number_format_i18n( $tasks_count ) . '</span>'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
510+
$submenu['woocommerce'][ $key ][0] .= ' <span class="awaiting-mod update-plugins remaining-tasks-badge count-' . esc_attr( $tasks_count ) . '">' . number_format_i18n( $tasks_count ) . '</span>'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
511511
break;
512512
}
513513
}

0 commit comments

Comments
 (0)