2019-05-13 02:38:19 -05:00
|
|
|
import { Organization, ThunkResult } from 'app/types';
|
2018-11-15 06:37:29 -06:00
|
|
|
import { getBackendSrv } from 'app/core/services/backend_srv';
|
2018-10-25 00:45:22 -05:00
|
|
|
|
|
|
|
export enum ActionTypes {
|
2018-12-05 06:08:00 -06:00
|
|
|
LoadOrganization = 'LOAD_ORGANIZATION',
|
2018-10-26 07:15:37 -05:00
|
|
|
SetOrganizationName = 'SET_ORGANIZATION_NAME',
|
2018-10-25 00:45:22 -05:00
|
|
|
}
|
|
|
|
|
2018-10-25 09:56:49 -05:00
|
|
|
interface LoadOrganizationAction {
|
2018-10-26 07:15:37 -05:00
|
|
|
type: ActionTypes.LoadOrganization;
|
2018-10-25 09:56:49 -05:00
|
|
|
payload: Organization;
|
2018-10-25 00:45:22 -05:00
|
|
|
}
|
|
|
|
|
2018-10-26 07:15:37 -05:00
|
|
|
interface SetOrganizationNameAction {
|
|
|
|
type: ActionTypes.SetOrganizationName;
|
|
|
|
payload: string;
|
|
|
|
}
|
|
|
|
|
2018-12-05 06:08:00 -06:00
|
|
|
const organizationLoaded = (organization: Organization) => ({
|
2018-10-26 07:15:37 -05:00
|
|
|
type: ActionTypes.LoadOrganization,
|
2018-12-05 06:08:00 -06:00
|
|
|
payload: organization,
|
2018-10-25 00:45:22 -05:00
|
|
|
});
|
|
|
|
|
2018-10-26 07:15:37 -05:00
|
|
|
export const setOrganizationName = (orgName: string) => ({
|
|
|
|
type: ActionTypes.SetOrganizationName,
|
|
|
|
payload: orgName,
|
|
|
|
});
|
|
|
|
|
2018-11-15 06:37:29 -06:00
|
|
|
export type Action = LoadOrganizationAction | SetOrganizationNameAction;
|
2018-10-25 00:45:22 -05:00
|
|
|
|
2019-05-13 02:38:19 -05:00
|
|
|
export function loadOrganization(): ThunkResult<any> {
|
2018-10-25 00:45:22 -05:00
|
|
|
return async dispatch => {
|
2018-12-05 06:08:00 -06:00
|
|
|
const organizationResponse = await getBackendSrv().get('/api/org');
|
|
|
|
dispatch(organizationLoaded(organizationResponse));
|
2018-10-25 09:56:49 -05:00
|
|
|
|
2018-12-05 06:08:00 -06:00
|
|
|
return organizationResponse;
|
2018-10-25 09:56:49 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-13 02:38:19 -05:00
|
|
|
export function updateOrganization(): ThunkResult<any> {
|
2018-10-26 07:51:33 -05:00
|
|
|
return async (dispatch, getStore) => {
|
|
|
|
const organization = getStore().organization.organization;
|
|
|
|
|
|
|
|
await getBackendSrv().put('/api/org', { name: organization.name });
|
|
|
|
|
|
|
|
dispatch(loadOrganization());
|
|
|
|
};
|
2018-10-26 07:15:37 -05:00
|
|
|
}
|