summaryrefslogtreecommitdiffstats
path: root/webapp/actions/team_actions.jsx
blob: 249c9d54049b6d0236fd487d0450677627795afa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import UserStore from 'stores/user_store.jsx';

import Constants from 'utils/constants.jsx';
const ActionTypes = Constants.ActionTypes;

import * as AsyncClient from 'utils/async_client.jsx';
import Client from 'utils/web_client.jsx';
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';

import {browserHistory} from 'react-router/es6';

export function checkIfTeamExists(teamName, onSuccess, onError) {
    Client.findTeamByName(teamName, onSuccess, onError);
}

export function createTeam(team, onSuccess, onError) {
    Client.createTeam(team,
        (rteam) => {
            AsyncClient.getDirectProfiles();

            AppDispatcher.handleServerAction({
                type: ActionTypes.CREATED_TEAM,
                team: rteam,
                member: {team_id: rteam.id, user_id: UserStore.getCurrentId(), roles: 'admin'}
            });

            browserHistory.push('/' + rteam.name + '/channels/town-square');

            if (onSuccess) {
                onSuccess(rteam);
            }
        },
        onError
    );
}