Skip to content

Commit 095fefc

Browse files
authored
Merge pull request #4461 from woocommerce/dev/PCP-6294-mexico-enable-installments-not-visible-on-overview-tab-in-section-feautres
fix(todos): prevent dismissed items reappearing when dismissing multiple todos (6294)
2 parents c7258d8 + 121a6fd commit 095fefc

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

modules/ppcp-settings/resources/js/data/todos/actions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ export function refresh() {
111111
};
112112
}
113113

114+
export function addDismissedTodo( todoId ) {
115+
return async ( { select, dispatch } ) => {
116+
const current = select.getDismissedTodos() || [];
117+
if ( ! current.includes( todoId ) ) {
118+
await dispatch.setDismissedTodos( [ ...current, todoId ] );
119+
}
120+
};
121+
}
122+
114123
export function resetDismissedTodos() {
115124
return async ( { dispatch } ) => {
116125
try {

modules/ppcp-settings/resources/js/data/todos/hooks.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const useStoreData = () => {
3838

3939
const useHooks = () => {
4040
const { dispatch, select } = useStoreData();
41-
const { fetchTodos, setDismissedTodos, setCompletedTodos } = dispatch;
41+
const { fetchTodos, addDismissedTodo, setCompletedTodos } = dispatch;
4242

4343
// Get todos data from store
4444
const todos = select.getTodos();
@@ -47,12 +47,7 @@ const useHooks = () => {
4747

4848
const dismissedSet = new Set( dismissedTodos );
4949

50-
const dismissTodo = async ( todoId ) => {
51-
if ( ! dismissedSet.has( todoId ) ) {
52-
const newDismissedTodos = [ ...dismissedTodos, todoId ];
53-
await setDismissedTodos( newDismissedTodos );
54-
}
55-
};
50+
const dismissTodo = ( todoId ) => addDismissedTodo( todoId );
5651

5752
const setTodoCompleted = async ( todoId, isCompleted ) => {
5853
let newCompletedTodos;

0 commit comments

Comments
 (0)