summaryrefslogtreecommitdiffstats
path: root/webapp/components/team_export_tab.jsx
blob: 37f886aab14b8275c6276feeea31aad7f6852762 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import Client from 'utils/web_client.jsx';

import {FormattedMessage} from 'react-intl';

import React from 'react';
import {Link} from 'react-router';

export default class TeamExportTab extends React.Component {
    constructor(props) {
        super(props);
        this.state = {status: 'request', link: '', err: ''};

        this.onExportSuccess = this.onExportSuccess.bind(this);
        this.onExportFailure = this.onExportFailure.bind(this);
        this.doExport = this.doExport.bind(this);
    }
    onExportSuccess(data) {
        this.setState({status: 'ready', link: data.link, err: ''});
    }
    onExportFailure(e) {
        this.setState({status: 'failure', link: '', err: e.message});
    }
    doExport() {
        if (this.state.status === 'in-progress') {
            return;
        }
        this.setState({status: 'in-progress'});
        Client.exportTeam(this.onExportSuccess, this.onExportFailure);
    }
    render() {
        var messageSection = '';
        switch (this.state.status) {
        case 'request':
            messageSection = '';
            break;
        case 'in-progress':
            messageSection = (
                <p className='confirm-import alert alert-warning'>
                    <i className='fa fa-spinner fa-pulse'/>
                    <FormattedMessage
                        id='team_export_tab.exporting'
                        defaultMessage=' Exporting...'
                    />
                </p>
            );
            break;
        case 'ready':
            messageSection = (
                <p className='confirm-import alert alert-success'>
                    <i className='fa fa-check'/>
                    <FormattedMessage
                        id='team_export_tab.ready'
                        defaultMessage=' Ready for '
                    />
                    <Link
                        to={this.state.link}
                        download={true}
                    >
                        <FormattedMessage
                            id='team_export_tab.download'
                            defaultMessage='download'
                        />
                    </Link>
                </p>
            );
            break;
        case 'failure':
            messageSection = (
                <p className='confirm-import alert alert-warning'>
                    <i className='fa fa-warning'/>
                    <FormattedMessage
                        id='team_export_tab.unable'
                        defaultMessage=' Unable to export: {error}'
                        values={{
                            error: this.state.err
                        }}
                    />
                </p>
            );
            break;
        }

        return (
            <div
                ref='wrapper'
                className='user-settings'
            >
                <h3 className='tab-header'>
                    <FormattedMessage
                        id='team_export_tab.export'
                        defaultMessage='Export'
                    />
                </h3>
                <div className='divider-dark first'/>
                <ul className='section-max'>
                    <li className='col-xs-12 section-title'>
                        <FormattedMessage
                            id='team_export_tab.exportTeam'
                            defaultMessage='Export your team'
                        />
                    </li>
                    <li className='col-xs-offset-3 col-xs-8'>
                        <ul className='setting-list'>
                            <li className='setting-list-item'>
                                <a
                                    className='btn btn-sm btn-primary btn-file sel-btn'
                                    href='#'
                                    onClick={this.doExport}
                                >
                                    <FormattedMessage
                                        id='team_export_tab.export'
                                        defaultMessage='Export'
                                    />
                                </a>
                            </li>
                        </ul>
                    </li>
                </ul>
                <div className='divider-dark'/>
                {messageSection}
            </div>
        );
    }
}