mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 03:07:52 +01:00
Add post status administration (#105)
This commit is contained in:
committed by
GitHub
parent
c5148147e3
commit
5256ea911a
62
app/javascript/actions/deletePostStatus.ts
Normal file
62
app/javascript/actions/deletePostStatus.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Action } from "redux";
|
||||
import { ThunkAction } from "redux-thunk";
|
||||
import buildRequestHeaders from "../helpers/buildRequestHeaders";
|
||||
import { State } from "../reducers/rootReducer";
|
||||
|
||||
export const POST_STATUS_DELETE_START = 'POST_STATUS_DELETE_START';
|
||||
interface PostStatusDeleteStartAction {
|
||||
type: typeof POST_STATUS_DELETE_START;
|
||||
}
|
||||
|
||||
export const POST_STATUS_DELETE_SUCCESS = 'POST_STATUS_DELETE_SUCCESS';
|
||||
interface PostStatusDeleteSuccessAction {
|
||||
type: typeof POST_STATUS_DELETE_SUCCESS;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export const POST_STATUS_DELETE_FAILURE = 'POST_STATUS_DELETE_FAILURE';
|
||||
interface PostStatusDeleteFailureAction {
|
||||
type: typeof POST_STATUS_DELETE_FAILURE;
|
||||
error: string;
|
||||
}
|
||||
|
||||
export type PostStatusDeleteActionTypes =
|
||||
PostStatusDeleteStartAction |
|
||||
PostStatusDeleteSuccessAction |
|
||||
PostStatusDeleteFailureAction;
|
||||
|
||||
const postStatusDeleteStart = (): PostStatusDeleteStartAction => ({
|
||||
type: POST_STATUS_DELETE_START,
|
||||
});
|
||||
|
||||
const postStatusDeleteSuccess = (
|
||||
id: number,
|
||||
): PostStatusDeleteSuccessAction => ({
|
||||
type: POST_STATUS_DELETE_SUCCESS,
|
||||
id,
|
||||
});
|
||||
|
||||
const postStatusDeleteFailure = (error: string): PostStatusDeleteFailureAction => ({
|
||||
type: POST_STATUS_DELETE_FAILURE,
|
||||
error,
|
||||
});
|
||||
|
||||
export const deletePostStatus = (
|
||||
id: number,
|
||||
authenticityToken: string,
|
||||
): ThunkAction<void, State, null, Action<string>> => (
|
||||
async (dispatch) => {
|
||||
dispatch(postStatusDeleteStart());
|
||||
|
||||
try {
|
||||
const response = await fetch(`/post_statuses/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: buildRequestHeaders(authenticityToken),
|
||||
});
|
||||
const json = await response.json();
|
||||
dispatch(postStatusDeleteSuccess(id));
|
||||
} catch (e) {
|
||||
dispatch(postStatusDeleteFailure(e));
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user