summaryrefslogtreecommitdiffstats
path: root/web/react/components/team_export_tab.jsx
blob: 1bc5abdb1464563f3be809051d0add714e65f884 (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
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.

var Client = require('../utils/client.jsx');

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' />
                    {' Exporting...'}
                </p>
            );
            break;
        case 'ready':
            messageSection = (
                <p className='confirm-import alert alert-success'>
                    <i className='fa fa-check' />
                    {' Ready for '}
                    <a
                        href={this.state.link}
                        download={true}
                    >
                        {'download'}
                    </a>
                </p>
            );
            break;
        case 'failure':
            messageSection = (
                <p className='confirm-import alert alert-warning'>
                    <i className='fa fa-warning' />
                    {' Unable to export: ' + this.state.err}
                </p>
            );
            break;
        }

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