Merge pull request #3059 from woocommerce/PCP-4124-dynamic-logic-for-things-to-do-next-ver4

Settings UI: Add functionality to mark todos as complete on click
This commit is contained in:
Danny Dudzic 2025-02-05 12:07:09 +01:00 committed by GitHub
commit 2d24240d02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 205 additions and 29 deletions

View file

@ -17,4 +17,5 @@ export default {
DO_FETCH_TODOS: 'TODOS:DO_FETCH_TODOS',
DO_PERSIST_DATA: 'TODOS:DO_PERSIST_DATA',
DO_RESET_DISMISSED_TODOS: 'TODOS:DO_RESET_DISMISSED_TODOS',
DO_COMPLETE_ONCLICK: 'TODOS:DO_COMPLETE_ONCLICK',
};

View file

@ -39,8 +39,7 @@ export const resetDismissedTodos = function* () {
const result = yield { type: ACTION_TYPES.DO_RESET_DISMISSED_TODOS };
if ( result && result.success ) {
// After successful reset, fetch fresh todos
yield fetchTodos();
yield setDismissedTodos( [] );
}
return result;
@ -50,3 +49,19 @@ export const setCompletedTodos = ( completedTodos ) => ( {
type: ACTION_TYPES.SET_COMPLETED_TODOS,
payload: completedTodos,
} );
export const completeOnClick = function* ( todoId ) {
const result = yield {
type: ACTION_TYPES.DO_COMPLETE_ONCLICK,
todoId,
};
if ( result && result.success ) {
// Set transient completed state for visual feedback
const currentTransientCompleted =
yield select( STORE_NAME ).getCompletedTodos();
yield setCompletedTodos( [ ...currentTransientCompleted, todoId ] );
}
return result;
};

View file

@ -9,3 +9,4 @@ export const REST_PATH = '/wc/v3/wc_paypal/todos';
export const REST_PERSIST_PATH = '/wc/v3/wc_paypal/todos';
export const REST_RESET_DISMISSED_TODOS_PATH =
'/wc/v3/wc_paypal/reset-dismissed-todos';
export const REST_COMPLETE_ONCLICK_PATH = '/wc/v3/wc_paypal/complete-onclick';

View file

@ -12,6 +12,7 @@ import {
REST_PATH,
REST_PERSIST_PATH,
REST_RESET_DISMISSED_TODOS_PATH,
REST_COMPLETE_ONCLICK_PATH,
} from './constants';
import ACTION_TYPES from './action-types';
@ -44,4 +45,21 @@ export const controls = {
};
}
},
async [ ACTION_TYPES.DO_COMPLETE_ONCLICK ]( { todoId } ) {
try {
const response = await apiFetch( {
path: REST_COMPLETE_ONCLICK_PATH,
method: 'POST',
data: { todoId },
} );
return response;
} catch ( e ) {
return {
success: false,
error: e,
message: e.message,
};
}
},
};

View file

@ -28,6 +28,7 @@ const defaultTransient = Object.freeze( {
const defaultPersistent = Object.freeze( {
todos: [],
dismissedTodos: [],
completedOnClickTodos: [],
} );
// Reducer logic.