mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
added config modify
This commit is contained in:
@@ -4,13 +4,20 @@ import * as types from "../../modules/types";
|
||||
import type { Action } from "../../types/Action";
|
||||
import { isPending } from "../../modules/pending";
|
||||
import { getFailure } from "../../modules/failure";
|
||||
import { Dispatch } from "redux";
|
||||
|
||||
export const FETCH_CONFIG = "scm/config/FETCH_CONFIG";
|
||||
export const FETCH_CONFIG_PENDING = `${FETCH_CONFIG}_${types.PENDING_SUFFIX}`;
|
||||
export const FETCH_CONFIG_SUCCESS = `${FETCH_CONFIG}_${types.SUCCESS_SUFFIX}`;
|
||||
export const FETCH_CONFIG_FAILURE = `${FETCH_CONFIG}_${types.FAILURE_SUFFIX}`;
|
||||
|
||||
export const MODIFY_CONFIG = "scm/config/FETCH_CONFIG";
|
||||
export const MODIFY_CONFIG_PENDING = `${MODIFY_CONFIG}_${types.PENDING_SUFFIX}`;
|
||||
export const MODIFY_CONFIG_SUCCESS = `${MODIFY_CONFIG}_${types.SUCCESS_SUFFIX}`;
|
||||
export const MODIFY_CONFIG_FAILURE = `${MODIFY_CONFIG}_${types.FAILURE_SUFFIX}`;
|
||||
|
||||
const CONFIG_URL = "config";
|
||||
const CONTENT_TYPE_CONFIG = "application/vnd.scmm-config+json;v=2";
|
||||
|
||||
//fetch config
|
||||
export function fetchConfig() {
|
||||
@@ -53,6 +60,53 @@ export function fetchConfigFailure(error: Error): Action {
|
||||
};
|
||||
}
|
||||
|
||||
// modify config
|
||||
export function modifyConfig(config: any, callback?: () => void) {
|
||||
return function(dispatch: Dispatch) {
|
||||
dispatch(modifyConfigPending(config));
|
||||
return apiClient
|
||||
.put(config._links.update.href, config, CONTENT_TYPE_CONFIG)
|
||||
.then(() => {
|
||||
dispatch(modifyConfigSuccess(config));
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
})
|
||||
.catch(cause => {
|
||||
dispatch(
|
||||
modifyConfigFailure(
|
||||
config,
|
||||
new Error(`could not modify config: ${cause.message}`)
|
||||
)
|
||||
);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function modifyConfigPending(config: any): Action {
|
||||
return {
|
||||
type: MODIFY_CONFIG_PENDING,
|
||||
payload: config
|
||||
};
|
||||
}
|
||||
|
||||
export function modifyConfigSuccess(config: any): Action {
|
||||
return {
|
||||
type: MODIFY_CONFIG_SUCCESS,
|
||||
payload: config
|
||||
};
|
||||
}
|
||||
|
||||
export function modifyConfigFailure(config: any, error: Error): Action {
|
||||
return {
|
||||
type: MODIFY_CONFIG_FAILURE,
|
||||
payload: {
|
||||
error,
|
||||
config
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//reducer
|
||||
|
||||
function reducer(state: any = {}, action: any = {}) {
|
||||
|
||||
Reference in New Issue
Block a user