This commit is contained in:
Rehan Dalal 2017-05-10 11:21:05 -04:00
Родитель 7a61a73e4a
Коммит 418ea89f48
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 410D198EEF339E0B
4 изменённых файлов: 53 добавлений и 0 удалений

Просмотреть файл

@ -2,6 +2,7 @@
export const ACTION_RECEIVE = 'ACTION_RECEIVE';
export const APPROVAL_REQUEST_RECEIVE = 'APPROVAL_REQUEST_RECEIVE';
export const RECIPE_DELETE = 'RECIPE_DELETE';
export const RECIPE_RECEIVE = 'RECIPE_RECEIVE';
export const RECIPE_FILTERS_RECEIVE = 'RECIPE_FILTERS_RECEIVE';
export const RECIPE_HISTORY_RECEIVE = 'RECIPE_HISTORY_RECEIVE';

Просмотреть файл

@ -1,5 +1,6 @@
import {
ACTION_RECEIVE,
RECIPE_DELETE,
RECIPE_RECEIVE,
RECIPE_FILTERS_RECEIVE,
RECIPE_HISTORY_RECEIVE,
@ -59,6 +60,46 @@ export function fetchAllRecipes() {
}
export function createRecipe(recipeData) {
return async dispatch => {
const requestId = 'create-recipe';
const recipe = await dispatch(makeApiRequest(requestId, 'v2/recipe/', {
method: 'POST',
data: recipeData,
}));
dispatch(recipeReceived(recipe));
};
}
export function updateRecipe(pk, recipeData) {
return async dispatch => {
const requestId = `update-recipe-${pk}`;
const recipe = await dispatch(makeApiRequest(requestId, `v2/recipe/${pk}`, {
method: 'PATCH',
data: recipeData,
}));
dispatch(recipeReceived(recipe));
};
}
export function deleteRecipe(pk) {
return async dispatch => {
const requestId = `delete-recipe-${pk}`;
await dispatch(makeApiRequest(requestId, `v2/recipe/${pk}`, {
method: 'DELETE',
}));
dispatch({
type: RECIPE_DELETE,
recipeId: pk,
});
};
}
export function fetchRecipeHistory(pk) {
return async dispatch => {
const requestId = `fetch-recipe-history-${pk}`;

Просмотреть файл

@ -2,6 +2,7 @@ import { fromJS, Map } from 'immutable';
import { combineReducers } from 'redux';
import {
RECIPE_DELETE,
RECIPE_RECEIVE,
RECIPE_FILTERS_RECEIVE,
RECIPE_HISTORY_RECEIVE,
@ -24,6 +25,9 @@ function history(state = new Map(), action) {
case RECIPE_HISTORY_RECEIVE:
return state.set(action.recipeId, fromJS(action.revisions.map(revision => revision.id)));
case RECIPE_DELETE:
return state.remove(action.recipeId);
default:
return state;
}
@ -54,6 +58,9 @@ function items(state = new Map(), action) {
return state.set(action.recipe.id, recipe);
case RECIPE_DELETE:
return state.remove(action.recipeId);
default:
return state;
}

Просмотреть файл

@ -2,6 +2,7 @@ import { fromJS, Map } from 'immutable';
import { combineReducers } from 'redux';
import {
RECIPE_DELETE,
REVISION_RECEIVE,
} from '../action-types';
@ -17,6 +18,9 @@ function items(state = new Map(), action) {
return state.set(action.revision.id, revision);
case RECIPE_DELETE:
return state.filterNot(item => item.getIn(['recipe', 'id']) === action.recipeId);
default:
return state;
}