File tree Expand file tree Collapse file tree 5 files changed +24
-1
lines changed
projects/packages/forms/src/dashboard Expand file tree Collapse file tree 5 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import { store as noticesStore } from '@wordpress/notices';
1515 * Internal dependencies
1616 */
1717import useInboxData from '../../hooks/use-inbox-data' ;
18+ import { store as dashboardStore } from '../../store' ;
1819
1920type CoreStore = typeof coreStore & {
2021 invalidateResolution : ( selector : string , args : unknown [ ] ) => void ;
@@ -42,6 +43,7 @@ const EmptySpamButton = ( {
4243 const [ isEmpty , setIsEmpty ] = useState ( true ) ;
4344 const { createSuccessNotice, createErrorNotice } = useDispatch ( noticesStore ) ;
4445 const { invalidateResolution } = useDispatch ( coreStore ) as unknown as CoreStore ;
46+ const { invalidateCounts } = useDispatch ( dashboardStore ) ;
4547
4648 // Use props if provided, otherwise use hook
4749 const hookData = useInboxData ( ) ;
@@ -103,12 +105,15 @@ const EmptySpamButton = ( {
103105 'feedback' ,
104106 { ...currentQuery , per_page : 1 , _fields : 'id' } ,
105107 ] ) ;
108+ // invalidate counts to refresh the counts across all status tabs
109+ invalidateCounts ( ) ;
106110 } ) ;
107111 } , [
108112 closeConfirmDialog ,
109113 createErrorNotice ,
110114 createSuccessNotice ,
111115 invalidateResolution ,
116+ invalidateCounts ,
112117 isEmpty ,
113118 isEmptying ,
114119 currentQuery ,
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import { store as noticesStore } from '@wordpress/notices';
1515 * Internal dependencies
1616 */
1717import useInboxData from '../../hooks/use-inbox-data' ;
18+ import { store as dashboardStore } from '../../store' ;
1819
1920type CoreStore = typeof coreStore & {
2021 invalidateResolution : ( selector : string , args : unknown [ ] ) => void ;
@@ -42,6 +43,7 @@ const EmptyTrashButton = ( {
4243 const [ isEmpty , setIsEmpty ] = useState ( true ) ;
4344 const { createSuccessNotice, createErrorNotice } = useDispatch ( noticesStore ) ;
4445 const { invalidateResolution } = useDispatch ( coreStore ) as unknown as CoreStore ;
46+ const { invalidateCounts } = useDispatch ( dashboardStore ) ;
4547
4648 // Use props if provided, otherwise use hook
4749 const hookData = useInboxData ( ) ;
@@ -103,12 +105,15 @@ const EmptyTrashButton = ( {
103105 'feedback' ,
104106 { ...currentQuery , per_page : 1 , _fields : 'id' } ,
105107 ] ) ;
108+ // invalidate counts to refresh the counts across all status tabs
109+ invalidateCounts ( ) ;
106110 } ) ;
107111 } , [
108112 closeConfirmDialog ,
109113 createErrorNotice ,
110114 createSuccessNotice ,
111115 invalidateResolution ,
116+ invalidateCounts ,
112117 isEmpty ,
113118 isEmptying ,
114119 currentQuery ,
Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ export const SET_CURRENT_QUERY = 'SET_CURRENT_QUERY';
44export const SET_SELECTED_RESPONSES = 'SET_SELECTED_RESPONSES' ;
55export const SET_COUNTS = 'SET_COUNTS' ;
66export const UPDATE_COUNTS_OPTIMISTICALLY = 'UPDATE_COUNTS_OPTIMISTICALLY' ;
7+ export const INVALIDATE_COUNTS = 'INVALIDATE_COUNTS' ;
Original file line number Diff line number Diff line change 99 INVALIDATE_FILTERS ,
1010 SET_COUNTS ,
1111 UPDATE_COUNTS_OPTIMISTICALLY ,
12+ INVALIDATE_COUNTS ,
1213} from './action-types' ;
1314
1415/**
@@ -30,6 +31,15 @@ export const invalidateFilters = () => {
3031 return { type : INVALIDATE_FILTERS } ;
3132} ;
3233
34+ /**
35+ * Invalidate the counts when responses are deleted.
36+ *
37+ * @return {object } Action object.
38+ */
39+ export const invalidateCounts = ( ) => {
40+ return { type : INVALIDATE_COUNTS } ;
41+ } ;
42+
3343/**
3444 * Set the selected responses from current data set.
3545 *
Original file line number Diff line number Diff line change 11import apiFetch from '@wordpress/api-fetch' ;
22import { addQueryArgs } from '@wordpress/url' ;
3- import { INVALIDATE_FILTERS } from './action-types' ;
3+ import { INVALIDATE_FILTERS , INVALIDATE_COUNTS } from './action-types' ;
44
55export const getFilters =
66 ( ) =>
@@ -39,3 +39,5 @@ export const getCounts =
3939 const response = await apiFetch ( { path } ) ;
4040 dispatch . setCounts ( response ) ;
4141 } ;
42+
43+ getCounts . shouldInvalidate = action => action . type === INVALIDATE_COUNTS ;
You can’t perform that action at this time.
0 commit comments