Add select to change board of post

This commit is contained in:
riggraz
2019-09-21 12:54:57 +02:00
parent 7874015580
commit 7729057180
13 changed files with 222 additions and 33 deletions

View File

@@ -0,0 +1,42 @@
import { Action } from 'redux';
import { ThunkAction } from 'redux-thunk';
import { State } from '../reducers/rootReducer';
export const CHANGE_POST_BOARD_SUCCESS = 'CHANGE_POST_BOARD_SUCCESS';
export interface ChangePostBoardSuccessAction {
type: typeof CHANGE_POST_BOARD_SUCCESS;
newBoardId;
}
const changePostBoardSuccess = (newBoardId: number): ChangePostBoardSuccessAction => ({
type: CHANGE_POST_BOARD_SUCCESS,
newBoardId,
});
export const changePostBoard = (
postId: number,
newBoardId: number,
authenticityToken: string,
): ThunkAction<void, State, null, Action<string>> => async (dispatch) => {
try {
const response = await fetch(`/posts/${postId}`, {
method: 'PATCH',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-CSRF-Token': authenticityToken,
},
body: JSON.stringify({
post: {
board_id: newBoardId,
},
})
});
if (response.status === 204) {
dispatch(changePostBoardSuccess(newBoardId));
}
} catch (e) {
console.log(e);
}
}