Skip to content

Commit 5a4436d

Browse files
committed
Format numbers and parse formatted numbers
1 parent 0f5d03f commit 5a4436d

File tree

1 file changed

+5
-2
lines changed
  • projects/packages/forms/src/dashboard/inbox

1 file changed

+5
-2
lines changed

projects/packages/forms/src/dashboard/inbox/utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { formatNumber } from '@automattic/number-formatters';
2+
13
// Function to get the URL of the page or post where the form was submitted.
24
export const getPath = item => {
35
try {
@@ -18,7 +20,7 @@ function updateBadge( element, count ) {
1820
const oldClass = [ ...element.classList ].find( c => c.startsWith( 'count-' ) );
1921
element.classList.replace( oldClass, `count-${ count }` );
2022
element.ariaHidden = count > 0 ? 'false' : 'true';
21-
element.textContent = count;
23+
element.textContent = formatNumber( count );
2224
}
2325

2426
/**
@@ -49,7 +51,8 @@ export const updateMenuCounterOptimistically = count => {
4951
document.querySelectorAll( '.jp-feedback-unread-counter' ).forEach( item => {
5052
let optimisticCount = 0;
5153
if ( item.textContent !== '' ) {
52-
optimisticCount = parseInt( item.textContent, 10 ) + count;
54+
// Ensure large formatted numbers like "1,000" are converted to integers properly
55+
optimisticCount = parseInt( item.textContent.replace( /\D/g, '' ), 10 ) + count;
5356
}
5457

5558
updateBadge( item, optimisticCount );

0 commit comments

Comments
 (0)