|
| 1 | +import React from "react"; |
| 2 | +import { connect } from "react-redux"; |
| 3 | + |
| 4 | +import { userActions } from "../_actions/user.actions.js"; |
| 5 | +import NavBar from "../_components/NavBar"; |
| 6 | +import SideBar from "../_components/SideBar"; |
| 7 | +import { Form } from "semantic-ui-react"; |
| 8 | +import InputTextField from "../_components/_formcomponents/InputTextField"; |
| 9 | +import DropdownSelect from "../_components/_formcomponents/DropdownSelect"; |
| 10 | + |
| 11 | +class Database extends React.Component { |
| 12 | + constructor(props) { |
| 13 | + super(props); |
| 14 | + |
| 15 | + this.state = { |
| 16 | + fields: [ |
| 17 | + { |
| 18 | + placeholder: "Resource group", |
| 19 | + name: "Resource group", |
| 20 | + input_type: "text", |
| 21 | + required: true |
| 22 | + }, |
| 23 | + { |
| 24 | + placeholder: "Server name", |
| 25 | + name: "Server name", |
| 26 | + input_type: "text", |
| 27 | + required: true |
| 28 | + }, |
| 29 | + { |
| 30 | + placeholder: "Database name", |
| 31 | + name: "Database name", |
| 32 | + input_type: "text", |
| 33 | + required: true |
| 34 | + }, |
| 35 | + { |
| 36 | + placeholder: "Location", |
| 37 | + name: "Location", |
| 38 | + input_type: "dropdown", |
| 39 | + required: true, |
| 40 | + values: [ |
| 41 | + { value: "centralus", text: "Central US" }, |
| 42 | + { value: "northus", text: "North US" } |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + placeholder: "Administrator Login", |
| 47 | + name: "Administrator Login", |
| 48 | + input_type: "text", |
| 49 | + required: true |
| 50 | + }, |
| 51 | + { |
| 52 | + placeholder: "Administrator Password", |
| 53 | + name: "Administrator Password", |
| 54 | + input_type: "text", |
| 55 | + required: true |
| 56 | + }, |
| 57 | + { |
| 58 | + placeholder: "Ex: 1.0", |
| 59 | + name: "Version", |
| 60 | + input_type: "text", |
| 61 | + required: true |
| 62 | + } |
| 63 | + ] |
| 64 | + }; |
| 65 | + |
| 66 | + this._handleChange = this._handleChange.bind(this); |
| 67 | + this.submitForm = this.submitForm.bind(this); |
| 68 | + this.changeSelectedDashboardService = this.changeSelectedDashboardService.bind( |
| 69 | + this |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + componentWillMount() { |
| 74 | + this.state.provider = localStorage.getItem("currentProvider"); |
| 75 | + } |
| 76 | + |
| 77 | + submitForm(event) { |
| 78 | + const { fields, ...inputFields } = this.state; |
| 79 | + event.preventDefault(); |
| 80 | + this.props.dispatch(userActions.createDatabase(inputFields)); |
| 81 | + } |
| 82 | + |
| 83 | + _handleChange(event, { name, value }) { |
| 84 | + this.setState({ |
| 85 | + [name]: value |
| 86 | + }); |
| 87 | + } |
| 88 | + |
| 89 | + handleServiceCreate(event) { |
| 90 | + this.setState({ showModal: false }); |
| 91 | + } |
| 92 | + |
| 93 | + handleShowSideBar() { |
| 94 | + this.setState({ |
| 95 | + showSideBar: !this.state.showSideBar |
| 96 | + }); |
| 97 | + } |
| 98 | + |
| 99 | + changeSelectedDashboardService(serviceName) { |
| 100 | + this.setState({ |
| 101 | + selectedDashboardService: serviceName |
| 102 | + }); |
| 103 | + } |
| 104 | + |
| 105 | + render() { |
| 106 | + const { fields, showSideBar, provider } = this.state; |
| 107 | + return ( |
| 108 | + <div> |
| 109 | + <NavBar |
| 110 | + handleCreateModal={() => this.handleCreateModal()} |
| 111 | + handleShowSideBar={() => this.handleShowSideBar()} |
| 112 | + /> |
| 113 | + <div style={{ margin: 20 }}> |
| 114 | + {showSideBar && ( |
| 115 | + <SideBar |
| 116 | + changeSelectedDashboardService={serviceName => |
| 117 | + this.changeSelectedDashboardService(serviceName) |
| 118 | + } |
| 119 | + /> |
| 120 | + )} |
| 121 | + <div |
| 122 | + style={{ |
| 123 | + margin: 50, |
| 124 | + width: "50%", |
| 125 | + marginLeft: showSideBar ? 250 : 0 |
| 126 | + }} |
| 127 | + > |
| 128 | + <h1> Database </h1> |
| 129 | + {provider === "azure" ? ( |
| 130 | + <Form onSubmit={this.submitForm}> |
| 131 | + {fields.map(form => { |
| 132 | + if (form.input_type === "text") { |
| 133 | + return ( |
| 134 | + <InputTextField |
| 135 | + name={form.name} |
| 136 | + placeholder={form.placeholder} |
| 137 | + required={form.required} |
| 138 | + key={form.placeholder} |
| 139 | + _handleChange={this._handleChange} |
| 140 | + /> |
| 141 | + ); |
| 142 | + } |
| 143 | + if (form.input_type === "dropdown") { |
| 144 | + return ( |
| 145 | + <DropdownSelect |
| 146 | + name={form.name} |
| 147 | + placeholder={form.placeholder} |
| 148 | + required={form.required} |
| 149 | + val={form.values} |
| 150 | + key={form.placeholder} |
| 151 | + _handleChange={this._handleChange} |
| 152 | + /> |
| 153 | + ); |
| 154 | + } |
| 155 | + })} |
| 156 | + <div |
| 157 | + class="actions" |
| 158 | + style={{ |
| 159 | + float: "right" |
| 160 | + }} |
| 161 | + > |
| 162 | + <div |
| 163 | + style={{ marginTop: "10px" }} |
| 164 | + class="ui positive right labeled icon button" |
| 165 | + onClick={this.submitForm} |
| 166 | + > |
| 167 | + Create |
| 168 | + <i class="checkmark icon" /> |
| 169 | + </div> |
| 170 | + </div> |
| 171 | + </Form> |
| 172 | + ) : ( |
| 173 | + <div> {provider} is under development</div> |
| 174 | + )} |
| 175 | + </div> |
| 176 | + </div> |
| 177 | + </div> |
| 178 | + ); |
| 179 | + } |
| 180 | +} |
| 181 | + |
| 182 | +const mapStateToProps = state => { |
| 183 | + return { |
| 184 | + users: state.users |
| 185 | + }; |
| 186 | +}; |
| 187 | + |
| 188 | +const connectedDatabase = connect(mapStateToProps)(Database); |
| 189 | +export { connectedDatabase as Database }; |
0 commit comments