-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.js
188 lines (166 loc) · 7.22 KB
/
Settings.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import React, { Component } from 'react';
import {
Table,
Button,
} from 'reactstrap';
import gql from "graphql-tag";
import { Query } from "react-apollo";
import Spinner from './Spinner';
import UpdateSettings from './UpdateSettings';
import ErrorModal from './ErrorModal';
import {
Redirect
} from "react-router-dom";
import { inject, observer } from "mobx-react";
const GET_SETTINGS_GQL = gql`
query Ledgers(
$propertyId: String!) {
property(id: $propertyId) {
propertyId
eventVersion
settings {
propertyName
currencyAcronym: currency(format: ACRONYM)
currencySymbol: currency(format: SYMBOL)
memberRate
allowNonMembers
nonMemberRate
timezone
maxOutDays
minInDays
reservationReminderDaysBefore
balanceReminderIntervalDays
minBalance
}
updateSettingsConstraints {
propertyNameMin
propertyNameMax
memberRateMin
memberRateMax
nonMemberRateMin
nonMemberRateMax
minBalanceMin
minBalanceMax
maxOutDaysMin
maxOutDaysMax
minInDaysMin
minInDaysMax
reservationReminderDaysBeforeMin
reservationReminderDaysBeforeMax
balanceReminderIntervalDaysMin
balanceReminderIntervalDaysMax
}
}
}
`;
class Settings extends Component {
constructor(props) {
super(props);
this.turnOffModals = this.turnOffModals.bind(this);
this.displaySettingsForm = this.displaySettingsForm.bind(this);
this.state = {
cachedProperty: null,
showSettingsForm: false,
};
}
render() {
const propertyId = this.props.appStateStore.propertyId ? this.props.appStateStore.propertyId : null;
var property = this.state.cachedProperty
if (propertyId === null) {
return (<Redirect to="/propertyselect" />)
} else {
var info = { propertyId: propertyId };
const apolloClient = this.props.appStateStore.apolloClient;
const queryKey = this.props.appStateStore.apolloQueryKey;
return (
<Query client={apolloClient} key={queryKey} query={GET_SETTINGS_GQL} fetchPolicy='no-cache'
variables={info}>
{({ loading, error, data }) => {
if (loading) { return (<Spinner />); }
if (error) { return (<ErrorModal error={error} />); }
if (data) {
if (data.property !== undefined) {
property = data.property
}
if (property === null) {
// cache property is also null
return (<div>No data from service, please refresh and try again</div>)
}
}
return (
<div>
{error && <ErrorModal error={error} />}
<Table bordered size="sm">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">{"Property Name"}</th>
<td>{property.settings.propertyName}</td>
</tr>
<tr>
<th scope="row">{"Currency"}</th>
<td>{property.settings.currencyAcronym} ({property.settings.currencySymbol})</td>
</tr>
<tr>
<th scope="row">{"Member Rate"}</th>
<td>{property.settings.memberRate}</td>
</tr>
<tr>
<th scope="row">{"Allow Non-Members"}</th>
<td>{property.settings.allowNonMembers ? 'true' : 'false'}</td>
</tr>
<tr>
<th scope="row">{"Non-Member Rate"}</th>
<td>{property.settings.nonMemberRate}</td>
</tr>
<tr>
<th scope="row">{"Timezone"}</th>
<td>{property.settings.timezone}</td>
</tr>
<tr>
<th scope="row">{"Last Checkout"}</th>
<td>{property.settings.maxOutDays}</td>
</tr>
<tr>
<th scope="row">{"First Checkin"}</th>
<td>{property.settings.minInDays}</td>
</tr>
<tr>
<th scope="row">{"Reservation Reminder"}</th>
<td>{property.settings.reservationReminderDaysBefore}</td>
</tr>
<tr>
<th scope="row">{"Low Balance Reminder"}</th>
<td>{property.settings.balanceReminderIntervalDays}</td>
</tr>
<tr>
<th scope="row">{"Minimum Balance"}</th>
<td>{property.settings.minBalance}</td>
</tr>
</tbody>
</Table>
<UpdateSettings currentSettings={property.settings} constraints={property.updateSettingsConstraints} showform={this.state.showSettingsForm} exitModal={this.turnOffModals} />
<div className="text-center">
<Button color="primary" onClick={() => this.displaySettingsForm()}>Update Settings</Button>
</div>
</div>
)
}}
</Query>)
}
}
turnOffModals = () => {
this.setState({ showSettingsForm: false });
}
displaySettingsForm() {
this.setState({
showSettingsForm: true
});
}
}
export default inject('appStateStore')(observer(Settings))