|
@@ -1,441 +1,441 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
3
|
3
|
import * as React from 'react';
|
4
|
|
-import {Button, Caption, Card, Headline, Subheading, withTheme} from 'react-native-paper';
|
5
|
|
-import {StackNavigationProp} from "@react-navigation/stack";
|
6
|
|
-import type {CustomTheme} from "../../../managers/ThemeManager";
|
7
|
|
-import type {Device} from "./EquipmentListScreen";
|
8
|
|
-import {BackHandler, View} from "react-native";
|
9
|
|
-import * as Animatable from "react-native-animatable";
|
10
|
|
-import i18n from "i18n-js";
|
11
|
|
-import {CalendarList} from "react-native-calendars";
|
12
|
|
-import LoadingConfirmDialog from "../../../components/Dialogs/LoadingConfirmDialog";
|
13
|
|
-import ErrorDialog from "../../../components/Dialogs/ErrorDialog";
|
14
|
4
|
import {
|
15
|
|
- generateMarkedDates,
|
16
|
|
- getFirstEquipmentAvailability,
|
17
|
|
- getISODate,
|
18
|
|
- getRelativeDateString,
|
19
|
|
- getValidRange,
|
20
|
|
- isEquipmentAvailable
|
21
|
|
-} from "../../../utils/EquipmentBooking";
|
22
|
|
-import ConnectionManager from "../../../managers/ConnectionManager";
|
23
|
|
-import CollapsibleScrollView from "../../../components/Collapsible/CollapsibleScrollView";
|
24
|
|
-
|
25
|
|
-type Props = {
|
26
|
|
- navigation: StackNavigationProp,
|
27
|
|
- route: {
|
28
|
|
- params?: {
|
29
|
|
- item?: Device,
|
30
|
|
- },
|
|
5
|
+ Button,
|
|
6
|
+ Caption,
|
|
7
|
+ Card,
|
|
8
|
+ Headline,
|
|
9
|
+ Subheading,
|
|
10
|
+ withTheme,
|
|
11
|
+} from 'react-native-paper';
|
|
12
|
+import {StackNavigationProp} from '@react-navigation/stack';
|
|
13
|
+import {BackHandler, View} from 'react-native';
|
|
14
|
+import * as Animatable from 'react-native-animatable';
|
|
15
|
+import i18n from 'i18n-js';
|
|
16
|
+import {CalendarList} from 'react-native-calendars';
|
|
17
|
+import type {DeviceType} from './EquipmentListScreen';
|
|
18
|
+import type {CustomTheme} from '../../../managers/ThemeManager';
|
|
19
|
+import LoadingConfirmDialog from '../../../components/Dialogs/LoadingConfirmDialog';
|
|
20
|
+import ErrorDialog from '../../../components/Dialogs/ErrorDialog';
|
|
21
|
+import {
|
|
22
|
+ generateMarkedDates,
|
|
23
|
+ getFirstEquipmentAvailability,
|
|
24
|
+ getISODate,
|
|
25
|
+ getRelativeDateString,
|
|
26
|
+ getValidRange,
|
|
27
|
+ isEquipmentAvailable,
|
|
28
|
+} from '../../../utils/EquipmentBooking';
|
|
29
|
+import ConnectionManager from '../../../managers/ConnectionManager';
|
|
30
|
+import CollapsibleScrollView from '../../../components/Collapsible/CollapsibleScrollView';
|
|
31
|
+
|
|
32
|
+type PropsType = {
|
|
33
|
+ navigation: StackNavigationProp,
|
|
34
|
+ route: {
|
|
35
|
+ params?: {
|
|
36
|
+ item?: DeviceType,
|
31
|
37
|
},
|
32
|
|
- theme: CustomTheme,
|
33
|
|
-}
|
|
38
|
+ },
|
|
39
|
+ theme: CustomTheme,
|
|
40
|
+};
|
34
|
41
|
|
35
|
|
-type State = {
|
36
|
|
- dialogVisible: boolean,
|
37
|
|
- errorDialogVisible: boolean,
|
38
|
|
- markedDates: { [key: string]: { startingDay: boolean, endingDay: boolean, color: string } },
|
39
|
|
- currentError: number,
|
40
|
|
-}
|
|
42
|
+export type MarkedDatesObjectType = {
|
|
43
|
+ [key: string]: {startingDay: boolean, endingDay: boolean, color: string},
|
|
44
|
+};
|
41
|
45
|
|
42
|
|
-class EquipmentRentScreen extends React.Component<Props, State> {
|
|
46
|
+type StateType = {
|
|
47
|
+ dialogVisible: boolean,
|
|
48
|
+ errorDialogVisible: boolean,
|
|
49
|
+ markedDates: MarkedDatesObjectType,
|
|
50
|
+ currentError: number,
|
|
51
|
+};
|
43
|
52
|
|
44
|
|
- state = {
|
45
|
|
- dialogVisible: false,
|
46
|
|
- errorDialogVisible: false,
|
47
|
|
- markedDates: {},
|
48
|
|
- currentError: 0,
|
49
|
|
- }
|
|
53
|
+class EquipmentRentScreen extends React.Component<PropsType, StateType> {
|
|
54
|
+ item: DeviceType | null;
|
50
|
55
|
|
51
|
|
- item: Device | null;
|
52
|
|
- bookedDates: Array<string>;
|
|
56
|
+ bookedDates: Array<string>;
|
53
|
57
|
|
54
|
|
- bookRef: { current: null | Animatable.View }
|
55
|
|
- canBookEquipment: boolean;
|
|
58
|
+ bookRef: {current: null | Animatable.View};
|
56
|
59
|
|
57
|
|
- lockedDates: { [key: string]: { startingDay: boolean, endingDay: boolean, color: string } }
|
|
60
|
+ canBookEquipment: boolean;
|
58
|
61
|
|
59
|
|
- constructor(props: Props) {
|
60
|
|
- super(props);
|
61
|
|
- this.resetSelection();
|
62
|
|
- this.bookRef = React.createRef();
|
63
|
|
- this.canBookEquipment = false;
|
64
|
|
- this.bookedDates = [];
|
65
|
|
- if (this.props.route.params != null) {
|
66
|
|
- if (this.props.route.params.item != null)
|
67
|
|
- this.item = this.props.route.params.item;
|
68
|
|
- else
|
69
|
|
- this.item = null;
|
70
|
|
- }
|
71
|
|
- const item = this.item;
|
72
|
|
- if (item != null) {
|
73
|
|
- this.lockedDates = {};
|
74
|
|
- for (let i = 0; i < item.booked_at.length; i++) {
|
75
|
|
- const range = getValidRange(new Date(item.booked_at[i].begin), new Date(item.booked_at[i].end), null);
|
76
|
|
- this.lockedDates = {
|
77
|
|
- ...this.lockedDates,
|
78
|
|
- ...generateMarkedDates(
|
79
|
|
- false,
|
80
|
|
- this.props.theme,
|
81
|
|
- range
|
82
|
|
- )
|
83
|
|
- };
|
84
|
|
- }
|
85
|
|
- }
|
86
|
|
-
|
87
|
|
- }
|
88
|
|
-
|
89
|
|
- /**
|
90
|
|
- * Captures focus and blur events to hook on android back button
|
91
|
|
- */
|
92
|
|
- componentDidMount() {
|
93
|
|
- this.props.navigation.addListener(
|
94
|
|
- 'focus',
|
95
|
|
- () =>
|
96
|
|
- BackHandler.addEventListener(
|
97
|
|
- 'hardwareBackPress',
|
98
|
|
- this.onBackButtonPressAndroid
|
99
|
|
- )
|
100
|
|
- );
|
101
|
|
- this.props.navigation.addListener(
|
102
|
|
- 'blur',
|
103
|
|
- () =>
|
104
|
|
- BackHandler.removeEventListener(
|
105
|
|
- 'hardwareBackPress',
|
106
|
|
- this.onBackButtonPressAndroid
|
107
|
|
- )
|
108
|
|
- );
|
109
|
|
- }
|
|
62
|
+ lockedDates: {
|
|
63
|
+ [key: string]: {startingDay: boolean, endingDay: boolean, color: string},
|
|
64
|
+ };
|
110
|
65
|
|
111
|
|
- /**
|
112
|
|
- * Overrides default android back button behaviour to deselect date if any is selected.
|
113
|
|
- *
|
114
|
|
- * @return {boolean}
|
115
|
|
- */
|
116
|
|
- onBackButtonPressAndroid = () => {
|
117
|
|
- if (this.bookedDates.length > 0) {
|
118
|
|
- this.resetSelection();
|
119
|
|
- this.updateMarkedSelection();
|
120
|
|
- return true;
|
121
|
|
- } else
|
122
|
|
- return false;
|
|
66
|
+ constructor(props: PropsType) {
|
|
67
|
+ super(props);
|
|
68
|
+ this.state = {
|
|
69
|
+ dialogVisible: false,
|
|
70
|
+ errorDialogVisible: false,
|
|
71
|
+ markedDates: {},
|
|
72
|
+ currentError: 0,
|
123
|
73
|
};
|
124
|
|
-
|
125
|
|
- /**
|
126
|
|
- * Selects a new date on the calendar.
|
127
|
|
- * If both start and end dates are already selected, unselect all.
|
128
|
|
- *
|
129
|
|
- * @param day The day selected
|
130
|
|
- */
|
131
|
|
- selectNewDate = (day: { dateString: string, day: number, month: number, timestamp: number, year: number }) => {
|
132
|
|
- const selected = new Date(day.dateString);
|
133
|
|
- const start = this.getBookStartDate();
|
134
|
|
-
|
135
|
|
- if (!(this.lockedDates.hasOwnProperty(day.dateString))) {
|
136
|
|
- if (start === null) {
|
137
|
|
- this.updateSelectionRange(selected, selected);
|
138
|
|
- this.enableBooking();
|
139
|
|
- } else if (start.getTime() === selected.getTime()) {
|
140
|
|
- this.resetSelection();
|
141
|
|
- } else if (this.bookedDates.length === 1) {
|
142
|
|
- this.updateSelectionRange(start, selected);
|
143
|
|
- this.enableBooking();
|
144
|
|
- } else
|
145
|
|
- this.resetSelection();
|
146
|
|
- this.updateMarkedSelection();
|
147
|
|
- }
|
148
|
|
- }
|
149
|
|
-
|
150
|
|
- updateSelectionRange(start: Date, end: Date) {
|
151
|
|
- this.bookedDates = getValidRange(start, end, this.item);
|
152
|
|
- }
|
153
|
|
-
|
154
|
|
- updateMarkedSelection() {
|
155
|
|
- this.setState({
|
156
|
|
- markedDates: generateMarkedDates(
|
157
|
|
- true,
|
158
|
|
- this.props.theme,
|
159
|
|
- this.bookedDates
|
160
|
|
- ),
|
161
|
|
- });
|
162
|
|
- }
|
163
|
|
-
|
164
|
|
- enableBooking() {
|
165
|
|
- if (!this.canBookEquipment) {
|
166
|
|
- this.showBookButton();
|
167
|
|
- this.canBookEquipment = true;
|
168
|
|
- }
|
169
|
|
- }
|
170
|
|
-
|
171
|
|
- resetSelection() {
|
172
|
|
- if (this.canBookEquipment)
|
173
|
|
- this.hideBookButton();
|
174
|
|
- this.canBookEquipment = false;
|
175
|
|
- this.bookedDates = [];
|
|
74
|
+ this.resetSelection();
|
|
75
|
+ this.bookRef = React.createRef();
|
|
76
|
+ this.canBookEquipment = false;
|
|
77
|
+ this.bookedDates = [];
|
|
78
|
+ if (props.route.params != null) {
|
|
79
|
+ if (props.route.params.item != null) this.item = props.route.params.item;
|
|
80
|
+ else this.item = null;
|
176
|
81
|
}
|
177
|
|
-
|
178
|
|
- /**
|
179
|
|
- * Shows the book button by plying a fade animation
|
180
|
|
- */
|
181
|
|
- showBookButton() {
|
182
|
|
- if (this.bookRef.current != null) {
|
183
|
|
- this.bookRef.current.fadeInUp(500);
|
184
|
|
- }
|
185
|
|
- }
|
186
|
|
-
|
187
|
|
- /**
|
188
|
|
- * Hides the book button by plying a fade animation
|
189
|
|
- */
|
190
|
|
- hideBookButton() {
|
191
|
|
- if (this.bookRef.current != null) {
|
192
|
|
- this.bookRef.current.fadeOutDown(500);
|
193
|
|
- }
|
194
|
|
- }
|
195
|
|
-
|
196
|
|
- showDialog = () => {
|
197
|
|
- this.setState({dialogVisible: true});
|
198
|
|
- }
|
199
|
|
-
|
200
|
|
- showErrorDialog = (error: number) => {
|
201
|
|
- this.setState({
|
202
|
|
- errorDialogVisible: true,
|
203
|
|
- currentError: error,
|
204
|
|
- });
|
|
82
|
+ const {item} = this;
|
|
83
|
+ if (item != null) {
|
|
84
|
+ this.lockedDates = {};
|
|
85
|
+ item.booked_at.forEach((date: {begin: string, end: string}) => {
|
|
86
|
+ const range = getValidRange(
|
|
87
|
+ new Date(date.begin),
|
|
88
|
+ new Date(date.end),
|
|
89
|
+ null,
|
|
90
|
+ );
|
|
91
|
+ this.lockedDates = {
|
|
92
|
+ ...this.lockedDates,
|
|
93
|
+ ...generateMarkedDates(false, props.theme, range),
|
|
94
|
+ };
|
|
95
|
+ });
|
205
|
96
|
}
|
206
|
|
-
|
207
|
|
- onDialogDismiss = () => {
|
208
|
|
- this.setState({dialogVisible: false});
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ /**
|
|
100
|
+ * Captures focus and blur events to hook on android back button
|
|
101
|
+ */
|
|
102
|
+ componentDidMount() {
|
|
103
|
+ const {navigation} = this.props;
|
|
104
|
+ navigation.addListener('focus', () => {
|
|
105
|
+ BackHandler.addEventListener(
|
|
106
|
+ 'hardwareBackPress',
|
|
107
|
+ this.onBackButtonPressAndroid,
|
|
108
|
+ );
|
|
109
|
+ });
|
|
110
|
+ navigation.addListener('blur', () => {
|
|
111
|
+ BackHandler.removeEventListener(
|
|
112
|
+ 'hardwareBackPress',
|
|
113
|
+ this.onBackButtonPressAndroid,
|
|
114
|
+ );
|
|
115
|
+ });
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+ /**
|
|
119
|
+ * Overrides default android back button behaviour to deselect date if any is selected.
|
|
120
|
+ *
|
|
121
|
+ * @return {boolean}
|
|
122
|
+ */
|
|
123
|
+ onBackButtonPressAndroid = (): boolean => {
|
|
124
|
+ if (this.bookedDates.length > 0) {
|
|
125
|
+ this.resetSelection();
|
|
126
|
+ this.updateMarkedSelection();
|
|
127
|
+ return true;
|
209
|
128
|
}
|
210
|
|
-
|
211
|
|
- onErrorDialogDismiss = () => {
|
212
|
|
- this.setState({errorDialogVisible: false});
|
|
129
|
+ return false;
|
|
130
|
+ };
|
|
131
|
+
|
|
132
|
+ onDialogDismiss = () => {
|
|
133
|
+ this.setState({dialogVisible: false});
|
|
134
|
+ };
|
|
135
|
+
|
|
136
|
+ onErrorDialogDismiss = () => {
|
|
137
|
+ this.setState({errorDialogVisible: false});
|
|
138
|
+ };
|
|
139
|
+
|
|
140
|
+ /**
|
|
141
|
+ * Sends the selected data to the server and waits for a response.
|
|
142
|
+ * If the request is a success, navigate to the recap screen.
|
|
143
|
+ * If it is an error, display the error to the user.
|
|
144
|
+ *
|
|
145
|
+ * @returns {Promise<void>}
|
|
146
|
+ */
|
|
147
|
+ onDialogAccept = (): Promise<void> => {
|
|
148
|
+ return new Promise((resolve: () => void) => {
|
|
149
|
+ const {item, props} = this;
|
|
150
|
+ const start = this.getBookStartDate();
|
|
151
|
+ const end = this.getBookEndDate();
|
|
152
|
+ if (item != null && start != null && end != null) {
|
|
153
|
+ ConnectionManager.getInstance()
|
|
154
|
+ .authenticatedRequest('location/booking', {
|
|
155
|
+ device: item.id,
|
|
156
|
+ begin: getISODate(start),
|
|
157
|
+ end: getISODate(end),
|
|
158
|
+ })
|
|
159
|
+ .then(() => {
|
|
160
|
+ this.onDialogDismiss();
|
|
161
|
+ props.navigation.replace('equipment-confirm', {
|
|
162
|
+ item: this.item,
|
|
163
|
+ dates: [getISODate(start), getISODate(end)],
|
|
164
|
+ });
|
|
165
|
+ resolve();
|
|
166
|
+ })
|
|
167
|
+ .catch((error: number) => {
|
|
168
|
+ this.onDialogDismiss();
|
|
169
|
+ this.showErrorDialog(error);
|
|
170
|
+ resolve();
|
|
171
|
+ });
|
|
172
|
+ } else {
|
|
173
|
+ this.onDialogDismiss();
|
|
174
|
+ resolve();
|
|
175
|
+ }
|
|
176
|
+ });
|
|
177
|
+ };
|
|
178
|
+
|
|
179
|
+ getBookStartDate(): Date | null {
|
|
180
|
+ return this.bookedDates.length > 0 ? new Date(this.bookedDates[0]) : null;
|
|
181
|
+ }
|
|
182
|
+
|
|
183
|
+ getBookEndDate(): Date | null {
|
|
184
|
+ const {length} = this.bookedDates;
|
|
185
|
+ return length > 0 ? new Date(this.bookedDates[length - 1]) : null;
|
|
186
|
+ }
|
|
187
|
+
|
|
188
|
+ /**
|
|
189
|
+ * Selects a new date on the calendar.
|
|
190
|
+ * If both start and end dates are already selected, unselect all.
|
|
191
|
+ *
|
|
192
|
+ * @param day The day selected
|
|
193
|
+ */
|
|
194
|
+ selectNewDate = (day: {
|
|
195
|
+ dateString: string,
|
|
196
|
+ day: number,
|
|
197
|
+ month: number,
|
|
198
|
+ timestamp: number,
|
|
199
|
+ year: number,
|
|
200
|
+ }) => {
|
|
201
|
+ const selected = new Date(day.dateString);
|
|
202
|
+ const start = this.getBookStartDate();
|
|
203
|
+
|
|
204
|
+ if (!this.lockedDates[day.dateString] != null) {
|
|
205
|
+ if (start === null) {
|
|
206
|
+ this.updateSelectionRange(selected, selected);
|
|
207
|
+ this.enableBooking();
|
|
208
|
+ } else if (start.getTime() === selected.getTime()) {
|
|
209
|
+ this.resetSelection();
|
|
210
|
+ } else if (this.bookedDates.length === 1) {
|
|
211
|
+ this.updateSelectionRange(start, selected);
|
|
212
|
+ this.enableBooking();
|
|
213
|
+ } else this.resetSelection();
|
|
214
|
+ this.updateMarkedSelection();
|
213
|
215
|
}
|
214
|
|
-
|
215
|
|
- /**
|
216
|
|
- * Sends the selected data to the server and waits for a response.
|
217
|
|
- * If the request is a success, navigate to the recap screen.
|
218
|
|
- * If it is an error, display the error to the user.
|
219
|
|
- *
|
220
|
|
- * @returns {Promise<R>}
|
221
|
|
- */
|
222
|
|
- onDialogAccept = () => {
|
223
|
|
- return new Promise((resolve) => {
|
224
|
|
- const item = this.item;
|
225
|
|
- const start = this.getBookStartDate();
|
226
|
|
- const end = this.getBookEndDate();
|
227
|
|
- if (item != null && start != null && end != null) {
|
228
|
|
- console.log({
|
229
|
|
- "device": item.id,
|
230
|
|
- "begin": getISODate(start),
|
231
|
|
- "end": getISODate(end),
|
232
|
|
- })
|
233
|
|
- ConnectionManager.getInstance().authenticatedRequest(
|
234
|
|
- "location/booking",
|
235
|
|
- {
|
236
|
|
- "device": item.id,
|
237
|
|
- "begin": getISODate(start),
|
238
|
|
- "end": getISODate(end),
|
239
|
|
- })
|
240
|
|
- .then(() => {
|
241
|
|
- this.onDialogDismiss();
|
242
|
|
- this.props.navigation.replace("equipment-confirm", {
|
243
|
|
- item: this.item,
|
244
|
|
- dates: [getISODate(start), getISODate(end)]
|
245
|
|
- });
|
246
|
|
- resolve();
|
247
|
|
- })
|
248
|
|
- .catch((error: number) => {
|
249
|
|
- this.onDialogDismiss();
|
250
|
|
- this.showErrorDialog(error);
|
251
|
|
- resolve();
|
252
|
|
- });
|
253
|
|
- } else {
|
254
|
|
- this.onDialogDismiss();
|
255
|
|
- resolve();
|
256
|
|
- }
|
257
|
|
- });
|
|
216
|
+ };
|
|
217
|
+
|
|
218
|
+ showErrorDialog = (error: number) => {
|
|
219
|
+ this.setState({
|
|
220
|
+ errorDialogVisible: true,
|
|
221
|
+ currentError: error,
|
|
222
|
+ });
|
|
223
|
+ };
|
|
224
|
+
|
|
225
|
+ showDialog = () => {
|
|
226
|
+ this.setState({dialogVisible: true});
|
|
227
|
+ };
|
|
228
|
+
|
|
229
|
+ /**
|
|
230
|
+ * Shows the book button by plying a fade animation
|
|
231
|
+ */
|
|
232
|
+ showBookButton() {
|
|
233
|
+ if (this.bookRef.current != null) {
|
|
234
|
+ this.bookRef.current.fadeInUp(500);
|
258
|
235
|
}
|
259
|
|
-
|
260
|
|
- getBookStartDate() {
|
261
|
|
- return this.bookedDates.length > 0 ? new Date(this.bookedDates[0]) : null;
|
|
236
|
+ }
|
|
237
|
+
|
|
238
|
+ /**
|
|
239
|
+ * Hides the book button by plying a fade animation
|
|
240
|
+ */
|
|
241
|
+ hideBookButton() {
|
|
242
|
+ if (this.bookRef.current != null) {
|
|
243
|
+ this.bookRef.current.fadeOutDown(500);
|
262
|
244
|
}
|
|
245
|
+ }
|
263
|
246
|
|
264
|
|
- getBookEndDate() {
|
265
|
|
- const length = this.bookedDates.length;
|
266
|
|
- return length > 0 ? new Date(this.bookedDates[length - 1]) : null;
|
|
247
|
+ enableBooking() {
|
|
248
|
+ if (!this.canBookEquipment) {
|
|
249
|
+ this.showBookButton();
|
|
250
|
+ this.canBookEquipment = true;
|
267
|
251
|
}
|
268
|
|
-
|
269
|
|
- render() {
|
270
|
|
- const item = this.item;
|
271
|
|
- const start = this.getBookStartDate();
|
272
|
|
- const end = this.getBookEndDate();
|
273
|
|
-
|
274
|
|
- if (item != null) {
|
275
|
|
- const isAvailable = isEquipmentAvailable(item);
|
276
|
|
- const firstAvailability = getFirstEquipmentAvailability(item);
|
277
|
|
- return (
|
|
252
|
+ }
|
|
253
|
+
|
|
254
|
+ resetSelection() {
|
|
255
|
+ if (this.canBookEquipment) this.hideBookButton();
|
|
256
|
+ this.canBookEquipment = false;
|
|
257
|
+ this.bookedDates = [];
|
|
258
|
+ }
|
|
259
|
+
|
|
260
|
+ updateSelectionRange(start: Date, end: Date) {
|
|
261
|
+ this.bookedDates = getValidRange(start, end, this.item);
|
|
262
|
+ }
|
|
263
|
+
|
|
264
|
+ updateMarkedSelection() {
|
|
265
|
+ const {theme} = this.props;
|
|
266
|
+ this.setState({
|
|
267
|
+ markedDates: generateMarkedDates(true, theme, this.bookedDates),
|
|
268
|
+ });
|
|
269
|
+ }
|
|
270
|
+
|
|
271
|
+ render(): React.Node {
|
|
272
|
+ const {item, props, state} = this;
|
|
273
|
+ const start = this.getBookStartDate();
|
|
274
|
+ const end = this.getBookEndDate();
|
|
275
|
+ let subHeadingText;
|
|
276
|
+ if (start == null) subHeadingText = i18n.t('screens.equipment.booking');
|
|
277
|
+ else if (end != null && start.getTime() !== end.getTime())
|
|
278
|
+ subHeadingText = i18n.t('screens.equipment.bookingPeriod', {
|
|
279
|
+ begin: getRelativeDateString(start),
|
|
280
|
+ end: getRelativeDateString(end),
|
|
281
|
+ });
|
|
282
|
+ else
|
|
283
|
+ i18n.t('screens.equipment.bookingDay', {
|
|
284
|
+ date: getRelativeDateString(start),
|
|
285
|
+ });
|
|
286
|
+ if (item != null) {
|
|
287
|
+ const isAvailable = isEquipmentAvailable(item);
|
|
288
|
+ const firstAvailability = getFirstEquipmentAvailability(item);
|
|
289
|
+ return (
|
|
290
|
+ <View style={{flex: 1}}>
|
|
291
|
+ <CollapsibleScrollView>
|
|
292
|
+ <Card style={{margin: 5}}>
|
|
293
|
+ <Card.Content>
|
278
|
294
|
<View style={{flex: 1}}>
|
279
|
|
- <CollapsibleScrollView>
|
280
|
|
- <Card style={{margin: 5}}>
|
281
|
|
- <Card.Content>
|
282
|
|
- <View style={{flex: 1}}>
|
283
|
|
- <View style={{
|
284
|
|
- marginLeft: "auto",
|
285
|
|
- marginRight: "auto",
|
286
|
|
- flexDirection: "row",
|
287
|
|
- flexWrap: "wrap",
|
288
|
|
- }}>
|
289
|
|
- <Headline style={{textAlign: "center"}}>
|
290
|
|
- {item.name}
|
291
|
|
- </Headline>
|
292
|
|
- <Caption style={{
|
293
|
|
- textAlign: "center",
|
294
|
|
- lineHeight: 35,
|
295
|
|
- marginLeft: 10,
|
296
|
|
- }}>
|
297
|
|
- ({i18n.t('screens.equipment.bail', {cost: item.caution})})
|
298
|
|
- </Caption>
|
299
|
|
- </View>
|
300
|
|
- </View>
|
301
|
|
-
|
302
|
|
- <Button
|
303
|
|
- icon={isAvailable ? "check-circle-outline" : "update"}
|
304
|
|
- color={isAvailable ? this.props.theme.colors.success : this.props.theme.colors.primary}
|
305
|
|
- mode="text"
|
306
|
|
- >
|
307
|
|
- {i18n.t('screens.equipment.available', {date: getRelativeDateString(firstAvailability)})}
|
308
|
|
- </Button>
|
309
|
|
- <Subheading style={{
|
310
|
|
- textAlign: "center",
|
311
|
|
- marginBottom: 10,
|
312
|
|
- minHeight: 50
|
313
|
|
- }}>
|
314
|
|
- {
|
315
|
|
- start == null
|
316
|
|
- ? i18n.t('screens.equipment.booking')
|
317
|
|
- : end != null && start.getTime() !== end.getTime()
|
318
|
|
- ? i18n.t('screens.equipment.bookingPeriod', {
|
319
|
|
- begin: getRelativeDateString(start),
|
320
|
|
- end: getRelativeDateString(end)
|
321
|
|
- })
|
322
|
|
- : i18n.t('screens.equipment.bookingDay', {
|
323
|
|
- date: getRelativeDateString(start)
|
324
|
|
- })
|
325
|
|
- }
|
326
|
|
-
|
327
|
|
- </Subheading>
|
328
|
|
- </Card.Content>
|
329
|
|
- </Card>
|
330
|
|
- <CalendarList
|
331
|
|
- // Minimum date that can be selected, dates before minDate will be grayed out. Default = undefined
|
332
|
|
- minDate={new Date()}
|
333
|
|
- // Max amount of months allowed to scroll to the past. Default = 50
|
334
|
|
- pastScrollRange={0}
|
335
|
|
- // Max amount of months allowed to scroll to the future. Default = 50
|
336
|
|
- futureScrollRange={3}
|
337
|
|
- // Enable horizontal scrolling, default = false
|
338
|
|
- horizontal={true}
|
339
|
|
- // Enable paging on horizontal, default = false
|
340
|
|
- pagingEnabled={true}
|
341
|
|
- // Handler which gets executed on day press. Default = undefined
|
342
|
|
- onDayPress={this.selectNewDate}
|
343
|
|
- // If firstDay=1 week starts from Monday. Note that dayNames and dayNamesShort should still start from Sunday.
|
344
|
|
- firstDay={1}
|
345
|
|
- // Disable all touch events for disabled days. can be override with disableTouchEvent in markedDates
|
346
|
|
- disableAllTouchEventsForDisabledDays={true}
|
347
|
|
- // Hide month navigation arrows.
|
348
|
|
- hideArrows={false}
|
349
|
|
- // Date marking style [simple/period/multi-dot/custom]. Default = 'simple'
|
350
|
|
- markingType={'period'}
|
351
|
|
- markedDates={{...this.lockedDates, ...this.state.markedDates}}
|
352
|
|
-
|
353
|
|
- theme={{
|
354
|
|
- backgroundColor: this.props.theme.colors.agendaBackgroundColor,
|
355
|
|
- calendarBackground: this.props.theme.colors.background,
|
356
|
|
- textSectionTitleColor: this.props.theme.colors.agendaDayTextColor,
|
357
|
|
- selectedDayBackgroundColor: this.props.theme.colors.primary,
|
358
|
|
- selectedDayTextColor: '#ffffff',
|
359
|
|
- todayTextColor: this.props.theme.colors.text,
|
360
|
|
- dayTextColor: this.props.theme.colors.text,
|
361
|
|
- textDisabledColor: this.props.theme.colors.agendaDayTextColor,
|
362
|
|
- dotColor: this.props.theme.colors.primary,
|
363
|
|
- selectedDotColor: '#ffffff',
|
364
|
|
- arrowColor: this.props.theme.colors.primary,
|
365
|
|
- monthTextColor: this.props.theme.colors.text,
|
366
|
|
- indicatorColor: this.props.theme.colors.primary,
|
367
|
|
- textDayFontFamily: 'monospace',
|
368
|
|
- textMonthFontFamily: 'monospace',
|
369
|
|
- textDayHeaderFontFamily: 'monospace',
|
370
|
|
- textDayFontWeight: '300',
|
371
|
|
- textMonthFontWeight: 'bold',
|
372
|
|
- textDayHeaderFontWeight: '300',
|
373
|
|
- textDayFontSize: 16,
|
374
|
|
- textMonthFontSize: 16,
|
375
|
|
- textDayHeaderFontSize: 16,
|
376
|
|
- 'stylesheet.day.period': {
|
377
|
|
- base: {
|
378
|
|
- overflow: 'hidden',
|
379
|
|
- height: 34,
|
380
|
|
- width: 34,
|
381
|
|
- alignItems: 'center',
|
382
|
|
-
|
383
|
|
- }
|
384
|
|
- }
|
385
|
|
- }}
|
386
|
|
- style={{marginBottom: 50}}
|
387
|
|
- />
|
388
|
|
- </CollapsibleScrollView>
|
389
|
|
- <LoadingConfirmDialog
|
390
|
|
- visible={this.state.dialogVisible}
|
391
|
|
- onDismiss={this.onDialogDismiss}
|
392
|
|
- onAccept={this.onDialogAccept}
|
393
|
|
- title={i18n.t('screens.equipment.dialogTitle')}
|
394
|
|
- titleLoading={i18n.t('screens.equipment.dialogTitleLoading')}
|
395
|
|
- message={i18n.t('screens.equipment.dialogMessage')}
|
396
|
|
- />
|
397
|
|
-
|
398
|
|
- <ErrorDialog
|
399
|
|
- visible={this.state.errorDialogVisible}
|
400
|
|
- onDismiss={this.onErrorDialogDismiss}
|
401
|
|
- errorCode={this.state.currentError}
|
402
|
|
- />
|
403
|
|
- <Animatable.View
|
404
|
|
- ref={this.bookRef}
|
405
|
|
- style={{
|
406
|
|
- position: "absolute",
|
407
|
|
- bottom: 0,
|
408
|
|
- left: 0,
|
409
|
|
- width: "100%",
|
410
|
|
- flex: 1,
|
411
|
|
- transform: [
|
412
|
|
- {translateY: 100},
|
413
|
|
- ]
|
414
|
|
- }}>
|
415
|
|
- <Button
|
416
|
|
- icon="bookmark-check"
|
417
|
|
- mode="contained"
|
418
|
|
- onPress={this.showDialog}
|
419
|
|
- style={{
|
420
|
|
- width: "80%",
|
421
|
|
- flex: 1,
|
422
|
|
- marginLeft: "auto",
|
423
|
|
- marginRight: "auto",
|
424
|
|
- marginBottom: 20,
|
425
|
|
- borderRadius: 10
|
426
|
|
- }}
|
427
|
|
- >
|
428
|
|
- {i18n.t('screens.equipment.bookButton')}
|
429
|
|
- </Button>
|
430
|
|
- </Animatable.View>
|
431
|
|
-
|
|
295
|
+ <View
|
|
296
|
+ style={{
|
|
297
|
+ marginLeft: 'auto',
|
|
298
|
+ marginRight: 'auto',
|
|
299
|
+ flexDirection: 'row',
|
|
300
|
+ flexWrap: 'wrap',
|
|
301
|
+ }}>
|
|
302
|
+ <Headline style={{textAlign: 'center'}}>
|
|
303
|
+ {item.name}
|
|
304
|
+ </Headline>
|
|
305
|
+ <Caption
|
|
306
|
+ style={{
|
|
307
|
+ textAlign: 'center',
|
|
308
|
+ lineHeight: 35,
|
|
309
|
+ marginLeft: 10,
|
|
310
|
+ }}>
|
|
311
|
+ ({i18n.t('screens.equipment.bail', {cost: item.caution})})
|
|
312
|
+ </Caption>
|
|
313
|
+ </View>
|
432
|
314
|
</View>
|
433
|
315
|
|
434
|
|
- )
|
435
|
|
- } else
|
436
|
|
- return <View/>;
|
|
316
|
+ <Button
|
|
317
|
+ icon={isAvailable ? 'check-circle-outline' : 'update'}
|
|
318
|
+ color={
|
|
319
|
+ isAvailable
|
|
320
|
+ ? props.theme.colors.success
|
|
321
|
+ : props.theme.colors.primary
|
|
322
|
+ }
|
|
323
|
+ mode="text">
|
|
324
|
+ {i18n.t('screens.equipment.available', {
|
|
325
|
+ date: getRelativeDateString(firstAvailability),
|
|
326
|
+ })}
|
|
327
|
+ </Button>
|
|
328
|
+ <Subheading
|
|
329
|
+ style={{
|
|
330
|
+ textAlign: 'center',
|
|
331
|
+ marginBottom: 10,
|
|
332
|
+ minHeight: 50,
|
|
333
|
+ }}>
|
|
334
|
+ {subHeadingText}
|
|
335
|
+ </Subheading>
|
|
336
|
+ </Card.Content>
|
|
337
|
+ </Card>
|
|
338
|
+ <CalendarList
|
|
339
|
+ // Minimum date that can be selected, dates before minDate will be grayed out. Default = undefined
|
|
340
|
+ minDate={new Date()}
|
|
341
|
+ // Max amount of months allowed to scroll to the past. Default = 50
|
|
342
|
+ pastScrollRange={0}
|
|
343
|
+ // Max amount of months allowed to scroll to the future. Default = 50
|
|
344
|
+ futureScrollRange={3}
|
|
345
|
+ // Enable horizontal scrolling, default = false
|
|
346
|
+ horizontal
|
|
347
|
+ // Enable paging on horizontal, default = false
|
|
348
|
+ pagingEnabled
|
|
349
|
+ // Handler which gets executed on day press. Default = undefined
|
|
350
|
+ onDayPress={this.selectNewDate}
|
|
351
|
+ // If firstDay=1 week starts from Monday. Note that dayNames and dayNamesShort should still start from Sunday.
|
|
352
|
+ firstDay={1}
|
|
353
|
+ // Disable all touch events for disabled days. can be override with disableTouchEvent in markedDates
|
|
354
|
+ disableAllTouchEventsForDisabledDays
|
|
355
|
+ // Hide month navigation arrows.
|
|
356
|
+ hideArrows={false}
|
|
357
|
+ // Date marking style [simple/period/multi-dot/custom]. Default = 'simple'
|
|
358
|
+ markingType="period"
|
|
359
|
+ markedDates={{...this.lockedDates, ...state.markedDates}}
|
|
360
|
+ theme={{
|
|
361
|
+ backgroundColor: props.theme.colors.agendaBackgroundColor,
|
|
362
|
+ calendarBackground: props.theme.colors.background,
|
|
363
|
+ textSectionTitleColor: props.theme.colors.agendaDayTextColor,
|
|
364
|
+ selectedDayBackgroundColor: props.theme.colors.primary,
|
|
365
|
+ selectedDayTextColor: '#ffffff',
|
|
366
|
+ todayTextColor: props.theme.colors.text,
|
|
367
|
+ dayTextColor: props.theme.colors.text,
|
|
368
|
+ textDisabledColor: props.theme.colors.agendaDayTextColor,
|
|
369
|
+ dotColor: props.theme.colors.primary,
|
|
370
|
+ selectedDotColor: '#ffffff',
|
|
371
|
+ arrowColor: props.theme.colors.primary,
|
|
372
|
+ monthTextColor: props.theme.colors.text,
|
|
373
|
+ indicatorColor: props.theme.colors.primary,
|
|
374
|
+ textDayFontFamily: 'monospace',
|
|
375
|
+ textMonthFontFamily: 'monospace',
|
|
376
|
+ textDayHeaderFontFamily: 'monospace',
|
|
377
|
+ textDayFontWeight: '300',
|
|
378
|
+ textMonthFontWeight: 'bold',
|
|
379
|
+ textDayHeaderFontWeight: '300',
|
|
380
|
+ textDayFontSize: 16,
|
|
381
|
+ textMonthFontSize: 16,
|
|
382
|
+ textDayHeaderFontSize: 16,
|
|
383
|
+ 'stylesheet.day.period': {
|
|
384
|
+ base: {
|
|
385
|
+ overflow: 'hidden',
|
|
386
|
+ height: 34,
|
|
387
|
+ width: 34,
|
|
388
|
+ alignItems: 'center',
|
|
389
|
+ },
|
|
390
|
+ },
|
|
391
|
+ }}
|
|
392
|
+ style={{marginBottom: 50}}
|
|
393
|
+ />
|
|
394
|
+ </CollapsibleScrollView>
|
|
395
|
+ <LoadingConfirmDialog
|
|
396
|
+ visible={state.dialogVisible}
|
|
397
|
+ onDismiss={this.onDialogDismiss}
|
|
398
|
+ onAccept={this.onDialogAccept}
|
|
399
|
+ title={i18n.t('screens.equipment.dialogTitle')}
|
|
400
|
+ titleLoading={i18n.t('screens.equipment.dialogTitleLoading')}
|
|
401
|
+ message={i18n.t('screens.equipment.dialogMessage')}
|
|
402
|
+ />
|
|
403
|
+
|
|
404
|
+ <ErrorDialog
|
|
405
|
+ visible={state.errorDialogVisible}
|
|
406
|
+ onDismiss={this.onErrorDialogDismiss}
|
|
407
|
+ errorCode={state.currentError}
|
|
408
|
+ />
|
|
409
|
+ <Animatable.View
|
|
410
|
+ ref={this.bookRef}
|
|
411
|
+ style={{
|
|
412
|
+ position: 'absolute',
|
|
413
|
+ bottom: 0,
|
|
414
|
+ left: 0,
|
|
415
|
+ width: '100%',
|
|
416
|
+ flex: 1,
|
|
417
|
+ transform: [{translateY: 100}],
|
|
418
|
+ }}>
|
|
419
|
+ <Button
|
|
420
|
+ icon="bookmark-check"
|
|
421
|
+ mode="contained"
|
|
422
|
+ onPress={this.showDialog}
|
|
423
|
+ style={{
|
|
424
|
+ width: '80%',
|
|
425
|
+ flex: 1,
|
|
426
|
+ marginLeft: 'auto',
|
|
427
|
+ marginRight: 'auto',
|
|
428
|
+ marginBottom: 20,
|
|
429
|
+ borderRadius: 10,
|
|
430
|
+ }}>
|
|
431
|
+ {i18n.t('screens.equipment.bookButton')}
|
|
432
|
+ </Button>
|
|
433
|
+ </Animatable.View>
|
|
434
|
+ </View>
|
|
435
|
+ );
|
437
|
436
|
}
|
438
|
|
-
|
|
437
|
+ return null;
|
|
438
|
+ }
|
439
|
439
|
}
|
440
|
440
|
|
441
|
441
|
export default withTheme(EquipmentRentScreen);
|