|
|
@@ -1,8 +1,8 @@
|
|
|
import { ThunkAction } from 'redux-thunk';
|
|
|
import { getBackendSrv } from 'app/core/services/backend_srv';
|
|
|
-import { NavModelItem, StoreState, Team, TeamGroup, TeamMember } from 'app/types';
|
|
|
+import { StoreState, Team, TeamGroup, TeamMember } from 'app/types';
|
|
|
import { updateNavIndex, UpdateNavIndexAction } from 'app/core/actions';
|
|
|
-import config from 'app/core/config';
|
|
|
+import { buildNavModel } from './navModel';
|
|
|
|
|
|
export enum ActionTypes {
|
|
|
LoadTeams = 'LOAD_TEAMS',
|
|
|
@@ -90,148 +90,73 @@ export function loadTeams(): ThunkResult<void> {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-function buildNavModel(team: Team): NavModelItem {
|
|
|
- const navModel = {
|
|
|
- img: team.avatarUrl,
|
|
|
- id: 'team-' + team.id,
|
|
|
- subTitle: 'Manage members & settings',
|
|
|
- url: '',
|
|
|
- text: team.name,
|
|
|
- breadcrumbs: [{ title: 'Teams', url: 'org/teams' }],
|
|
|
- children: [
|
|
|
- {
|
|
|
- active: false,
|
|
|
- icon: 'gicon gicon-team',
|
|
|
- id: `team-members-${team.id}`,
|
|
|
- text: 'Members',
|
|
|
- url: `org/teams/edit/${team.id}/members`,
|
|
|
- },
|
|
|
- {
|
|
|
- active: false,
|
|
|
- icon: 'fa fa-fw fa-sliders',
|
|
|
- id: `team-settings-${team.id}`,
|
|
|
- text: 'Settings',
|
|
|
- url: `org/teams/edit/${team.id}/settings`,
|
|
|
- },
|
|
|
- ],
|
|
|
- };
|
|
|
-
|
|
|
- if (config.buildInfo.isEnterprise) {
|
|
|
- navModel.children.push({
|
|
|
- active: false,
|
|
|
- icon: 'fa fa-fw fa-refresh',
|
|
|
- id: `team-groupsync-${team.id}`,
|
|
|
- text: 'External group sync',
|
|
|
- url: `org/teams/edit/${team.id}/groupsync`,
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- return navModel;
|
|
|
-}
|
|
|
-
|
|
|
export function loadTeam(id: number): ThunkResult<void> {
|
|
|
return async dispatch => {
|
|
|
- await getBackendSrv()
|
|
|
- .get(`/api/teams/${id}`)
|
|
|
- .then(response => {
|
|
|
- dispatch(teamLoaded(response));
|
|
|
- dispatch(updateNavIndex(buildNavModel(response)));
|
|
|
- });
|
|
|
+ const response = await getBackendSrv().get(`/api/teams/${id}`);
|
|
|
+ dispatch(teamLoaded(response));
|
|
|
+ dispatch(updateNavIndex(buildNavModel(response)));
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function loadTeamMembers(): ThunkResult<void> {
|
|
|
return async (dispatch, getStore) => {
|
|
|
const team = getStore().team.team;
|
|
|
-
|
|
|
- await getBackendSrv()
|
|
|
- .get(`/api/teams/${team.id}/members`)
|
|
|
- .then(response => {
|
|
|
- dispatch(teamMembersLoaded(response));
|
|
|
- });
|
|
|
+ const response = await getBackendSrv().get(`/api/teams/${team.id}/members`);
|
|
|
+ dispatch(teamMembersLoaded(response));
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function addTeamMember(id: number): ThunkResult<void> {
|
|
|
return async (dispatch, getStore) => {
|
|
|
const team = getStore().team.team;
|
|
|
-
|
|
|
- await getBackendSrv()
|
|
|
- .post(`/api/teams/${team.id}/members`, { userId: id })
|
|
|
- .then(() => {
|
|
|
- dispatch(loadTeamMembers());
|
|
|
- });
|
|
|
+ await getBackendSrv().post(`/api/teams/${team.id}/members`, { userId: id });
|
|
|
+ dispatch(loadTeamMembers());
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function removeTeamMember(id: number): ThunkResult<void> {
|
|
|
return async (dispatch, getStore) => {
|
|
|
const team = getStore().team.team;
|
|
|
-
|
|
|
- await getBackendSrv()
|
|
|
- .delete(`/api/teams/${team.id}/members/${id}`)
|
|
|
- .then(() => {
|
|
|
- dispatch(loadTeamMembers());
|
|
|
- });
|
|
|
+ await getBackendSrv().delete(`/api/teams/${team.id}/members/${id}`);
|
|
|
+ dispatch(loadTeamMembers());
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function updateTeam(name: string, email: string): ThunkResult<void> {
|
|
|
return async (dispatch, getStore) => {
|
|
|
const team = getStore().team.team;
|
|
|
- await getBackendSrv()
|
|
|
- .put(`/api/teams/${team.id}`, {
|
|
|
- name,
|
|
|
- email,
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- dispatch(loadTeam(team.id));
|
|
|
- });
|
|
|
+ await getBackendSrv().put(`/api/teams/${team.id}`, { name, email });
|
|
|
+ dispatch(loadTeam(team.id));
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function loadTeamGroups(): ThunkResult<void> {
|
|
|
return async (dispatch, getStore) => {
|
|
|
const team = getStore().team.team;
|
|
|
-
|
|
|
- await getBackendSrv()
|
|
|
- .get(`/api/teams/${team.id}/groups`)
|
|
|
- .then(response => {
|
|
|
- dispatch(teamGroupsLoaded(response));
|
|
|
- });
|
|
|
+ const response = await getBackendSrv().get(`/api/teams/${team.id}/groups`);
|
|
|
+ dispatch(teamGroupsLoaded(response));
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function addTeamGroup(groupId: string): ThunkResult<void> {
|
|
|
return async (dispatch, getStore) => {
|
|
|
const team = getStore().team.team;
|
|
|
-
|
|
|
- await getBackendSrv()
|
|
|
- .post(`/api/teams/${team.id}/groups`, { groupId: groupId })
|
|
|
- .then(() => {
|
|
|
- dispatch(loadTeamGroups());
|
|
|
- });
|
|
|
+ await getBackendSrv().post(`/api/teams/${team.id}/groups`, { groupId: groupId });
|
|
|
+ dispatch(loadTeamGroups());
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function removeTeamGroup(groupId: string): ThunkResult<void> {
|
|
|
return async (dispatch, getStore) => {
|
|
|
const team = getStore().team.team;
|
|
|
-
|
|
|
- await getBackendSrv()
|
|
|
- .delete(`/api/teams/${team.id}/groups/${groupId}`)
|
|
|
- .then(() => {
|
|
|
- dispatch(loadTeamGroups());
|
|
|
- });
|
|
|
+ await getBackendSrv().delete(`/api/teams/${team.id}/groups/${groupId}`);
|
|
|
+ dispatch(loadTeamGroups());
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function deleteTeam(id: number): ThunkResult<void> {
|
|
|
return async dispatch => {
|
|
|
- await getBackendSrv()
|
|
|
- .delete(`/api/teams/${id}`)
|
|
|
- .then(() => {
|
|
|
- dispatch(loadTeams());
|
|
|
- });
|
|
|
+ await getBackendSrv().delete(`/api/teams/${id}`);
|
|
|
+ dispatch(loadTeams());
|
|
|
};
|
|
|
}
|