|
| 1 | +import React from 'react'; |
| 2 | +import DocumentTitle from 'react-document-title'; |
| 3 | + |
| 4 | +import {t} from '../locale'; |
| 5 | +import api from '../api'; |
| 6 | +import ConfigStore from '../stores/configStore'; |
| 7 | +import LoadingIndicator from '../components/loadingIndicator'; |
| 8 | +import {EmailField, TextField} from '../components/forms'; |
| 9 | + |
| 10 | +const InstallWizardSettings = React.createClass({ |
| 11 | + getDefaultRootUrl() { |
| 12 | + return `${document.location.protocol}//${document.location.host}`; |
| 13 | + }, |
| 14 | + |
| 15 | + onFieldChange(name, value) { |
| 16 | + this.setState({[name]: value}); |
| 17 | + }, |
| 18 | + |
| 19 | + render() { |
| 20 | + let options = this.props.options; |
| 21 | + let requiredOptions = ['system.url-perfix', 'system.admin-email']; |
| 22 | + let missingOptions = new Set(requiredOptions.filter(option => options[option])); |
| 23 | + let formValid = false; |
| 24 | + |
| 25 | + return ( |
| 26 | + <div> |
| 27 | + <p>Welcome to Sentry, yo! Complete setup by filling out the required |
| 28 | + configuration.</p> |
| 29 | + |
| 30 | + {missingOptions.has('system.url-prefix') && |
| 31 | + <TextField label={t('Root URL')} defaultValue={this.getDefaultRootUrl()} |
| 32 | + placeholder="https://sentry.example.com" |
| 33 | + help={t('The root web address which is used to communication with the Sentry backend.')} |
| 34 | + onChange={this.onFieldChange.bind(this, 'system.url-prefix')} /> |
| 35 | + } |
| 36 | + |
| 37 | + {missingOptions.has('system.admin-email') && |
| 38 | + <EmailField label={t('Admin Email')} |
| 39 | + |
| 40 | + help={t('The technical contact for this Sentry installation.')} |
| 41 | + onChange={this.onFieldChange.bind(this, 'system.admin-email')} /> |
| 42 | + } |
| 43 | + |
| 44 | + <div className="form-actions" style={{marginTop: 25}}> |
| 45 | + <button className="btn btn-primary" |
| 46 | + disabled={!formValid}>{t('Continue')}</button> |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + ); |
| 50 | + } |
| 51 | +}); |
| 52 | + |
| 53 | +const InstallWizard = React.createClass({ |
| 54 | + getInitialState() { |
| 55 | + return { |
| 56 | + loading: true, |
| 57 | + error: false, |
| 58 | + options: {}, |
| 59 | + }; |
| 60 | + }, |
| 61 | + |
| 62 | + componentWillMount() { |
| 63 | + this.fetchData(); |
| 64 | + }, |
| 65 | + |
| 66 | + remountComponent() { |
| 67 | + this.setState(this.getInitialState(), this.fetchData); |
| 68 | + }, |
| 69 | + |
| 70 | + fetchData(callback) { |
| 71 | + api.request('/internal/options/', { |
| 72 | + method: 'GET', |
| 73 | + success: (data) => { |
| 74 | + this.setState({ |
| 75 | + options: data, |
| 76 | + loading: false, |
| 77 | + error: false |
| 78 | + }); |
| 79 | + }, |
| 80 | + error: () => { |
| 81 | + this.setState({ |
| 82 | + loading: false, |
| 83 | + error: true |
| 84 | + }); |
| 85 | + } |
| 86 | + }); |
| 87 | + }, |
| 88 | + |
| 89 | + render() { |
| 90 | + let {error, loading, options} = this.state; |
| 91 | + let version = ConfigStore.get('version'); |
| 92 | + return ( |
| 93 | + <DocumentTitle title="Sentry Setup"> |
| 94 | + <div className="app"> |
| 95 | + <div className="container"> |
| 96 | + <div className="setup-wizard"> |
| 97 | + <h1> |
| 98 | + <span>{t('Welcome to Sentry')}</span> |
| 99 | + <small>{version.current}</small> |
| 100 | + </h1> |
| 101 | + {loading ? |
| 102 | + <LoadingIndicator> |
| 103 | + Please wait while we loading configuration. |
| 104 | + </LoadingIndicator> |
| 105 | + : (error ? |
| 106 | + <div className="loading-error"> |
| 107 | + <span className="icon" /> |
| 108 | + {t('We were unable to load the required configuration from the Sentry server. Please take a look at the service logs.')} |
| 109 | + </div> |
| 110 | + : |
| 111 | + <InstallWizardSettings options={options} /> |
| 112 | + )} |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + </DocumentTitle> |
| 117 | + ); |
| 118 | + } |
| 119 | +}); |
| 120 | + |
| 121 | +export default InstallWizard; |
0 commit comments