Skip to content

Instantly share code, notes, and snippets.

@mcjcloud
Created July 10, 2020 06:40
Show Gist options
  • Save mcjcloud/f95f9af99d5c295db7cc262962465bca to your computer and use it in GitHub Desktop.
Save mcjcloud/f95f9af99d5c295db7cc262962465bca to your computer and use it in GitHub Desktop.
Asterisk Medium Article: uncompleteTodo
export const uncompleteTodo = (guid: string) => async (dispatch: Dispatch) => {
dispatch({ type: "TODO_UNCOMPLETED_STARTED" })
const response = await fetch(`${API_ENDPOINT}/todo/${guid}/uncomplete`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
}).then(r => r.json())
if (!!response && !!response?.todo) {
dispatch({ type: "TODO_UNCOMPLETED", payload: { todo: response.todo } })
} else {
dispatch({ type: "TODO_ERRORED", payload: { uncompleteError: response?.error ?? "Error uncompleting Todo item" } })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment