summaryrefslogtreecommitdiffstats
path: root/webapp/components/integrations/components/commands_container/commands_container.jsx
blob: 8f89ff631df4abde2e4b4568c52caab8e91939f4 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import React from 'react';
import PropTypes from 'prop-types';

export default class CommandsContainer extends React.PureComponent {
    static propTypes = {

        /**
        * The team data needed to pass into child components
        */
        team: PropTypes.object,

        /**
        * The user data needed to pass into child components
        */
        user: PropTypes.object,

        /**
        * The children prop needed to render child component
        */
        children: PropTypes.node.isRequired,

        /**
        * Set if user is admin
        */
        isAdmin: PropTypes.bool,

        /**
        * The users collection
        */
        users: PropTypes.object,

        /**
        * Installed slash commands to display
        */
        commands: PropTypes.array,

        actions: PropTypes.shape({

            /**
            * The function to call to fetch team commands
            */
            getCustomTeamCommands: PropTypes.func.isRequired
        }).isRequired
    }

    constructor(props) {
        super(props);
        this.state = {
            loading: true
        };
    }

    componentDidMount() {
        if (window.mm_config.EnableCommands === 'true') {
            this.props.actions.getCustomTeamCommands(this.props.team.id).then(
                () => this.setState({loading: false})
            );
        }
    }

    render() {
        return (
            <div>
                {React.cloneElement(this.props.children, {
                    loading: this.state.loading,
                    commands: this.props.commands || [],
                    users: this.props.users,
                    team: this.props.team,
                    user: this.props.user,
                    isAdmin: this.props.isAdmin
                })}
            </div>
        );
    }
}