@plusscommunities/pluss-maintenance-app-forms 7.0.20 → 7.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/module/actions/JobActions.js +4 -4
  2. package/dist/module/actions/JobActions.js.map +1 -1
  3. package/dist/module/actions/index.js +1 -1
  4. package/dist/module/actions/index.js.map +1 -1
  5. package/dist/module/actions/types.js +1 -1
  6. package/dist/module/actions/types.js.map +1 -1
  7. package/dist/module/apis/index.js +3 -3
  8. package/dist/module/apis/index.js.map +1 -1
  9. package/dist/module/apis/maintenanceActions.js +36 -36
  10. package/dist/module/apis/maintenanceActions.js.map +1 -1
  11. package/dist/module/apis/userActions.js +5 -5
  12. package/dist/module/apis/userActions.js.map +1 -1
  13. package/dist/module/components/FilterPopupMenu.js +49 -49
  14. package/dist/module/components/FilterPopupMenu.js.map +1 -1
  15. package/dist/module/components/MaintenanceList.js +38 -38
  16. package/dist/module/components/MaintenanceList.js.map +1 -1
  17. package/dist/module/components/MaintenanceListItem.js +62 -62
  18. package/dist/module/components/MaintenanceListItem.js.map +1 -1
  19. package/dist/module/components/MaintenanceWidgetItem.js +27 -27
  20. package/dist/module/components/MaintenanceWidgetItem.js.map +1 -1
  21. package/dist/module/components/PrioritySelectorPopup.js +15 -15
  22. package/dist/module/components/PrioritySelectorPopup.js.map +1 -1
  23. package/dist/module/components/StatusSelectorPopup.js +16 -16
  24. package/dist/module/components/StatusSelectorPopup.js.map +1 -1
  25. package/dist/module/components/WidgetLarge.js +2 -2
  26. package/dist/module/components/WidgetLarge.js.map +1 -1
  27. package/dist/module/components/WidgetSmall.js +19 -19
  28. package/dist/module/components/WidgetSmall.js.map +1 -1
  29. package/dist/module/core.config.js +1 -1
  30. package/dist/module/core.config.js.map +1 -1
  31. package/dist/module/feature.config.js +17 -17
  32. package/dist/module/feature.config.js.map +1 -1
  33. package/dist/module/helper.js +10 -10
  34. package/dist/module/helper.js.map +1 -1
  35. package/dist/module/index.js +11 -11
  36. package/dist/module/index.js.map +1 -1
  37. package/dist/module/reducers/JobsReducer.js +13 -13
  38. package/dist/module/reducers/JobsReducer.js.map +1 -1
  39. package/dist/module/screens/JobTypePicker.js +17 -17
  40. package/dist/module/screens/JobTypePicker.js.map +1 -1
  41. package/dist/module/screens/MaintenancePage.js +10 -10
  42. package/dist/module/screens/MaintenancePage.js.map +1 -1
  43. package/dist/module/screens/MaintenanceUserPicker.js +129 -22
  44. package/dist/module/screens/MaintenanceUserPicker.js.map +1 -1
  45. package/dist/module/screens/RequestDetail.js +145 -145
  46. package/dist/module/screens/RequestDetail.js.map +1 -1
  47. package/dist/module/screens/RequestNotes.js +59 -59
  48. package/dist/module/screens/RequestNotes.js.map +1 -1
  49. package/dist/module/screens/ServiceRequest.js +187 -187
  50. package/dist/module/screens/ServiceRequest.js.map +1 -1
  51. package/dist/module/values.config.a.js +31 -31
  52. package/dist/module/values.config.a.js.map +1 -1
  53. package/dist/module/values.config.default.js +35 -35
  54. package/dist/module/values.config.default.js.map +1 -1
  55. package/dist/module/values.config.enquiry.js +35 -35
  56. package/dist/module/values.config.enquiry.js.map +1 -1
  57. package/dist/module/values.config.feedback.js +35 -35
  58. package/dist/module/values.config.feedback.js.map +1 -1
  59. package/dist/module/values.config.food.js +35 -35
  60. package/dist/module/values.config.food.js.map +1 -1
  61. package/dist/module/values.config.forms.js +34 -34
  62. package/dist/module/values.config.forms.js.map +1 -1
  63. package/dist/module/values.config.js +34 -34
  64. package/dist/module/values.config.js.map +1 -1
  65. package/package.json +52 -52
  66. package/src/actions/JobActions.js +67 -60
  67. package/src/actions/index.js +1 -1
  68. package/src/actions/types.js +1 -2
  69. package/src/apis/index.js +3 -3
  70. package/src/apis/maintenanceActions.js +189 -178
  71. package/src/apis/userActions.js +17 -17
  72. package/src/components/FilterPopupMenu.js +313 -256
  73. package/src/components/MaintenanceList.js +396 -317
  74. package/src/components/MaintenanceListItem.js +347 -288
  75. package/src/components/MaintenanceWidgetItem.js +145 -124
  76. package/src/components/PrioritySelectorPopup.js +81 -68
  77. package/src/components/StatusSelectorPopup.js +81 -70
  78. package/src/components/WidgetLarge.js +5 -5
  79. package/src/components/WidgetSmall.js +153 -133
  80. package/src/core.config.js +27 -3
  81. package/src/feature.config.js +62 -62
  82. package/src/helper.js +58 -53
  83. package/src/index.js +22 -22
  84. package/src/reducers/JobsReducer.js +85 -66
  85. package/src/screens/JobTypePicker.js +115 -92
  86. package/src/screens/MaintenancePage.js +89 -80
  87. package/src/screens/MaintenanceUserPicker.js +262 -99
  88. package/src/screens/RequestDetail.js +1345 -1125
  89. package/src/screens/RequestNotes.js +946 -805
  90. package/src/screens/ServiceRequest.js +1773 -1557
  91. package/src/values.config.a.js +34 -34
  92. package/src/values.config.default.js +40 -40
  93. package/src/values.config.enquiry.js +40 -40
  94. package/src/values.config.feedback.js +40 -40
  95. package/src/values.config.food.js +40 -40
  96. package/src/values.config.forms.js +39 -39
  97. package/src/values.config.js +39 -39
@@ -1,1568 +1,1784 @@
1
- import React, { Component } from 'react';
1
+ import React, { Component } from "react";
2
2
  import {
3
- Dimensions,
4
- Platform,
5
- KeyboardAvoidingView,
6
- ScrollView,
7
- Text,
8
- TouchableOpacity,
9
- View,
10
- Switch,
11
- FlatList,
12
- ImageBackground,
13
- Keyboard,
14
- } from 'react-native';
15
- import DateTimePicker from 'react-native-modal-datetime-picker';
16
- import { Icon } from '@rneui/themed';
17
- import _ from 'lodash';
18
- import moment from 'moment';
19
- import { connect } from 'react-redux';
20
- import { jobAdded } from '../actions';
21
- import { maintenanceActions, userActions } from '../apis';
22
- import { Services } from '../feature.config';
23
- import { Components, Colours, Helper, Config } from '../core.config';
24
- import { values } from '../values.config';
25
-
26
- const PHOTO_SIZE = (Dimensions.get('window').width - 64) / 3;
3
+ Dimensions,
4
+ Platform,
5
+ KeyboardAvoidingView,
6
+ ScrollView,
7
+ Text,
8
+ TouchableOpacity,
9
+ View,
10
+ Switch,
11
+ FlatList,
12
+ ImageBackground,
13
+ Keyboard,
14
+ } from "react-native";
15
+ import DateTimePicker from "react-native-modal-datetime-picker";
16
+ import { Icon } from "@rneui/themed";
17
+ import _ from "lodash";
18
+ import moment from "moment";
19
+ import { connect } from "react-redux";
20
+ import { jobAdded } from "../actions";
21
+ import { maintenanceActions, userActions } from "../apis";
22
+ import { Services } from "../feature.config";
23
+ import { Components, Colours, Helper, Config } from "../core.config";
24
+ import { values } from "../values.config";
25
+
26
+ const PHOTO_SIZE = (Dimensions.get("window").width - 64) / 3;
27
27
 
28
28
  class MaintenanceRequest extends Component {
29
- constructor(props) {
30
- super(props);
31
- this.state = {
32
- submitting: false,
33
- success: false,
34
- fail: false,
35
- error: null,
36
- showError: false,
37
- loadingTypes: values.forceCustomFields,
38
-
39
- userName: '',
40
- roomNumber: '',
41
- phone: '',
42
- title: '',
43
- description: '',
44
- times: '',
45
-
46
- type: 'General',
47
-
48
- uploadingImage: false,
49
- images: [
50
- {
51
- add: true,
52
- },
53
- ],
54
- showFullscreenVideo: false,
55
- currentVideoUrl: '',
56
-
57
- isHome: false,
58
-
59
- types: [],
60
-
61
- confirmationToShow: false,
62
-
63
- customFields: [],
64
- customFieldImages: {},
65
- customFieldDocuments: {},
66
- isDateTimePickerVisible: false,
67
- popUpType: 'date',
68
- dateFieldId: null,
69
- imageFieldId: null,
70
-
71
- // PC-1255: On-behalf request fields
72
- canCreateOnBehalf: false,
73
- selectedUser: null,
74
- users: [],
75
- };
76
- this.checkThumb = null;
77
- this.keyboardTypes = {
78
- phone: 'phone-pad',
79
- email: 'email-address',
80
- text: 'default',
81
- };
82
- }
83
-
84
- componentDidMount() {
85
- this.checkUserPermissions();
86
- this.getJobTypes();
87
- }
88
-
89
- checkUserPermissions = async () => {
90
- // PC-1255: Check if user has userManagement permission
91
- const hasUserManagement = this.props.permissions?.includes('userManagement') || false;
92
-
93
- if (hasUserManagement) {
94
- this.setState({ canCreateOnBehalf: true });
95
- // Load site users for picker
96
- await this.loadSiteUsers();
97
- } else {
98
- // Default to logged-in user for non-staff or staff without permission
99
- this.setDefaultUser();
100
- }
101
- };
102
-
103
- loadSiteUsers = async () => {
104
- try {
105
- const response = await userActions.getSiteUsers(this.props.site);
106
-
107
- let items = response.data.Items || [];
108
- if (this.props.optionOnlyForResidents) {
109
- items = _.filter(items, u => u.category === 'resident');
110
- }
111
-
112
- const users = _.sortBy(items, u => (u.displayName || '').toLowerCase());
113
- this.setState({ users });
114
- } catch (error) {
115
- console.log('Error loading site users:', error);
116
- // Fall back to default user if loading fails
117
- this.setDefaultUser();
118
- }
119
- };
120
-
121
- setDefaultUser = () => {
122
- if (this.props.userType !== 'KIOSK') {
123
- const defaultUser = {
124
- userId: this.props.uid,
125
- displayName: this.props.displayName,
126
- profilePic: this.props.profilePic,
127
- };
128
- this.setState({
129
- selectedUser: defaultUser,
130
- userName: this.props.displayName,
131
- roomNumber: this.props.unit,
132
- phone: !_.isEmpty(this.props.phoneNumber) ? this.props.phoneNumber : '',
133
- });
134
- }
135
- };
136
-
137
- componentWillUnmount() {
138
- clearInterval(this.checkThumb);
139
- }
140
-
141
- onChangeName = userName => {
142
- const update = { userName };
143
- if (!this.state.customFields || !_.some(this.state.customFields, 'isTitle')) {
144
- update.title = userName;
145
- }
146
- this.setState(update);
147
- };
148
-
149
- // PC-1255: Handle user picker navigation
150
- onPressUser = () => {
151
- const { users, selectedUser } = this.state;
152
- if (!users || users.length === 0) return;
153
-
154
- Services.navigation.navigate(values.screenUserPicker, {
155
- currentUser: selectedUser,
156
- users,
157
- onSelectUser: this.onSelectUser.bind(this),
158
- });
159
- };
160
-
161
- // PC-1255: Handle user selection and auto-populate contact details
162
- onSelectUser = async user => {
163
- const update = {
164
- selectedUser: user,
165
- userName: user.displayName,
166
- };
167
-
168
- // PC-1255: Try to fetch full user details for auto-population
169
- try {
170
- // getSiteUsers returns 'Id', but fetchUser expects 'userId'
171
- const userId = user.userId || user.Id;
172
- const response = await userActions.fetchUser(this.props.site, userId);
173
- if (response.data && response.data.user) {
174
- const userDetails = response.data.user;
175
- if (userDetails.phoneNumber) {
176
- update.phone = userDetails.phoneNumber;
177
- }
178
- if (userDetails.unit) {
179
- update.roomNumber = userDetails.unit;
180
- }
181
- if (!this.state.customFields || !_.some(this.state.customFields, 'isTitle')) {
182
- update.title = userDetails.displayName || null;
183
- }
184
- }
185
- } catch (error) {
186
- // Permission denied (403) or other error - continue without auto-population
187
- // User can still manually enter contact details
188
- console.log('Could not fetch user details for auto-population:', error);
189
- } finally {
190
- // In any case, we still need a title. Inform the user to set one form field as a title.
191
- if (!state.title && !update.title) {
192
- update.title = '[Missing title - Set one of the form field as title in the community manager]';
193
- }
194
- }
195
- this.setState(update);
196
- };
197
-
198
- onChangeAnswer = (fieldId, answer) => {
199
- const update = { customFields: _.cloneDeep(this.state.customFields) };
200
- const field = update.customFields[fieldId];
201
- field.answer = answer;
202
- if (field.isTitle) update.title = field.answer;
203
- this.setState(update);
204
- };
205
-
206
- onChangeToggleAnswer = (fieldId, answer) => {
207
- const update = { customFields: _.cloneDeep(this.state.customFields) };
208
- const field = update.customFields[fieldId];
209
- field.answer = field.answer === answer ? undefined : answer;
210
- if (field.isTitle) update.title = field.answer;
211
- this.setState(update);
212
- };
213
-
214
- onChangeCheckboxAnswer = (fieldId, answer) => {
215
- const update = { customFields: _.cloneDeep(this.state.customFields) };
216
- const field = update.customFields[fieldId];
217
- field.answer = _.xor(field.answer || [], [answer]);
218
- if (field.isTitle) update.title = field.answer.join(', ');
219
- this.setState(update);
220
- };
221
-
222
- onOpenDatePicker = (field, fieldId) => {
223
- Keyboard.dismiss();
224
- this.setState({ dateFieldId: fieldId, popUpType: field.type, isDateTimePickerVisible: true });
225
- };
226
-
227
- onClearDate = fieldId => {
228
- const update = { customFields: _.cloneDeep(this.state.customFields) };
229
- const field = update.customFields[fieldId];
230
- field.answer = undefined;
231
- if (field.isTitle) update.title = field.answer;
232
- this.setState(update);
233
- };
234
-
235
- onDateSelected = date => {
236
- const { customFields, dateFieldId, popUpType } = this.state;
237
- const update = { customFields: _.cloneDeep(customFields), isDateTimePickerVisible: false, fieldId: null };
238
- const field = update.customFields[dateFieldId];
239
- const dateObj = moment(date);
240
- if (popUpType === 'date') {
241
- field.answer = dateObj.format('YYYY-MM-DD');
242
- if (field.isTitle) update.title = dateObj.format('DD MMM YYYY');
243
- } else {
244
- field.answer = dateObj.format('HH:mm');
245
- if (field.isTitle) update.title = dateObj.format('h:mm a');
246
- }
247
- this.setState(update);
248
- };
249
-
250
- onUploadStartedImage = (uploadUri, imageUri) => {
251
- const { imageFieldId } = this.state;
252
- const imagesUpdate = this.getImages(imageFieldId);
253
- imagesUpdate.splice(imagesUpdate.length - 1, 0, {
254
- uploading: true,
255
- uploadProgress: '0%',
256
- uploadUri,
257
- imageUri,
258
- allowRetry: true,
259
- });
260
-
261
- this.setImages(imagesUpdate, imageFieldId);
262
- };
263
-
264
- onUploadProgressImage = progress => {
265
- const { imageFieldId } = this.state;
266
- const imagesUpdate = this.getImages(imageFieldId);
267
- imagesUpdate.map(img => {
268
- if (img.uploadUri === progress.uri) {
269
- img.uploadProgress = progress.percentage;
270
- img.uploading = true;
271
- img.allowRetry = true;
272
- }
273
- });
274
-
275
- this.setImages(imagesUpdate, imageFieldId);
276
- };
277
-
278
- onUploadSuccessImage = async (uri, uploadUri) => {
279
- const { imageFieldId } = this.state;
280
- const imagesUpdate = this.getImages(imageFieldId);
281
- imagesUpdate.map(img => {
282
- if (img.uploadUri === uploadUri && img.uploading) {
283
- img.url = uri.replace('/general/', '/general1400/');
284
- img.thumbNailExists = false;
285
- img.thumbNailUrl = Helper.getThumb300(img.url);
286
- img.allowRetry = true;
287
- }
288
- });
289
-
290
- this.setImages(imagesUpdate, imageFieldId, () => this.waitForThumbnails());
291
- };
292
-
293
- onUploadFailedImage = uploadUri => {
294
- const { imageFieldId } = this.state;
295
- const imagesUpdate = this.getImages(imageFieldId);
296
- imagesUpdate.map(img => {
297
- if (img.uploadUri === uploadUri) {
298
- img.uploading = true; // Requried for retry
299
- img.uploadProgress = '';
300
- img.allowRetry = true;
301
- }
302
- });
303
-
304
- this.setImages(imagesUpdate, imageFieldId);
305
- };
306
-
307
- onLibrarySelected = uri => {
308
- const { imageFieldId } = this.state;
309
- const imagesUpdate = this.getImages(imageFieldId);
310
- imagesUpdate.splice(imagesUpdate.length - 1, 0, {
311
- uploading: false,
312
- allowRetry: false,
313
- url: Helper.get1400(uri),
314
- thumbNailExists: true,
315
- thumbNailUrl: Helper.getThumb300(uri),
316
- });
317
-
318
- this.setImages(imagesUpdate, imageFieldId);
319
- };
320
-
321
- onUploadStartedDocument = (uploadUri, documentUri, documentName, documentExt, documentFieldId) => {
322
- const documentsUpdate = this.getDocuments(documentFieldId);
323
- documentsUpdate.splice(documentsUpdate.length - 1, 0, {
324
- uploading: true,
325
- uploadProgress: '0%',
326
- uploadUri,
327
- documentUri,
328
- documentName,
329
- documentExt,
330
- allowRetry: true,
331
- });
332
-
333
- this.setDocuments(documentsUpdate, documentFieldId);
334
- };
335
-
336
- onUploadProgressDocument = (progress, documentFieldId) => {
337
- const documentsUpdate = this.getDocuments(documentFieldId);
338
- documentsUpdate.map(doc => {
339
- if (doc.uploadUri === progress.uri) {
340
- doc.uploadProgress = progress.percentage;
341
- doc.uploading = true;
342
- doc.allowRetry = true;
343
- }
344
- });
345
-
346
- this.setDocuments(documentsUpdate, documentFieldId);
347
- };
348
-
349
- onUploadSuccessDocument = async (uri, uploadUri, documentFieldId) => {
350
- const documentsUpdate = this.getDocuments(documentFieldId);
351
- documentsUpdate.map(doc => {
352
- if (doc.uploadUri === uploadUri && doc.uploading) {
353
- doc.uploading = false;
354
- doc.uploadProgress = '100%';
355
- doc.url = uri;
356
- doc.allowRetry = true;
357
- }
358
- });
359
-
360
- this.setDocuments(documentsUpdate, documentFieldId);
361
- };
362
-
363
- onUploadFailedDocument = (uploadUri, documentFieldId) => {
364
- const documentsUpdate = this.getDocuments(documentFieldId);
365
- documentsUpdate.map(doc => {
366
- if (doc.uploadUri === uploadUri) {
367
- doc.uploading = true; // Requried for retry
368
- doc.uploadProgress = '';
369
- doc.allowRetry = true;
370
- }
371
- });
372
-
373
- this.setDocuments(documentsUpdate, documentFieldId);
374
- };
375
-
376
- onPressBack() {
377
- Services.navigation.goBack();
378
- }
379
-
380
- onPressType() {
381
- Services.navigation.navigate(values.screenJobTypePicker, {
382
- currentType: this.state.type,
383
- types: this.state.types,
384
- onSelectType: this.pickType.bind(this),
385
- });
386
- }
387
-
388
- onCloseConfirmationPopup() {
389
- this.setState({
390
- confirmationToShow: false,
391
- });
392
- Services.navigation.goBack();
393
- this.props.onBack && this.props.onBack();
394
- }
395
-
396
- onConfirmationReset() {
397
- this.setState(
398
- {
399
- confirmationToShow: false,
400
- title: '',
401
- description: '',
402
- times: '',
403
- isHome: false,
404
- uploadingImage: false,
405
- images: [
406
- {
407
- add: true,
408
- },
409
- ],
410
- submitting: false,
411
- success: false,
412
- fail: false,
413
- customFields: [],
414
- customFieldImages: {},
415
- customFieldDocuments: {},
416
- isDateTimePickerVisible: false,
417
- popUpType: 'date',
418
- dateFieldId: null,
419
- imageFieldId: null,
420
- },
421
- () => this.pickType(this.state.type),
422
- );
423
- }
424
-
425
- isFieldValid = (field, fieldId) => {
426
- const { mandatory, type, answer } = field;
427
- if (['staticTitle', 'staticText'].includes(type)) return true;
428
-
429
- const checkMandatory = () => {
430
- if (!mandatory) return true;
431
- switch (type) {
432
- case 'yn':
433
- return _.isBoolean(answer);
434
- case 'image':
435
- const imagesList = this.getImageUrls(fieldId);
436
- return imagesList.length > 0;
437
- case 'document':
438
- const documentsList = this.getDocumentAnswers(fieldId);
439
- return documentsList.length > 0;
440
- case 'checkbox':
441
- return _.isArray(answer) && answer.length > 0;
442
- default:
443
- return !_.isNil(answer) && !_.isEmpty(answer);
444
- }
445
- };
446
- const checkFormat = () => {
447
- if (_.isNil(answer) || _.isEmpty(answer)) return true;
448
- switch (type) {
449
- case 'email':
450
- return Helper.isEmail(answer);
451
- case 'date':
452
- return moment(answer, 'YYYY-MM-DD', true).isValid();
453
- case 'time':
454
- return moment(answer, 'HH:mm', true).isValid();
455
- default:
456
- return true;
457
- }
458
- };
459
-
460
- const valid = checkMandatory() && checkFormat();
461
- return valid;
462
- };
463
-
464
- getJobTypes() {
465
- maintenanceActions
466
- .getJobTypes(Helper.getSite(this.props.site))
467
- .then(res => {
468
- this.setState({
469
- types: res.data,
470
- });
471
- this.getDefaultJob();
472
- })
473
- .catch(() => {});
474
- }
475
-
476
- pickType(type) {
477
- const { types } = this.state;
478
- const selected = types.find(t => t.typeName === type) || {};
479
- if (values.forceCustomFields && !selected.hasCustomFields) {
480
- this.setState({
481
- type,
482
- customFields: [],
483
- noType: true,
484
- });
485
- return;
486
- }
487
- const update = {
488
- type,
489
- customFields: selected.hasCustomFields && selected.customFields.length > 0 ? _.cloneDeep(selected.customFields) : [],
490
- loadingTypes: false,
491
- };
492
-
493
- if (!_.isEmpty(update.customFields) && !_.some(update.customFields, 'isTitle')) {
494
- update.title = this.state.userName;
495
- }
496
-
497
- this.setState(update);
498
- }
499
-
500
- getDefaultJob() {
501
- const { types, jobId } = this.state;
502
- if (types.length !== 0 && jobId == null) {
503
- const defaultType = types[0];
504
- this.pickType(defaultType.typeName);
505
- }
506
- }
507
-
508
- showUploadMenu = fieldId => {
509
- Keyboard.dismiss();
510
- if (this.state.uploadingImage || this.state.submitting) {
511
- return;
512
- }
513
- if (fieldId) this.setState({ imageFieldId: fieldId });
514
- this.imageUploader.showUploadMenu();
515
- };
516
-
517
- submit = async () => {
518
- this.setState({ submitting: true });
519
-
520
- let description = this.state.description;
521
-
522
- if (this.state.isHome) {
523
- description = description + `. -- Times Available: ${this.state.times}`;
524
- }
525
-
526
- setTimeout(() => {
527
- this.scrollContainer.scrollTo({ y: 0 });
528
- }, 100);
529
-
530
- const images = this.getImageUrls();
531
-
532
- // Fix custom images field answers
533
- const customFields = _.cloneDeep(this.state.customFields);
534
- const updatedCustomFields = customFields.map((field, fieldId) => {
535
- if (field.type === 'image') field.answer = this.getImageUrls(fieldId);
536
- if (field.type === 'document') field.answer = this.getDocumentAnswers(fieldId);
537
- return field;
538
- });
539
-
540
- maintenanceActions
541
- .sendMaintenanceRequest(
542
- this.props.uid,
543
- this.state.userName,
544
- this.state.phone,
545
- this.state.roomNumber,
546
- this.state.title,
547
- description,
548
- null,
549
- this.state.type,
550
- images,
551
- Helper.getSite(this.props.site),
552
- this.state.isHome,
553
- this.state.times,
554
- updatedCustomFields,
555
- )
556
- .then(res => {
557
- if (res.data.success) {
558
- this.refreshRequest(res.data.searchResult);
559
- if (this.props.onSubmissionSuccess) this.props.onSubmissionSuccess(res.data);
560
- this.setState({
561
- submitting: false,
562
- success: true,
563
- confirmationToShow: true,
564
- });
565
- } else {
566
- this.setState({
567
- submitting: false,
568
- });
569
- }
570
- })
571
- .catch(err => {
572
- console.log('maintenance submission fail.');
573
- console.log(err);
574
- this.setState({
575
- submitting: false,
576
- });
577
- });
578
- };
579
-
580
- refreshRequest = async id => {
581
- try {
582
- const job = await maintenanceActions.getJob(Helper.getSite(this.props.site), id);
583
- this.props.jobAdded(job.data);
584
- } catch (error) {
585
- console.log('refreshRequest error', error);
586
- }
587
- };
588
-
589
- validateCustomFields = () => {
590
- const { customFields } = this.state;
591
- if (!customFields || customFields.length === 0) return true;
592
-
593
- return customFields.every((field, index) => {
594
- const isValid = this.isFieldValid(field, index);
595
- return isValid;
596
- });
597
- };
598
-
599
- submitRequest() {
600
- const { customFields, submitting, uploadingImage, title, roomNumber, isHome, times } = this.state;
601
- const hasCustomFields = customFields && customFields.length > 0;
602
-
603
- if (submitting || !this.props.connected) {
604
- if (!this.props.connected) {
605
- this.setState({ error: { message: 'No internet connection detected' } });
606
- }
607
- return;
608
- }
609
- if (uploadingImage) return;
610
-
611
- this.setState({ error: null, showError: false });
612
-
613
- // PC-1255: Validate user selection for on-behalf requests
614
- if (this.state.canCreateOnBehalf && !this.state.selectedUser) {
615
- console.log('submitRequest - no user selected for on-behalf request');
616
- this.setState({ showError: true });
617
- return;
618
- }
619
-
620
- if (title.length === 0 || !roomNumber || roomNumber.length === 0) {
621
- console.log('submitRequest - error', { title, roomNumber });
622
- this.setState({ showError: true });
623
- return;
624
- }
625
- if (hasCustomFields) {
626
- if (!this.validateCustomFields()) {
627
- console.log('submitRequest - custom fields error');
628
- this.setState({ showError: true });
629
- return;
630
- }
631
- } else {
632
- if (isHome && times.length < 2) {
633
- console.log('submitRequest - error', { isHome, times });
634
- this.setState({ showError: true });
635
- return;
636
- }
637
- }
638
- this.submit();
639
- }
640
-
641
- getImages = (fieldId = null) => {
642
- const { images, customFieldImages } = this.state;
643
- const imagesList = _.cloneDeep(fieldId ? customFieldImages[fieldId] : images);
644
- if (!imagesList || !Array.isArray(imagesList) || imagesList.length === 0) {
645
- return [{ add: true }];
646
- }
647
- return imagesList;
648
- };
649
-
650
- setImages = (imagesList, fieldId = null, callback = null) => {
651
- let update = {};
652
- if (fieldId) {
653
- const customFieldImages = _.cloneDeep(this.state.customFieldImages);
654
- customFieldImages[fieldId] = imagesList;
655
- update = { customFieldImages };
656
- } else {
657
- update = { images: imagesList };
658
- }
659
- this.setState(update, callback);
660
- };
661
-
662
- getImageUrls = (fieldId = null) => {
663
- const imagesList = this.getImages(fieldId);
664
- return _.filter(imagesList, img => {
665
- return !img.uploading && !img.add;
666
- }).map(img => {
667
- return img.url;
668
- });
669
- };
670
-
671
- waitForThumbnails = () => {
672
- if (this.checkThumb) return;
673
-
674
- this.checkThumb = setInterval(async () => {
675
- const { imageFieldId } = this.state;
676
- const imagesList = this.getImages(imageFieldId);
677
- const imagesUpdate = [];
678
- await Promise.all(
679
- imagesList.map(image => {
680
- return new Promise(async resolve => {
681
- const newImage = { ...image };
682
- imagesUpdate.push(newImage);
683
- if (newImage.url && !newImage.thumbNailExists) {
684
- newImage.uploading = false;
685
- newImage.allowRetry = false;
686
- newImage.thumbNailExists = await Helper.imageExists(newImage.thumbNailUrl);
687
- resolve(newImage.thumbNailExists);
688
- }
689
- resolve(true);
690
- });
691
- }),
692
- );
693
- const thumbnailsExist = imagesUpdate.every(image => !image.url || image.thumbNailExists);
694
- if (thumbnailsExist) {
695
- clearInterval(this.checkThumb);
696
- this.checkThumb = null;
697
- this.setImages(imagesUpdate, imageFieldId);
698
- }
699
- }, 2000);
700
- };
701
-
702
- removeImage = (index, fieldId) => {
703
- const imagesUpdate = this.getImages(fieldId);
704
- imagesUpdate.splice(index, 1);
705
-
706
- this.setImages(imagesUpdate, fieldId);
707
- };
708
-
709
- getDocuments = fieldId => {
710
- const { customFieldDocuments } = this.state;
711
- const documentsList = _.cloneDeep(customFieldDocuments[fieldId]) || [];
712
- return documentsList;
713
- };
714
-
715
- setDocuments = (documentsList, fieldId) => {
716
- let update = {};
717
- const customFieldDocuments = _.cloneDeep(this.state.customFieldDocuments);
718
- customFieldDocuments[fieldId] = documentsList;
719
- update = { customFieldDocuments };
720
- this.setState(update);
721
- };
722
-
723
- getDocumentAnswers = fieldId => {
724
- const documentsList = this.getDocuments(fieldId);
725
- return _.filter(documentsList, doc => {
726
- return !doc.uploading && doc.url;
727
- }).map(doc => {
728
- return {
729
- name: doc.documentName,
730
- ext: doc.documentExt,
731
- url: doc.url,
732
- };
733
- });
734
- };
735
-
736
- removeDocument = (index, fieldId) => {
737
- const documentsUpdate = this.getDocuments(fieldId);
738
- documentsUpdate.splice(index, 1);
739
-
740
- this.setDocuments(documentsUpdate, fieldId);
741
- };
742
-
743
- toggleFullscreenVideo = url => {
744
- if (typeof url !== 'string') url = '';
745
- this.setState({ showFullscreenVideo: url.length > 0, currentVideoUrl: url });
746
- };
747
-
748
- renderImageUploader() {
749
- return (
750
- <Components.ImageUploader
751
- ref={ref => (this.imageUploader = ref)}
752
- onUploadStarted={this.onUploadStartedImage}
753
- onUploadSuccess={this.onUploadSuccessImage}
754
- onUploadFailed={this.onUploadFailedImage}
755
- onUploadProgress={this.onUploadProgressImage}
756
- onLibrarySelected={this.onLibrarySelectedImage}
757
- size={{ width: 1400 }}
758
- quality={0.8}
759
- fileName={'serviceImage'}
760
- popupTitle={'Upload Image'}
761
- userId={this.props.uid}
762
- allowsEditing={false}
763
- multiple
764
- hideLibrary
765
- />
766
- );
767
- }
768
-
769
- renderImage(item, index, fieldId = null) {
770
- const isVideoUrl = Helper.isVideo(item.url);
771
- const imagesList = this.getImages(fieldId);
772
-
773
- if (item.add) {
774
- return (
775
- <TouchableOpacity activeOpacity={0.8} onPress={() => this.showUploadMenu(fieldId)}>
776
- <View
777
- style={[
778
- styles.imageContainer,
779
- imagesList.length > 1 && styles.imageContainerNotEmpty,
780
- index % 3 === 0 && { marginLeft: 0 },
781
- index > 2 && { marginTop: 8 },
782
- ]}
783
- >
784
- <View style={styles.imageCircle}>
785
- <Icon name="camera" type="font-awesome" iconStyle={styles.addImageIcon} />
786
- </View>
787
- </View>
788
- </TouchableOpacity>
789
- );
790
- }
791
- return (
792
- <View
793
- style={[
794
- styles.imageContainer,
795
- imagesList.length > 1 && styles.imageContainerNotEmpty,
796
- index % 3 === 0 && { marginLeft: 0 },
797
- index > 2 && { marginTop: 8 },
798
- ]}
799
- >
800
- {item.uploading ? (
801
- <Components.ImageUploadProgress uploader={this.imageUploader} image={item} color={this.props.colourBrandingMain} />
802
- ) : (
803
- <ImageBackground
804
- style={styles.imageBackground}
805
- source={Helper.getImageSource(item.thumbNailExists ? item.thumbNailUrl : item.url)}
806
- >
807
- {isVideoUrl && (
808
- <View style={styles.imagePlayContainer}>
809
- <TouchableOpacity onPress={this.toggleFullscreenVideo.bind(this, item.url)}>
810
- <Icon name="play" type="font-awesome" iconStyle={styles.imageControlIcon} />
811
- </TouchableOpacity>
812
- </View>
813
- )}
814
- <TouchableOpacity style={styles.removeImage} onPress={() => this.removeImage(index, fieldId)}>
815
- <Icon name="remove" type="font-awesome" iconStyle={styles.imageControlIcon} style={styles.removeImage} />
816
- </TouchableOpacity>
817
- </ImageBackground>
818
- )}
819
- </View>
820
- );
821
- }
822
-
823
- renderDocument(item, index, fieldId) {
824
- const { colourBrandingMain } = this.props;
825
- return (
826
- <View key={index} style={styles.documentContainer}>
827
- <View style={{ ...styles.documentTypeContainer, backgroundColor: colourBrandingMain }}>
828
- <Text style={styles.documentTypeText}>{item.documentExt}</Text>
829
- </View>
830
- <Text style={styles.documentText}>{`${item.documentName}${item.uploading ? ` - ${item.uploadProgress}` : ''}`}</Text>
831
- {!item.uploading && (
832
- <TouchableOpacity style={styles.removeDocumentButton} onPress={() => this.removeDocument(index, fieldId)}>
833
- <Icon name="remove" type="font-awesome" iconStyle={{ ...styles.removeDocumentIcon, color: colourBrandingMain }} />
834
- </TouchableOpacity>
835
- )}
836
- </View>
837
- );
838
- }
839
-
840
- renderSuccess() {
841
- return (
842
- <View style={{ padding: 16, flex: 1, backgroundColor: '#fff' }}>
843
- <Text style={styles.requestSuccess}>Your request has been submitted. Thank you.</Text>
844
- </View>
845
- );
846
- }
847
-
848
- renderImageList(fieldId = null) {
849
- const imagesList = this.getImages(fieldId);
850
- return (
851
- <View style={[styles.imageListContainer, imagesList.length < 2 && styles.imageListContainerEmpty]}>
852
- <FlatList
853
- keyboardShouldPersistTaps="always"
854
- enableEmptySections
855
- data={imagesList}
856
- renderItem={({ item, index }) => this.renderImage(item, index, fieldId)}
857
- keyExtractor={(item, index) => index}
858
- numColumns={3}
859
- />
860
- </View>
861
- );
862
- }
863
-
864
- // renderDocumentList(fieldId) {
865
- // const documentsList = this.getDocuments(fieldId);
866
- // return (
867
- // <View style={styles.documentListContainer}>
868
- // {documentsList.length > 0 ? documentsList.map((document, index) => this.renderDocument(document, index, fieldId)) : null}
869
- // <Components.DocumentUploader
870
- // buttonTitle="Add Files"
871
- // allowedTypes={['application/pdf']}
872
- // onUploadStarted={(uploadUri, uri, name, ext) => this.onUploadStartedDocument(uploadUri, uri, name, ext, fieldId)}
873
- // onUploadProgress={progress => this.onUploadProgressDocument(progress, fieldId)}
874
- // onUploadSuccess={(uri, uploadUri) => this.onUploadSuccessDocument(uri, uploadUri, fieldId)}
875
- // onUploadFailed={uploadUri => this.onUploadFailedDocument(uploadUri, fieldId)}
876
- // fileName="serviceDocument"
877
- // userId={this.props.uid}
878
- // disabled={false}
879
- // multiple
880
- // />
881
- // </View>
882
- // );
883
- // }
884
-
885
- renderDateField(field, fieldId, sectionStyle) {
886
- let displayText, placeHolder, icon, errorText;
887
- if (field.type === 'date') {
888
- displayText = field.answer ? moment(field.answer, 'YYYY-MM-DD').format('DD MMM YYYY') : '';
889
- placeHolder = 'dd mmm yyyy';
890
- icon = 'calendar';
891
- errorText = 'Not a valid date';
892
- } else {
893
- displayText = field.answer ? moment(field.answer, 'HH:mm').format('h:mm a') : '';
894
- placeHolder = '--:-- --';
895
- icon = 'clock-o';
896
- errorText = 'Not a valid time';
897
- }
898
-
899
- return (
900
- <Components.GenericInputSection
901
- key={fieldId}
902
- label={field.label}
903
- sectionStyle={sectionStyle}
904
- isValid={() => this.isFieldValid(field, fieldId)}
905
- required={field.mandatory}
906
- showError={this.state.showError}
907
- errorText={errorText}
908
- >
909
- <View style={styles.dateContainer}>
910
- <TouchableOpacity style={styles.dateFieldButton} onPress={() => this.onOpenDatePicker(field, fieldId)}>
911
- <View style={styles.dateFieldContainer}>
912
- <Text style={styles.dateText}>{displayText || placeHolder}</Text>
913
- <Icon type="font-awesome" name={icon} iconStyle={styles.dateIcon} />
914
- </View>
915
- </TouchableOpacity>
916
- {displayText ? (
917
- <TouchableOpacity style={styles.dateClearButton} onPress={() => this.onClearDate(fieldId)}>
918
- <Icon type="font-awesome" name="times" iconStyle={styles.removeIcon} />
919
- </TouchableOpacity>
920
- ) : null}
921
- </View>
922
- </Components.GenericInputSection>
923
- );
924
- }
925
-
926
- renderField(field, fieldId) {
927
- const sectionStyle = { marginTop: fieldId === 0 ? 24 : 0, marginBottom: 24 };
928
- switch (field.type) {
929
- case 'yn':
930
- return (
931
- <Components.GenericInputSection
932
- key={fieldId}
933
- label={field.label}
934
- sectionStyle={sectionStyle}
935
- inputType="toggle"
936
- value={field.answer}
937
- onChange={answer => this.onChangeToggleAnswer(fieldId, answer)}
938
- isValid={() => this.isFieldValid(field, fieldId)}
939
- showError={this.state.showError}
940
- required={field.mandatory}
941
- />
942
- );
943
- case 'multichoice':
944
- return (
945
- <Components.GenericInputSection
946
- key={fieldId}
947
- label={field.label}
948
- sectionStyle={sectionStyle}
949
- inputType="radio"
950
- value={field.answer}
951
- onChange={answer => this.onChangeToggleAnswer(fieldId, answer)}
952
- options={field.values.map(o => {
953
- return {
954
- Label: o,
955
- Value: o,
956
- };
957
- })}
958
- isValid={() => this.isFieldValid(field, fieldId)}
959
- showError={this.state.showError}
960
- required={field.mandatory}
961
- />
962
- );
963
- case 'checkbox':
964
- return (
965
- <Components.GenericInputSection
966
- key={fieldId}
967
- label={field.label}
968
- sectionStyle={sectionStyle}
969
- isValid={() => this.isFieldValid(field, fieldId)}
970
- showError={this.state.showError}
971
- required={field.mandatory}
972
- >
973
- {field.values.map((o, i) => {
974
- const isActive = field.answer && _.includes(field.answer, o);
975
- return (
976
- <TouchableOpacity
977
- onPress={() => this.onChangeCheckboxAnswer(fieldId, o)}
978
- key={i}
979
- style={styles.multiChoiceOption}
980
- hitSlop={{ top: 8, left: 8, bottom: 8, right: 8 }}
981
- >
982
- {isActive ? (
983
- <Components.TickIcon style={styles.tick} size={20} color={this.props.colourBrandingMain} />
984
- ) : (
985
- <View style={styles.unticked} />
986
- )}
987
- <Text style={styles.multiChoiceText}>{o}</Text>
988
- </TouchableOpacity>
989
- );
990
- })}
991
- </Components.GenericInputSection>
992
- );
993
- case 'text':
994
- case 'email':
995
- case 'phone':
996
- return (
997
- <Components.GenericInputSection
998
- key={fieldId}
999
- label={field.label}
1000
- placeholder={field.placeHolder}
1001
- value={field.answer}
1002
- onChangeText={val => this.onChangeAnswer(fieldId, val)}
1003
- editable
1004
- squaredCorners
1005
- isValid={() => this.isFieldValid(field, fieldId)}
1006
- showError={this.state.showError}
1007
- errorText={field.type === 'email' ? 'Not a valid email' : undefined}
1008
- required={field.mandatory}
1009
- sectionStyle={sectionStyle}
1010
- autoCapitalize="sentences"
1011
- keyboardType={this.keyboardTypes[field.type]}
1012
- />
1013
- );
1014
- case 'staticTitle':
1015
- return (
1016
- <Text key={fieldId} style={[styles.staticTitle, { color: this.props.colourBrandingMain }, sectionStyle]}>
1017
- {field.label}
1018
- </Text>
1019
- );
1020
- case 'staticText':
1021
- return (
1022
- <View key={fieldId} style={[styles.staticText, sectionStyle]}>
1023
- {Helper.toParagraphed(field.label, styles.staticText)}
1024
- </View>
1025
- );
1026
- case 'date':
1027
- case 'time':
1028
- return this.renderDateField(field, fieldId, sectionStyle);
1029
- case 'image':
1030
- return (
1031
- <Components.GenericInputSection
1032
- key={fieldId}
1033
- label={field.label}
1034
- sectionStyle={sectionStyle}
1035
- isValid={() => this.isFieldValid(field, fieldId)}
1036
- required={field.mandatory}
1037
- showError={this.state.showError}
1038
- >
1039
- {this.renderImageList(fieldId)}
1040
- </Components.GenericInputSection>
1041
- );
1042
- // case 'document':
1043
- // return (
1044
- // <Components.GenericInputSection
1045
- // key={fieldId}
1046
- // label={field.label}
1047
- // sectionStyle={sectionStyle}
1048
- // isValid={() => this.isFieldValid(field, fieldId)}
1049
- // required={field.mandatory}
1050
- // showError={this.state.showError}
1051
- // >
1052
- // {this.renderDocumentList(fieldId)}
1053
- // </Components.GenericInputSection>
1054
- // );
1055
- default:
1056
- return null;
1057
- }
1058
- }
1059
-
1060
- renderCustomFields() {
1061
- const { customFields } = this.state;
1062
- if (!customFields || customFields.length === 0) return null;
1063
-
1064
- return (
1065
- <Components.FormCard style={{ marginTop: 16 }}>{customFields.map((field, i) => this.renderField(field, i))}</Components.FormCard>
1066
- );
1067
- }
1068
-
1069
- renderForm() {
1070
- const { customFields, loadingTypes } = this.state;
1071
- const hasCustomFields = customFields && customFields.length > 0;
1072
-
1073
- if (loadingTypes) {
1074
- return <Components.Spinner />;
1075
- }
1076
-
1077
- return (
1078
- <View style={{ flex: 1 }}>
1079
- <ScrollView keyboardShouldPersistTaps="always" style={{ flex: 1 }} ref={ref => (this.scrollContainer = ref)}>
1080
- <View style={{ paddingBottom: 2 }}>
1081
- <Components.LoadingIndicator visible={this.state.submitting} />
1082
- {this.state.error && <Text style={styles.errorText}>{this.state.error}</Text>}
1083
- <Components.FormCard style={{ marginTop: 16 }}>
1084
- {/* PC-1255: User picker for on-behalf requests */}
1085
- {this.state.canCreateOnBehalf && (
1086
- <Components.FormCardSection
1087
- label={'Select User'}
1088
- textValue={this.state.selectedUser?.displayName}
1089
- hasContent
1090
- hasUnderline
1091
- required
1092
- errorText="Please select a user."
1093
- showError={this.state.showError && !this.state.selectedUser}
1094
- sectionStyle={{ borderBottomWidth: 1, borderBottomColor: Colours.LINEGREY }}
1095
- >
1096
- <TouchableOpacity onPress={this.onPressUser}>
1097
- <View style={styles.userPickerContainer}>
1098
- <View style={styles.profileContainer}>
1099
- <Components.ProfilePic ProfilePic={this.state.selectedUser?.profilePic} Diameter={30} />
1100
- <Text style={styles.nameText}>{this.state.selectedUser?.displayName || 'Select User'}</Text>
1101
- </View>
1102
- <Icon
1103
- name="angle-right"
1104
- type="font-awesome"
1105
- iconStyle={[styles.sectionTitle, { fontSize: 20, color: this.props.colourBrandingMain }]}
1106
- />
1107
- </View>
1108
- </TouchableOpacity>
1109
- </Components.FormCardSection>
1110
- )}
1111
- {/* PC-1255: Hide Name field when creating on behalf - name comes from selected user */}
1112
- {!this.state.canCreateOnBehalf && (
1113
- <Components.FormCardSection
1114
- label={'Name'}
1115
- placeholder={'Enter your name'}
1116
- textValue={this.state.userName}
1117
- onChangeText={userName => this.onChangeName(userName)}
1118
- editable={this.props.userType === 'KIOSK' && this.state.submitting === false}
1119
- isValid={() => {
1120
- return this.state.userName.length > 1;
1121
- }}
1122
- required
1123
- errorText="Please enter your name."
1124
- showError={this.state.showError && this.state.userName.length < 2}
1125
- hasUnderline
1126
- />
1127
- )}
1128
- <Components.FormCardSection
1129
- label={'Contact number'}
1130
- placeholder={'Enter phone number'}
1131
- textValue={this.state.phone}
1132
- onChangeText={phone => this.setState({ phone })}
1133
- editable={this.state.submitting === false}
1134
- hasUnderline
1135
- keyboardType={'phone-pad'}
1136
- />
1137
- <Components.FormCardSection
1138
- label={'Address'}
1139
- placeholder={'Enter your address'}
1140
- textValue={this.state.roomNumber}
1141
- onChangeText={roomNumber => this.setState({ roomNumber })}
1142
- editable={this.state.submitting === false}
1143
- hasUnderline
1144
- isValid={() => {
1145
- return this.state.roomNumber && this.state.roomNumber.length > 1;
1146
- }}
1147
- required
1148
- errorText="Please provide your address."
1149
- showError={this.state.showError && (!this.state.roomNumber || this.state.roomNumber.length < 2)}
1150
- />
1151
- </Components.FormCard>
1152
- <Components.FormCard
1153
- style={{ marginTop: 16, paddingHorizontal: 24, paddingVertical: 16, flexDirection: 'row', justifyContent: 'space-between' }}
1154
- >
1155
- <Text style={styles.sectionTitle}>{values.textJobType}</Text>
1156
- <TouchableOpacity onPress={this.onPressType.bind(this)}>
1157
- <View style={{ flexDirection: 'row' }}>
1158
- <Text style={[styles.sectionTitle, { color: this.props.colourBrandingMain, marginRight: 16 }]}>{this.state.type}</Text>
1159
- <Icon
1160
- name="angle-right"
1161
- type="font-awesome"
1162
- iconStyle={[styles.sectionTitle, { fontSize: 20, color: this.props.colourBrandingMain }]}
1163
- />
1164
- </View>
1165
- </TouchableOpacity>
1166
- </Components.FormCard>
1167
- {hasCustomFields ? (
1168
- this.renderCustomFields()
1169
- ) : (
1170
- <>
1171
- <Components.FormCard style={{ marginTop: 16 }}>
1172
- <Components.FormCardSection
1173
- label={'Title'}
1174
- placeholder={'Enter a title for your request'}
1175
- textValue={this.state.title}
1176
- onChangeText={title => this.setState({ title })}
1177
- editable={this.state.submitting === false}
1178
- hasUnderline
1179
- isValid={() => {
1180
- return this.state.title.length > 1;
1181
- }}
1182
- required
1183
- errorText="Please provide a title."
1184
- showError={this.state.showError && this.state.title.length < 2}
1185
- autoCorrect
1186
- multiline
1187
- autoGrow
1188
- />
1189
- <Components.FormCardSection
1190
- label={'Description'}
1191
- placeholder={'Describe your request here in detail'}
1192
- textValue={this.state.description}
1193
- onChangeText={description => this.setState({ description })}
1194
- editable={this.state.submitting === false}
1195
- hasUnderline
1196
- autoCorrect
1197
- multiline
1198
- autoGrow
1199
- />
1200
- </Components.FormCard>
1201
- <Components.FormCard style={{ marginTop: 16, paddingHorizontal: 24 }}>
1202
- <View
1203
- style={[
1204
- {
1205
- width: '100%',
1206
- paddingVertical: 16,
1207
- flexDirection: 'row',
1208
- justifyContent: 'space-between',
1209
- alignItems: 'center',
1210
- position: 'relative',
1211
- },
1212
- this.state.isHome && { borderBottomWidth: 1, borderBottomColor: Colours.LINEGREY },
1213
- ]}
1214
- >
1215
- <Text style={styles.sectionTitle}>{Config.env.strings.MAINTENANCE_HOME}</Text>
1216
- <Switch
1217
- value={this.state.isHome}
1218
- disabled={this.state.submitting}
1219
- onValueChange={value => this.setState({ isHome: value })}
1220
- trackColor={{ false: '#ddd', true: this.props.colourBrandingMain }}
1221
- thumbColor={Platform.OS === 'android' ? '#fff' : null}
1222
- />
1223
- </View>
1224
- {this.state.isHome && (
1225
- <Components.FormCardSection
1226
- label={'Available times'}
1227
- placeholder={'Describe your available times here in detail.'}
1228
- textValue={this.state.times}
1229
- onChangeText={times => this.setState({ times })}
1230
- editable={this.state.submitting === false}
1231
- hasUnderline
1232
- isValid={() => {
1233
- return this.state.times.length > 1;
1234
- }}
1235
- required
1236
- errorText="Please provide available times."
1237
- showError={this.state.showError && this.state.isHome && this.state.times.length < 2}
1238
- minHeight={40}
1239
- autoCorrect
1240
- multiline
1241
- autoGrow
1242
- />
1243
- )}
1244
- </Components.FormCard>
1245
- {this.renderImageList()}
1246
- </>
1247
- )}
1248
- </View>
1249
- </ScrollView>
1250
- </View>
1251
- );
1252
- }
1253
-
1254
- renderRegisterConfirmation() {
1255
- return (
1256
- <Components.ConfirmationPopup
1257
- confirmText={`${values.textEntityName} submitted`}
1258
- repeatText={'Submit another'}
1259
- visible={this.state.confirmationToShow}
1260
- onClose={this.onCloseConfirmationPopup.bind(this)}
1261
- onPressAction={this.onConfirmationReset.bind(this)}
1262
- />
1263
- );
1264
- }
1265
-
1266
- renderVideoPlayerPopup() {
1267
- const { showFullscreenVideo, currentVideoUrl } = this.state;
1268
- if (!currentVideoUrl) return;
1269
-
1270
- return (
1271
- <Components.VideoPopup
1272
- uri={currentVideoUrl}
1273
- visible={showFullscreenVideo}
1274
- showFullscreenButton={false}
1275
- onClose={this.toggleFullscreenVideo}
1276
- />
1277
- );
1278
- }
1279
-
1280
- renderNoType() {
1281
- if (!this.state.noType) {
1282
- return null;
1283
- }
1284
- return (
1285
- <Components.WarningPopup
1286
- confirmText={'No forms are available'}
1287
- infoText={'Check back later for forms.'}
1288
- visible={this.state.noType}
1289
- onClose={this.onPressBack.bind(this)}
1290
- padHorizontal
1291
- />
1292
- );
1293
- }
1294
-
1295
- render() {
1296
- const { submitting, success, isDateTimePickerVisible, popUpType } = this.state;
1297
-
1298
- return (
1299
- <KeyboardAvoidingView behavior={'padding'} style={styles.viewContainer}>
1300
- {this.renderImageUploader()}
1301
- <View style={styles.container}>
1302
- <Components.Header
1303
- leftIcon="angle-left"
1304
- onPressLeft={this.onPressBack.bind(this)}
1305
- text={this.props.strings[`${values.featureKey}_textFeatureTitle`] || values.textFeatureTitle}
1306
- rightText={submitting || success ? null : 'Done'}
1307
- onPressRight={this.submitRequest.bind(this)}
1308
- absoluteRight
1309
- />
1310
- {this.renderForm()}
1311
- </View>
1312
- {this.renderRegisterConfirmation()}
1313
- {this.renderVideoPlayerPopup()}
1314
- {this.renderNoType()}
1315
- <DateTimePicker
1316
- isVisible={isDateTimePickerVisible}
1317
- onConfirm={this.onDateSelected}
1318
- onCancel={() => this.setState({ isDateTimePickerVisible: false })}
1319
- mode={popUpType}
1320
- headerTextIOS={`Pick a ${popUpType}`}
1321
- />
1322
- </KeyboardAvoidingView>
1323
- );
1324
- }
29
+ constructor(props) {
30
+ super(props);
31
+ this.state = {
32
+ submitting: false,
33
+ success: false,
34
+ fail: false,
35
+ error: null,
36
+ showError: false,
37
+ loadingTypes: values.forceCustomFields,
38
+
39
+ userName: "",
40
+ roomNumber: "",
41
+ phone: "",
42
+ title: "",
43
+ description: "",
44
+ times: "",
45
+
46
+ type: "General",
47
+
48
+ uploadingImage: false,
49
+ images: [
50
+ {
51
+ add: true,
52
+ },
53
+ ],
54
+ showFullscreenVideo: false,
55
+ currentVideoUrl: "",
56
+
57
+ isHome: false,
58
+
59
+ types: [],
60
+
61
+ confirmationToShow: false,
62
+
63
+ customFields: [],
64
+ customFieldImages: {},
65
+ customFieldDocuments: {},
66
+ isDateTimePickerVisible: false,
67
+ popUpType: "date",
68
+ dateFieldId: null,
69
+ imageFieldId: null,
70
+
71
+ // PC-1255: On-behalf request fields
72
+ canCreateOnBehalf: false,
73
+ selectedUser: null,
74
+ users: [],
75
+ };
76
+ this.checkThumb = null;
77
+ this.keyboardTypes = {
78
+ phone: "phone-pad",
79
+ email: "email-address",
80
+ text: "default",
81
+ };
82
+ }
83
+
84
+ componentDidMount() {
85
+ this.checkUserPermissions();
86
+ this.getJobTypes();
87
+ }
88
+
89
+ checkUserPermissions = async () => {
90
+ // PC-1255: Check if user has userManagement permission
91
+ const hasUserManagement =
92
+ this.props.permissions?.includes("userManagement") || false;
93
+
94
+ if (hasUserManagement) {
95
+ this.setState({ canCreateOnBehalf: true });
96
+ // Load site users for picker
97
+ await this.loadSiteUsers();
98
+ } else {
99
+ // Default to logged-in user for non-staff or staff without permission
100
+ this.setDefaultUser();
101
+ }
102
+ };
103
+
104
+ loadSiteUsers = async () => {
105
+ try {
106
+ const response = await userActions.getSiteUsers(this.props.site);
107
+
108
+ let items = response.data.Items || [];
109
+ if (this.props.optionOnlyForResidents) {
110
+ items = _.filter(items, (u) => u.category === "resident");
111
+ }
112
+
113
+ const users = _.sortBy(items, (u) => (u.displayName || "").toLowerCase());
114
+ this.setState({ users });
115
+ } catch (error) {
116
+ console.log("Error loading site users:", error);
117
+ // Fall back to default user if loading fails
118
+ this.setDefaultUser();
119
+ }
120
+ };
121
+
122
+ setDefaultUser = () => {
123
+ if (this.props.userType !== "KIOSK") {
124
+ const defaultUser = {
125
+ userId: this.props.uid,
126
+ displayName: this.props.displayName,
127
+ profilePic: this.props.profilePic,
128
+ };
129
+ this.setState({
130
+ selectedUser: defaultUser,
131
+ userName: this.props.displayName,
132
+ roomNumber: this.props.unit,
133
+ phone: !_.isEmpty(this.props.phoneNumber) ? this.props.phoneNumber : "",
134
+ });
135
+ }
136
+ };
137
+
138
+ componentWillUnmount() {
139
+ clearInterval(this.checkThumb);
140
+ }
141
+
142
+ onChangeName = (userName) => {
143
+ const update = { userName };
144
+ if (
145
+ !this.state.customFields ||
146
+ !_.some(this.state.customFields, "isTitle")
147
+ ) {
148
+ update.title = userName;
149
+ }
150
+ this.setState(update);
151
+ };
152
+
153
+ // PC-1255: Handle user picker navigation
154
+ onPressUser = () => {
155
+ const { users, selectedUser } = this.state;
156
+ if (!users || users.length === 0) return;
157
+
158
+ Services.navigation.navigate(values.screenUserPicker, {
159
+ currentUser: selectedUser,
160
+ users,
161
+ onSelectUser: this.onSelectUser.bind(this),
162
+ });
163
+ };
164
+
165
+ // PC-1255: Handle user selection and auto-populate contact details
166
+ onSelectUser = async (user) => {
167
+ const update = {
168
+ selectedUser: user,
169
+ userName: user.displayName,
170
+ };
171
+
172
+ // PC-1255: Try to fetch full user details for auto-population
173
+ try {
174
+ // getSiteUsers returns 'Id', but fetchUser expects 'userId'
175
+ const userId = user.userId || user.Id;
176
+ const response = await userActions.fetchUser(this.props.site, userId);
177
+ if (response.data && response.data.user) {
178
+ const userDetails = response.data.user;
179
+ if (userDetails.phoneNumber) {
180
+ update.phone = userDetails.phoneNumber;
181
+ }
182
+ if (userDetails.unit) {
183
+ update.roomNumber = userDetails.unit;
184
+ }
185
+ if (
186
+ !this.state.customFields ||
187
+ !_.some(this.state.customFields, "isTitle")
188
+ ) {
189
+ update.title = userDetails.displayName || null;
190
+ }
191
+ }
192
+ } catch (error) {
193
+ // Permission denied (403) or other error - continue without auto-population
194
+ // User can still manually enter contact details
195
+ console.log("Could not fetch user details for auto-population:", error);
196
+ } finally {
197
+ // In any case, we still need a title. Inform the user to set one form field as a title.
198
+ if (!state.title && !update.title) {
199
+ update.title =
200
+ "[Missing title - Set one of the form field as title in the community manager]";
201
+ }
202
+ }
203
+ this.setState(update);
204
+ };
205
+
206
+ onChangeAnswer = (fieldId, answer) => {
207
+ const update = { customFields: _.cloneDeep(this.state.customFields) };
208
+ const field = update.customFields[fieldId];
209
+ field.answer = answer;
210
+ if (field.isTitle) update.title = field.answer;
211
+ this.setState(update);
212
+ };
213
+
214
+ onChangeToggleAnswer = (fieldId, answer) => {
215
+ const update = { customFields: _.cloneDeep(this.state.customFields) };
216
+ const field = update.customFields[fieldId];
217
+ field.answer = field.answer === answer ? undefined : answer;
218
+ if (field.isTitle) update.title = field.answer;
219
+ this.setState(update);
220
+ };
221
+
222
+ onChangeCheckboxAnswer = (fieldId, answer) => {
223
+ const update = { customFields: _.cloneDeep(this.state.customFields) };
224
+ const field = update.customFields[fieldId];
225
+ field.answer = _.xor(field.answer || [], [answer]);
226
+ if (field.isTitle) update.title = field.answer.join(", ");
227
+ this.setState(update);
228
+ };
229
+
230
+ onOpenDatePicker = (field, fieldId) => {
231
+ Keyboard.dismiss();
232
+ this.setState({
233
+ dateFieldId: fieldId,
234
+ popUpType: field.type,
235
+ isDateTimePickerVisible: true,
236
+ });
237
+ };
238
+
239
+ onClearDate = (fieldId) => {
240
+ const update = { customFields: _.cloneDeep(this.state.customFields) };
241
+ const field = update.customFields[fieldId];
242
+ field.answer = undefined;
243
+ if (field.isTitle) update.title = field.answer;
244
+ this.setState(update);
245
+ };
246
+
247
+ onDateSelected = (date) => {
248
+ const { customFields, dateFieldId, popUpType } = this.state;
249
+ const update = {
250
+ customFields: _.cloneDeep(customFields),
251
+ isDateTimePickerVisible: false,
252
+ fieldId: null,
253
+ };
254
+ const field = update.customFields[dateFieldId];
255
+ const dateObj = moment(date);
256
+ if (popUpType === "date") {
257
+ field.answer = dateObj.format("YYYY-MM-DD");
258
+ if (field.isTitle) update.title = dateObj.format("DD MMM YYYY");
259
+ } else {
260
+ field.answer = dateObj.format("HH:mm");
261
+ if (field.isTitle) update.title = dateObj.format("h:mm a");
262
+ }
263
+ this.setState(update);
264
+ };
265
+
266
+ onUploadStartedImage = (uploadUri, imageUri) => {
267
+ const { imageFieldId } = this.state;
268
+ const imagesUpdate = this.getImages(imageFieldId);
269
+ imagesUpdate.splice(imagesUpdate.length - 1, 0, {
270
+ uploading: true,
271
+ uploadProgress: "0%",
272
+ uploadUri,
273
+ imageUri,
274
+ allowRetry: true,
275
+ });
276
+
277
+ this.setImages(imagesUpdate, imageFieldId);
278
+ };
279
+
280
+ onUploadProgressImage = (progress) => {
281
+ const { imageFieldId } = this.state;
282
+ const imagesUpdate = this.getImages(imageFieldId);
283
+ imagesUpdate.map((img) => {
284
+ if (img.uploadUri === progress.uri) {
285
+ img.uploadProgress = progress.percentage;
286
+ img.uploading = true;
287
+ img.allowRetry = true;
288
+ }
289
+ });
290
+
291
+ this.setImages(imagesUpdate, imageFieldId);
292
+ };
293
+
294
+ onUploadSuccessImage = async (uri, uploadUri) => {
295
+ const { imageFieldId } = this.state;
296
+ const imagesUpdate = this.getImages(imageFieldId);
297
+ imagesUpdate.map((img) => {
298
+ if (img.uploadUri === uploadUri && img.uploading) {
299
+ img.url = uri.replace("/general/", "/general1400/");
300
+ img.thumbNailExists = false;
301
+ img.thumbNailUrl = Helper.getThumb300(img.url);
302
+ img.allowRetry = true;
303
+ }
304
+ });
305
+
306
+ this.setImages(imagesUpdate, imageFieldId, () => this.waitForThumbnails());
307
+ };
308
+
309
+ onUploadFailedImage = (uploadUri) => {
310
+ const { imageFieldId } = this.state;
311
+ const imagesUpdate = this.getImages(imageFieldId);
312
+ imagesUpdate.map((img) => {
313
+ if (img.uploadUri === uploadUri) {
314
+ img.uploading = true; // Requried for retry
315
+ img.uploadProgress = "";
316
+ img.allowRetry = true;
317
+ }
318
+ });
319
+
320
+ this.setImages(imagesUpdate, imageFieldId);
321
+ };
322
+
323
+ onLibrarySelected = (uri) => {
324
+ const { imageFieldId } = this.state;
325
+ const imagesUpdate = this.getImages(imageFieldId);
326
+ imagesUpdate.splice(imagesUpdate.length - 1, 0, {
327
+ uploading: false,
328
+ allowRetry: false,
329
+ url: Helper.get1400(uri),
330
+ thumbNailExists: true,
331
+ thumbNailUrl: Helper.getThumb300(uri),
332
+ });
333
+
334
+ this.setImages(imagesUpdate, imageFieldId);
335
+ };
336
+
337
+ onUploadStartedDocument = (
338
+ uploadUri,
339
+ documentUri,
340
+ documentName,
341
+ documentExt,
342
+ documentFieldId,
343
+ ) => {
344
+ const documentsUpdate = this.getDocuments(documentFieldId);
345
+ documentsUpdate.splice(documentsUpdate.length - 1, 0, {
346
+ uploading: true,
347
+ uploadProgress: "0%",
348
+ uploadUri,
349
+ documentUri,
350
+ documentName,
351
+ documentExt,
352
+ allowRetry: true,
353
+ });
354
+
355
+ this.setDocuments(documentsUpdate, documentFieldId);
356
+ };
357
+
358
+ onUploadProgressDocument = (progress, documentFieldId) => {
359
+ const documentsUpdate = this.getDocuments(documentFieldId);
360
+ documentsUpdate.map((doc) => {
361
+ if (doc.uploadUri === progress.uri) {
362
+ doc.uploadProgress = progress.percentage;
363
+ doc.uploading = true;
364
+ doc.allowRetry = true;
365
+ }
366
+ });
367
+
368
+ this.setDocuments(documentsUpdate, documentFieldId);
369
+ };
370
+
371
+ onUploadSuccessDocument = async (uri, uploadUri, documentFieldId) => {
372
+ const documentsUpdate = this.getDocuments(documentFieldId);
373
+ documentsUpdate.map((doc) => {
374
+ if (doc.uploadUri === uploadUri && doc.uploading) {
375
+ doc.uploading = false;
376
+ doc.uploadProgress = "100%";
377
+ doc.url = uri;
378
+ doc.allowRetry = true;
379
+ }
380
+ });
381
+
382
+ this.setDocuments(documentsUpdate, documentFieldId);
383
+ };
384
+
385
+ onUploadFailedDocument = (uploadUri, documentFieldId) => {
386
+ const documentsUpdate = this.getDocuments(documentFieldId);
387
+ documentsUpdate.map((doc) => {
388
+ if (doc.uploadUri === uploadUri) {
389
+ doc.uploading = true; // Requried for retry
390
+ doc.uploadProgress = "";
391
+ doc.allowRetry = true;
392
+ }
393
+ });
394
+
395
+ this.setDocuments(documentsUpdate, documentFieldId);
396
+ };
397
+
398
+ onPressBack() {
399
+ Services.navigation.goBack();
400
+ }
401
+
402
+ onPressType() {
403
+ Services.navigation.navigate(values.screenJobTypePicker, {
404
+ currentType: this.state.type,
405
+ types: this.state.types,
406
+ onSelectType: this.pickType.bind(this),
407
+ });
408
+ }
409
+
410
+ onCloseConfirmationPopup() {
411
+ this.setState({
412
+ confirmationToShow: false,
413
+ });
414
+ Services.navigation.goBack();
415
+ this.props.onBack && this.props.onBack();
416
+ }
417
+
418
+ onConfirmationReset() {
419
+ this.setState(
420
+ {
421
+ confirmationToShow: false,
422
+ title: "",
423
+ description: "",
424
+ times: "",
425
+ isHome: false,
426
+ uploadingImage: false,
427
+ images: [
428
+ {
429
+ add: true,
430
+ },
431
+ ],
432
+ submitting: false,
433
+ success: false,
434
+ fail: false,
435
+ customFields: [],
436
+ customFieldImages: {},
437
+ customFieldDocuments: {},
438
+ isDateTimePickerVisible: false,
439
+ popUpType: "date",
440
+ dateFieldId: null,
441
+ imageFieldId: null,
442
+ },
443
+ () => this.pickType(this.state.type),
444
+ );
445
+ }
446
+
447
+ isFieldValid = (field, fieldId) => {
448
+ const { mandatory, type, answer } = field;
449
+ if (["staticTitle", "staticText"].includes(type)) return true;
450
+
451
+ const checkMandatory = () => {
452
+ if (!mandatory) return true;
453
+ switch (type) {
454
+ case "yn":
455
+ return _.isBoolean(answer);
456
+ case "image":
457
+ const imagesList = this.getImageUrls(fieldId);
458
+ return imagesList.length > 0;
459
+ case "document":
460
+ const documentsList = this.getDocumentAnswers(fieldId);
461
+ return documentsList.length > 0;
462
+ case "checkbox":
463
+ return _.isArray(answer) && answer.length > 0;
464
+ default:
465
+ return !_.isNil(answer) && !_.isEmpty(answer);
466
+ }
467
+ };
468
+ const checkFormat = () => {
469
+ if (_.isNil(answer) || _.isEmpty(answer)) return true;
470
+ switch (type) {
471
+ case "email":
472
+ return Helper.isEmail(answer);
473
+ case "date":
474
+ return moment(answer, "YYYY-MM-DD", true).isValid();
475
+ case "time":
476
+ return moment(answer, "HH:mm", true).isValid();
477
+ default:
478
+ return true;
479
+ }
480
+ };
481
+
482
+ const valid = checkMandatory() && checkFormat();
483
+ return valid;
484
+ };
485
+
486
+ getJobTypes() {
487
+ maintenanceActions
488
+ .getJobTypes(Helper.getSite(this.props.site))
489
+ .then((res) => {
490
+ this.setState({
491
+ types: res.data,
492
+ });
493
+ this.getDefaultJob();
494
+ })
495
+ .catch(() => {});
496
+ }
497
+
498
+ pickType(type) {
499
+ const { types } = this.state;
500
+ const selected = types.find((t) => t.typeName === type) || {};
501
+ if (values.forceCustomFields && !selected.hasCustomFields) {
502
+ this.setState({
503
+ type,
504
+ customFields: [],
505
+ noType: true,
506
+ });
507
+ return;
508
+ }
509
+ const update = {
510
+ type,
511
+ customFields:
512
+ selected.hasCustomFields && selected.customFields.length > 0
513
+ ? _.cloneDeep(selected.customFields)
514
+ : [],
515
+ loadingTypes: false,
516
+ };
517
+
518
+ if (
519
+ !_.isEmpty(update.customFields) &&
520
+ !_.some(update.customFields, "isTitle")
521
+ ) {
522
+ update.title = this.state.userName;
523
+ }
524
+
525
+ this.setState(update);
526
+ }
527
+
528
+ getDefaultJob() {
529
+ const { types, jobId } = this.state;
530
+ if (types.length !== 0 && jobId == null) {
531
+ const defaultType = types[0];
532
+ this.pickType(defaultType.typeName);
533
+ }
534
+ }
535
+
536
+ showUploadMenu = (fieldId) => {
537
+ Keyboard.dismiss();
538
+ if (this.state.uploadingImage || this.state.submitting) {
539
+ return;
540
+ }
541
+ if (fieldId) this.setState({ imageFieldId: fieldId });
542
+ this.imageUploader.showUploadMenu();
543
+ };
544
+
545
+ submit = async () => {
546
+ this.setState({ submitting: true });
547
+
548
+ let description = this.state.description;
549
+
550
+ if (this.state.isHome) {
551
+ description = description + `. -- Times Available: ${this.state.times}`;
552
+ }
553
+
554
+ setTimeout(() => {
555
+ this.scrollContainer.scrollTo({ y: 0 });
556
+ }, 100);
557
+
558
+ const images = this.getImageUrls();
559
+
560
+ // Fix custom images field answers
561
+ const customFields = _.cloneDeep(this.state.customFields);
562
+ const updatedCustomFields = customFields.map((field, fieldId) => {
563
+ if (field.type === "image") field.answer = this.getImageUrls(fieldId);
564
+ if (field.type === "document")
565
+ field.answer = this.getDocumentAnswers(fieldId);
566
+ return field;
567
+ });
568
+
569
+ maintenanceActions
570
+ .sendMaintenanceRequest(
571
+ this.props.uid,
572
+ this.state.userName,
573
+ this.state.phone,
574
+ this.state.roomNumber,
575
+ this.state.title,
576
+ description,
577
+ null,
578
+ this.state.type,
579
+ images,
580
+ Helper.getSite(this.props.site),
581
+ this.state.isHome,
582
+ this.state.times,
583
+ updatedCustomFields,
584
+ )
585
+ .then((res) => {
586
+ if (res.data.success) {
587
+ this.refreshRequest(res.data.searchResult);
588
+ if (this.props.onSubmissionSuccess)
589
+ this.props.onSubmissionSuccess(res.data);
590
+ this.setState({
591
+ submitting: false,
592
+ success: true,
593
+ confirmationToShow: true,
594
+ });
595
+ } else {
596
+ this.setState({
597
+ submitting: false,
598
+ });
599
+ }
600
+ })
601
+ .catch((err) => {
602
+ console.log("maintenance submission fail.");
603
+ console.log(err);
604
+ this.setState({
605
+ submitting: false,
606
+ });
607
+ });
608
+ };
609
+
610
+ refreshRequest = async (id) => {
611
+ try {
612
+ const job = await maintenanceActions.getJob(
613
+ Helper.getSite(this.props.site),
614
+ id,
615
+ );
616
+ this.props.jobAdded(job.data);
617
+ } catch (error) {
618
+ console.log("refreshRequest error", error);
619
+ }
620
+ };
621
+
622
+ validateCustomFields = () => {
623
+ const { customFields } = this.state;
624
+ if (!customFields || customFields.length === 0) return true;
625
+
626
+ return customFields.every((field, index) => {
627
+ const isValid = this.isFieldValid(field, index);
628
+ return isValid;
629
+ });
630
+ };
631
+
632
+ submitRequest() {
633
+ const {
634
+ customFields,
635
+ submitting,
636
+ uploadingImage,
637
+ title,
638
+ roomNumber,
639
+ isHome,
640
+ times,
641
+ } = this.state;
642
+ const hasCustomFields = customFields && customFields.length > 0;
643
+
644
+ if (submitting || !this.props.connected) {
645
+ if (!this.props.connected) {
646
+ this.setState({
647
+ error: { message: "No internet connection detected" },
648
+ });
649
+ }
650
+ return;
651
+ }
652
+ if (uploadingImage) return;
653
+
654
+ this.setState({ error: null, showError: false });
655
+
656
+ // PC-1255: Validate user selection for on-behalf requests
657
+ if (this.state.canCreateOnBehalf && !this.state.selectedUser) {
658
+ console.log("submitRequest - no user selected for on-behalf request");
659
+ this.setState({ showError: true });
660
+ return;
661
+ }
662
+
663
+ if (title.length === 0 || !roomNumber || roomNumber.length === 0) {
664
+ console.log("submitRequest - error", { title, roomNumber });
665
+ this.setState({ showError: true });
666
+ return;
667
+ }
668
+ if (hasCustomFields) {
669
+ if (!this.validateCustomFields()) {
670
+ console.log("submitRequest - custom fields error");
671
+ this.setState({ showError: true });
672
+ return;
673
+ }
674
+ } else {
675
+ if (isHome && times.length < 2) {
676
+ console.log("submitRequest - error", { isHome, times });
677
+ this.setState({ showError: true });
678
+ return;
679
+ }
680
+ }
681
+ this.submit();
682
+ }
683
+
684
+ getImages = (fieldId = null) => {
685
+ const { images, customFieldImages } = this.state;
686
+ const imagesList = _.cloneDeep(
687
+ fieldId ? customFieldImages[fieldId] : images,
688
+ );
689
+ if (!imagesList || !Array.isArray(imagesList) || imagesList.length === 0) {
690
+ return [{ add: true }];
691
+ }
692
+ return imagesList;
693
+ };
694
+
695
+ setImages = (imagesList, fieldId = null, callback = null) => {
696
+ let update = {};
697
+ if (fieldId) {
698
+ const customFieldImages = _.cloneDeep(this.state.customFieldImages);
699
+ customFieldImages[fieldId] = imagesList;
700
+ update = { customFieldImages };
701
+ } else {
702
+ update = { images: imagesList };
703
+ }
704
+ this.setState(update, callback);
705
+ };
706
+
707
+ getImageUrls = (fieldId = null) => {
708
+ const imagesList = this.getImages(fieldId);
709
+ return _.filter(imagesList, (img) => {
710
+ return !img.uploading && !img.add;
711
+ }).map((img) => {
712
+ return img.url;
713
+ });
714
+ };
715
+
716
+ waitForThumbnails = () => {
717
+ if (this.checkThumb) return;
718
+
719
+ this.checkThumb = setInterval(async () => {
720
+ const { imageFieldId } = this.state;
721
+ const imagesList = this.getImages(imageFieldId);
722
+ const imagesUpdate = [];
723
+ await Promise.all(
724
+ imagesList.map((image) => {
725
+ return new Promise(async (resolve) => {
726
+ const newImage = { ...image };
727
+ imagesUpdate.push(newImage);
728
+ if (newImage.url && !newImage.thumbNailExists) {
729
+ newImage.uploading = false;
730
+ newImage.allowRetry = false;
731
+ newImage.thumbNailExists = await Helper.imageExists(
732
+ newImage.thumbNailUrl,
733
+ );
734
+ resolve(newImage.thumbNailExists);
735
+ }
736
+ resolve(true);
737
+ });
738
+ }),
739
+ );
740
+ const thumbnailsExist = imagesUpdate.every(
741
+ (image) => !image.url || image.thumbNailExists,
742
+ );
743
+ if (thumbnailsExist) {
744
+ clearInterval(this.checkThumb);
745
+ this.checkThumb = null;
746
+ this.setImages(imagesUpdate, imageFieldId);
747
+ }
748
+ }, 2000);
749
+ };
750
+
751
+ removeImage = (index, fieldId) => {
752
+ const imagesUpdate = this.getImages(fieldId);
753
+ imagesUpdate.splice(index, 1);
754
+
755
+ this.setImages(imagesUpdate, fieldId);
756
+ };
757
+
758
+ getDocuments = (fieldId) => {
759
+ const { customFieldDocuments } = this.state;
760
+ const documentsList = _.cloneDeep(customFieldDocuments[fieldId]) || [];
761
+ return documentsList;
762
+ };
763
+
764
+ setDocuments = (documentsList, fieldId) => {
765
+ let update = {};
766
+ const customFieldDocuments = _.cloneDeep(this.state.customFieldDocuments);
767
+ customFieldDocuments[fieldId] = documentsList;
768
+ update = { customFieldDocuments };
769
+ this.setState(update);
770
+ };
771
+
772
+ getDocumentAnswers = (fieldId) => {
773
+ const documentsList = this.getDocuments(fieldId);
774
+ return _.filter(documentsList, (doc) => {
775
+ return !doc.uploading && doc.url;
776
+ }).map((doc) => {
777
+ return {
778
+ name: doc.documentName,
779
+ ext: doc.documentExt,
780
+ url: doc.url,
781
+ };
782
+ });
783
+ };
784
+
785
+ removeDocument = (index, fieldId) => {
786
+ const documentsUpdate = this.getDocuments(fieldId);
787
+ documentsUpdate.splice(index, 1);
788
+
789
+ this.setDocuments(documentsUpdate, fieldId);
790
+ };
791
+
792
+ toggleFullscreenVideo = (url) => {
793
+ if (typeof url !== "string") url = "";
794
+ this.setState({
795
+ showFullscreenVideo: url.length > 0,
796
+ currentVideoUrl: url,
797
+ });
798
+ };
799
+
800
+ renderImageUploader() {
801
+ return (
802
+ <Components.ImageUploader
803
+ ref={(ref) => (this.imageUploader = ref)}
804
+ onUploadStarted={this.onUploadStartedImage}
805
+ onUploadSuccess={this.onUploadSuccessImage}
806
+ onUploadFailed={this.onUploadFailedImage}
807
+ onUploadProgress={this.onUploadProgressImage}
808
+ onLibrarySelected={this.onLibrarySelectedImage}
809
+ size={{ width: 1400 }}
810
+ quality={0.8}
811
+ fileName={"serviceImage"}
812
+ popupTitle={"Upload Image"}
813
+ userId={this.props.uid}
814
+ allowsEditing={false}
815
+ multiple
816
+ hideLibrary
817
+ />
818
+ );
819
+ }
820
+
821
+ renderImage(item, index, fieldId = null) {
822
+ const isVideoUrl = Helper.isVideo(item.url);
823
+ const imagesList = this.getImages(fieldId);
824
+
825
+ if (item.add) {
826
+ return (
827
+ <TouchableOpacity
828
+ activeOpacity={0.8}
829
+ onPress={() => this.showUploadMenu(fieldId)}
830
+ >
831
+ <View
832
+ style={[
833
+ styles.imageContainer,
834
+ imagesList.length > 1 && styles.imageContainerNotEmpty,
835
+ index % 3 === 0 && { marginLeft: 0 },
836
+ index > 2 && { marginTop: 8 },
837
+ ]}
838
+ >
839
+ <View style={styles.imageCircle}>
840
+ <Icon
841
+ name="camera"
842
+ type="font-awesome"
843
+ iconStyle={styles.addImageIcon}
844
+ />
845
+ </View>
846
+ </View>
847
+ </TouchableOpacity>
848
+ );
849
+ }
850
+ return (
851
+ <View
852
+ style={[
853
+ styles.imageContainer,
854
+ imagesList.length > 1 && styles.imageContainerNotEmpty,
855
+ index % 3 === 0 && { marginLeft: 0 },
856
+ index > 2 && { marginTop: 8 },
857
+ ]}
858
+ >
859
+ {item.uploading ? (
860
+ <Components.ImageUploadProgress
861
+ uploader={this.imageUploader}
862
+ image={item}
863
+ color={this.props.colourBrandingMain}
864
+ />
865
+ ) : (
866
+ <ImageBackground
867
+ style={styles.imageBackground}
868
+ source={Helper.getImageSource(
869
+ item.thumbNailExists ? item.thumbNailUrl : item.url,
870
+ )}
871
+ >
872
+ {isVideoUrl && (
873
+ <View style={styles.imagePlayContainer}>
874
+ <TouchableOpacity
875
+ onPress={this.toggleFullscreenVideo.bind(this, item.url)}
876
+ >
877
+ <Icon
878
+ name="play"
879
+ type="font-awesome"
880
+ iconStyle={styles.imageControlIcon}
881
+ />
882
+ </TouchableOpacity>
883
+ </View>
884
+ )}
885
+ <TouchableOpacity
886
+ style={styles.removeImage}
887
+ onPress={() => this.removeImage(index, fieldId)}
888
+ >
889
+ <Icon
890
+ name="remove"
891
+ type="font-awesome"
892
+ iconStyle={styles.imageControlIcon}
893
+ style={styles.removeImage}
894
+ />
895
+ </TouchableOpacity>
896
+ </ImageBackground>
897
+ )}
898
+ </View>
899
+ );
900
+ }
901
+
902
+ renderDocument(item, index, fieldId) {
903
+ const { colourBrandingMain } = this.props;
904
+ return (
905
+ <View key={index} style={styles.documentContainer}>
906
+ <View
907
+ style={{
908
+ ...styles.documentTypeContainer,
909
+ backgroundColor: colourBrandingMain,
910
+ }}
911
+ >
912
+ <Text style={styles.documentTypeText}>{item.documentExt}</Text>
913
+ </View>
914
+ <Text
915
+ style={styles.documentText}
916
+ >{`${item.documentName}${item.uploading ? ` - ${item.uploadProgress}` : ""}`}</Text>
917
+ {!item.uploading && (
918
+ <TouchableOpacity
919
+ style={styles.removeDocumentButton}
920
+ onPress={() => this.removeDocument(index, fieldId)}
921
+ >
922
+ <Icon
923
+ name="remove"
924
+ type="font-awesome"
925
+ iconStyle={{
926
+ ...styles.removeDocumentIcon,
927
+ color: colourBrandingMain,
928
+ }}
929
+ />
930
+ </TouchableOpacity>
931
+ )}
932
+ </View>
933
+ );
934
+ }
935
+
936
+ renderSuccess() {
937
+ return (
938
+ <View style={{ padding: 16, flex: 1, backgroundColor: "#fff" }}>
939
+ <Text style={styles.requestSuccess}>
940
+ Your request has been submitted. Thank you.
941
+ </Text>
942
+ </View>
943
+ );
944
+ }
945
+
946
+ renderImageList(fieldId = null) {
947
+ const imagesList = this.getImages(fieldId);
948
+ return (
949
+ <View
950
+ style={[
951
+ styles.imageListContainer,
952
+ imagesList.length < 2 && styles.imageListContainerEmpty,
953
+ ]}
954
+ >
955
+ <FlatList
956
+ keyboardShouldPersistTaps="always"
957
+ enableEmptySections
958
+ data={imagesList}
959
+ renderItem={({ item, index }) =>
960
+ this.renderImage(item, index, fieldId)
961
+ }
962
+ keyExtractor={(item, index) => index}
963
+ numColumns={3}
964
+ />
965
+ </View>
966
+ );
967
+ }
968
+
969
+ // renderDocumentList(fieldId) {
970
+ // const documentsList = this.getDocuments(fieldId);
971
+ // return (
972
+ // <View style={styles.documentListContainer}>
973
+ // {documentsList.length > 0 ? documentsList.map((document, index) => this.renderDocument(document, index, fieldId)) : null}
974
+ // <Components.DocumentUploader
975
+ // buttonTitle="Add Files"
976
+ // allowedTypes={['application/pdf']}
977
+ // onUploadStarted={(uploadUri, uri, name, ext) => this.onUploadStartedDocument(uploadUri, uri, name, ext, fieldId)}
978
+ // onUploadProgress={progress => this.onUploadProgressDocument(progress, fieldId)}
979
+ // onUploadSuccess={(uri, uploadUri) => this.onUploadSuccessDocument(uri, uploadUri, fieldId)}
980
+ // onUploadFailed={uploadUri => this.onUploadFailedDocument(uploadUri, fieldId)}
981
+ // fileName="serviceDocument"
982
+ // userId={this.props.uid}
983
+ // disabled={false}
984
+ // multiple
985
+ // />
986
+ // </View>
987
+ // );
988
+ // }
989
+
990
+ renderDateField(field, fieldId, sectionStyle) {
991
+ let displayText, placeHolder, icon, errorText;
992
+ if (field.type === "date") {
993
+ displayText = field.answer
994
+ ? moment(field.answer, "YYYY-MM-DD").format("DD MMM YYYY")
995
+ : "";
996
+ placeHolder = "dd mmm yyyy";
997
+ icon = "calendar";
998
+ errorText = "Not a valid date";
999
+ } else {
1000
+ displayText = field.answer
1001
+ ? moment(field.answer, "HH:mm").format("h:mm a")
1002
+ : "";
1003
+ placeHolder = "--:-- --";
1004
+ icon = "clock-o";
1005
+ errorText = "Not a valid time";
1006
+ }
1007
+
1008
+ return (
1009
+ <Components.GenericInputSection
1010
+ key={fieldId}
1011
+ label={field.label}
1012
+ sectionStyle={sectionStyle}
1013
+ isValid={() => this.isFieldValid(field, fieldId)}
1014
+ required={field.mandatory}
1015
+ showError={this.state.showError}
1016
+ errorText={errorText}
1017
+ >
1018
+ <View style={styles.dateContainer}>
1019
+ <TouchableOpacity
1020
+ style={styles.dateFieldButton}
1021
+ onPress={() => this.onOpenDatePicker(field, fieldId)}
1022
+ >
1023
+ <View style={styles.dateFieldContainer}>
1024
+ <Text style={styles.dateText}>{displayText || placeHolder}</Text>
1025
+ <Icon
1026
+ type="font-awesome"
1027
+ name={icon}
1028
+ iconStyle={styles.dateIcon}
1029
+ />
1030
+ </View>
1031
+ </TouchableOpacity>
1032
+ {displayText ? (
1033
+ <TouchableOpacity
1034
+ style={styles.dateClearButton}
1035
+ onPress={() => this.onClearDate(fieldId)}
1036
+ >
1037
+ <Icon
1038
+ type="font-awesome"
1039
+ name="times"
1040
+ iconStyle={styles.removeIcon}
1041
+ />
1042
+ </TouchableOpacity>
1043
+ ) : null}
1044
+ </View>
1045
+ </Components.GenericInputSection>
1046
+ );
1047
+ }
1048
+
1049
+ renderField(field, fieldId) {
1050
+ const sectionStyle = {
1051
+ marginTop: fieldId === 0 ? 24 : 0,
1052
+ marginBottom: 24,
1053
+ };
1054
+ switch (field.type) {
1055
+ case "yn":
1056
+ return (
1057
+ <Components.GenericInputSection
1058
+ key={fieldId}
1059
+ label={field.label}
1060
+ sectionStyle={sectionStyle}
1061
+ inputType="toggle"
1062
+ value={field.answer}
1063
+ onChange={(answer) => this.onChangeToggleAnswer(fieldId, answer)}
1064
+ isValid={() => this.isFieldValid(field, fieldId)}
1065
+ showError={this.state.showError}
1066
+ required={field.mandatory}
1067
+ />
1068
+ );
1069
+ case "multichoice":
1070
+ return (
1071
+ <Components.GenericInputSection
1072
+ key={fieldId}
1073
+ label={field.label}
1074
+ sectionStyle={sectionStyle}
1075
+ inputType="radio"
1076
+ value={field.answer}
1077
+ onChange={(answer) => this.onChangeToggleAnswer(fieldId, answer)}
1078
+ options={field.values.map((o) => {
1079
+ return {
1080
+ Label: o,
1081
+ Value: o,
1082
+ };
1083
+ })}
1084
+ isValid={() => this.isFieldValid(field, fieldId)}
1085
+ showError={this.state.showError}
1086
+ required={field.mandatory}
1087
+ />
1088
+ );
1089
+ case "checkbox":
1090
+ return (
1091
+ <Components.GenericInputSection
1092
+ key={fieldId}
1093
+ label={field.label}
1094
+ sectionStyle={sectionStyle}
1095
+ isValid={() => this.isFieldValid(field, fieldId)}
1096
+ showError={this.state.showError}
1097
+ required={field.mandatory}
1098
+ >
1099
+ {field.values.map((o, i) => {
1100
+ const isActive = field.answer && _.includes(field.answer, o);
1101
+ return (
1102
+ <TouchableOpacity
1103
+ onPress={() => this.onChangeCheckboxAnswer(fieldId, o)}
1104
+ key={i}
1105
+ style={styles.multiChoiceOption}
1106
+ hitSlop={{ top: 8, left: 8, bottom: 8, right: 8 }}
1107
+ >
1108
+ {isActive ? (
1109
+ <Components.TickIcon
1110
+ style={styles.tick}
1111
+ size={20}
1112
+ color={this.props.colourBrandingMain}
1113
+ />
1114
+ ) : (
1115
+ <View style={styles.unticked} />
1116
+ )}
1117
+ <Text style={styles.multiChoiceText}>{o}</Text>
1118
+ </TouchableOpacity>
1119
+ );
1120
+ })}
1121
+ </Components.GenericInputSection>
1122
+ );
1123
+ case "text":
1124
+ case "email":
1125
+ case "phone":
1126
+ return (
1127
+ <Components.GenericInputSection
1128
+ key={fieldId}
1129
+ label={field.label}
1130
+ placeholder={field.placeHolder}
1131
+ value={field.answer}
1132
+ onChangeText={(val) => this.onChangeAnswer(fieldId, val)}
1133
+ editable
1134
+ squaredCorners
1135
+ isValid={() => this.isFieldValid(field, fieldId)}
1136
+ showError={this.state.showError}
1137
+ errorText={field.type === "email" ? "Not a valid email" : undefined}
1138
+ required={field.mandatory}
1139
+ sectionStyle={sectionStyle}
1140
+ autoCapitalize="sentences"
1141
+ keyboardType={this.keyboardTypes[field.type]}
1142
+ />
1143
+ );
1144
+ case "staticTitle":
1145
+ return (
1146
+ <Text
1147
+ key={fieldId}
1148
+ style={[
1149
+ styles.staticTitle,
1150
+ { color: this.props.colourBrandingMain },
1151
+ sectionStyle,
1152
+ ]}
1153
+ >
1154
+ {field.label}
1155
+ </Text>
1156
+ );
1157
+ case "staticText":
1158
+ return (
1159
+ <View key={fieldId} style={[styles.staticText, sectionStyle]}>
1160
+ {Helper.toParagraphed(field.label, styles.staticText)}
1161
+ </View>
1162
+ );
1163
+ case "date":
1164
+ case "time":
1165
+ return this.renderDateField(field, fieldId, sectionStyle);
1166
+ case "image":
1167
+ return (
1168
+ <Components.GenericInputSection
1169
+ key={fieldId}
1170
+ label={field.label}
1171
+ sectionStyle={sectionStyle}
1172
+ isValid={() => this.isFieldValid(field, fieldId)}
1173
+ required={field.mandatory}
1174
+ showError={this.state.showError}
1175
+ >
1176
+ {this.renderImageList(fieldId)}
1177
+ </Components.GenericInputSection>
1178
+ );
1179
+ // case 'document':
1180
+ // return (
1181
+ // <Components.GenericInputSection
1182
+ // key={fieldId}
1183
+ // label={field.label}
1184
+ // sectionStyle={sectionStyle}
1185
+ // isValid={() => this.isFieldValid(field, fieldId)}
1186
+ // required={field.mandatory}
1187
+ // showError={this.state.showError}
1188
+ // >
1189
+ // {this.renderDocumentList(fieldId)}
1190
+ // </Components.GenericInputSection>
1191
+ // );
1192
+ default:
1193
+ return null;
1194
+ }
1195
+ }
1196
+
1197
+ renderCustomFields() {
1198
+ const { customFields } = this.state;
1199
+ if (!customFields || customFields.length === 0) return null;
1200
+
1201
+ return (
1202
+ <Components.FormCard style={{ marginTop: 16 }}>
1203
+ {customFields.map((field, i) => this.renderField(field, i))}
1204
+ </Components.FormCard>
1205
+ );
1206
+ }
1207
+
1208
+ renderForm() {
1209
+ const { customFields, loadingTypes } = this.state;
1210
+ const hasCustomFields = customFields && customFields.length > 0;
1211
+
1212
+ if (loadingTypes) {
1213
+ return <Components.Spinner />;
1214
+ }
1215
+
1216
+ return (
1217
+ <View style={{ flex: 1 }}>
1218
+ <ScrollView
1219
+ keyboardShouldPersistTaps="always"
1220
+ style={{ flex: 1 }}
1221
+ ref={(ref) => (this.scrollContainer = ref)}
1222
+ >
1223
+ <View style={{ paddingBottom: 2 }}>
1224
+ <Components.LoadingIndicator visible={this.state.submitting} />
1225
+ {this.state.error && (
1226
+ <Text style={styles.errorText}>{this.state.error}</Text>
1227
+ )}
1228
+ <Components.FormCard style={{ marginTop: 16 }}>
1229
+ {/* PC-1255: User picker for on-behalf requests */}
1230
+ {this.state.canCreateOnBehalf && (
1231
+ <Components.FormCardSection
1232
+ label={"Select User"}
1233
+ textValue={this.state.selectedUser?.displayName}
1234
+ hasContent
1235
+ hasUnderline
1236
+ required
1237
+ errorText="Please select a user."
1238
+ showError={this.state.showError && !this.state.selectedUser}
1239
+ sectionStyle={{
1240
+ borderBottomWidth: 1,
1241
+ borderBottomColor: Colours.LINEGREY,
1242
+ }}
1243
+ >
1244
+ <TouchableOpacity onPress={this.onPressUser}>
1245
+ <View style={styles.userPickerContainer}>
1246
+ <View style={styles.profileContainer}>
1247
+ <Components.ProfilePic
1248
+ ProfilePic={this.state.selectedUser?.profilePic}
1249
+ Diameter={30}
1250
+ />
1251
+ <Text style={styles.nameText}>
1252
+ {this.state.selectedUser?.displayName ||
1253
+ "Select User"}
1254
+ </Text>
1255
+ </View>
1256
+ <Icon
1257
+ name="angle-right"
1258
+ type="font-awesome"
1259
+ iconStyle={[
1260
+ styles.sectionTitle,
1261
+ {
1262
+ fontSize: 20,
1263
+ color: this.props.colourBrandingMain,
1264
+ },
1265
+ ]}
1266
+ />
1267
+ </View>
1268
+ </TouchableOpacity>
1269
+ </Components.FormCardSection>
1270
+ )}
1271
+ {/* PC-1255: Hide Name field when creating on behalf - name comes from selected user */}
1272
+ {!this.state.canCreateOnBehalf && (
1273
+ <Components.FormCardSection
1274
+ label={"Name"}
1275
+ placeholder={"Enter your name"}
1276
+ textValue={this.state.userName}
1277
+ onChangeText={(userName) => this.onChangeName(userName)}
1278
+ editable={
1279
+ this.props.userType === "KIOSK" &&
1280
+ this.state.submitting === false
1281
+ }
1282
+ isValid={() => {
1283
+ return this.state.userName.length > 1;
1284
+ }}
1285
+ required
1286
+ errorText="Please enter your name."
1287
+ showError={
1288
+ this.state.showError && this.state.userName.length < 2
1289
+ }
1290
+ hasUnderline
1291
+ />
1292
+ )}
1293
+ <Components.FormCardSection
1294
+ label={"Contact number"}
1295
+ placeholder={"Enter phone number"}
1296
+ textValue={this.state.phone}
1297
+ onChangeText={(phone) => this.setState({ phone })}
1298
+ editable={this.state.submitting === false}
1299
+ hasUnderline
1300
+ keyboardType={"phone-pad"}
1301
+ />
1302
+ <Components.FormCardSection
1303
+ label={"Address"}
1304
+ placeholder={"Enter your address"}
1305
+ textValue={this.state.roomNumber}
1306
+ onChangeText={(roomNumber) => this.setState({ roomNumber })}
1307
+ editable={this.state.submitting === false}
1308
+ hasUnderline
1309
+ isValid={() => {
1310
+ return (
1311
+ this.state.roomNumber && this.state.roomNumber.length > 1
1312
+ );
1313
+ }}
1314
+ required
1315
+ errorText="Please provide your address."
1316
+ showError={
1317
+ this.state.showError &&
1318
+ (!this.state.roomNumber || this.state.roomNumber.length < 2)
1319
+ }
1320
+ />
1321
+ </Components.FormCard>
1322
+ <Components.FormCard
1323
+ style={{
1324
+ marginTop: 16,
1325
+ paddingHorizontal: 24,
1326
+ paddingVertical: 16,
1327
+ flexDirection: "row",
1328
+ justifyContent: "space-between",
1329
+ }}
1330
+ >
1331
+ <Text style={styles.sectionTitle}>{values.textJobType}</Text>
1332
+ <TouchableOpacity onPress={this.onPressType.bind(this)}>
1333
+ <View style={{ flexDirection: "row" }}>
1334
+ <Text
1335
+ style={[
1336
+ styles.sectionTitle,
1337
+ { color: this.props.colourBrandingMain, marginRight: 16 },
1338
+ ]}
1339
+ >
1340
+ {this.state.type}
1341
+ </Text>
1342
+ <Icon
1343
+ name="angle-right"
1344
+ type="font-awesome"
1345
+ iconStyle={[
1346
+ styles.sectionTitle,
1347
+ { fontSize: 20, color: this.props.colourBrandingMain },
1348
+ ]}
1349
+ />
1350
+ </View>
1351
+ </TouchableOpacity>
1352
+ </Components.FormCard>
1353
+ {hasCustomFields ? (
1354
+ this.renderCustomFields()
1355
+ ) : (
1356
+ <>
1357
+ <Components.FormCard style={{ marginTop: 16 }}>
1358
+ <Components.FormCardSection
1359
+ label={"Title"}
1360
+ placeholder={"Enter a title for your request"}
1361
+ textValue={this.state.title}
1362
+ onChangeText={(title) => this.setState({ title })}
1363
+ editable={this.state.submitting === false}
1364
+ hasUnderline
1365
+ isValid={() => {
1366
+ return this.state.title.length > 1;
1367
+ }}
1368
+ required
1369
+ errorText="Please provide a title."
1370
+ showError={
1371
+ this.state.showError && this.state.title.length < 2
1372
+ }
1373
+ autoCorrect
1374
+ multiline
1375
+ autoGrow
1376
+ />
1377
+ <Components.FormCardSection
1378
+ label={"Description"}
1379
+ placeholder={"Describe your request here in detail"}
1380
+ textValue={this.state.description}
1381
+ onChangeText={(description) =>
1382
+ this.setState({ description })
1383
+ }
1384
+ editable={this.state.submitting === false}
1385
+ hasUnderline
1386
+ autoCorrect
1387
+ multiline
1388
+ autoGrow
1389
+ />
1390
+ </Components.FormCard>
1391
+ <Components.FormCard
1392
+ style={{ marginTop: 16, paddingHorizontal: 24 }}
1393
+ >
1394
+ <View
1395
+ style={[
1396
+ {
1397
+ width: "100%",
1398
+ paddingVertical: 16,
1399
+ flexDirection: "row",
1400
+ justifyContent: "space-between",
1401
+ alignItems: "center",
1402
+ position: "relative",
1403
+ },
1404
+ this.state.isHome && {
1405
+ borderBottomWidth: 1,
1406
+ borderBottomColor: Colours.LINEGREY,
1407
+ },
1408
+ ]}
1409
+ >
1410
+ <Text style={styles.sectionTitle}>
1411
+ {Config.env.strings.MAINTENANCE_HOME}
1412
+ </Text>
1413
+ <Switch
1414
+ value={this.state.isHome}
1415
+ disabled={this.state.submitting}
1416
+ onValueChange={(value) =>
1417
+ this.setState({ isHome: value })
1418
+ }
1419
+ trackColor={{
1420
+ false: "#ddd",
1421
+ true: this.props.colourBrandingMain,
1422
+ }}
1423
+ thumbColor={Platform.OS === "android" ? "#fff" : null}
1424
+ />
1425
+ </View>
1426
+ {this.state.isHome && (
1427
+ <Components.FormCardSection
1428
+ label={"Available times"}
1429
+ placeholder={
1430
+ "Describe your available times here in detail."
1431
+ }
1432
+ textValue={this.state.times}
1433
+ onChangeText={(times) => this.setState({ times })}
1434
+ editable={this.state.submitting === false}
1435
+ hasUnderline
1436
+ isValid={() => {
1437
+ return this.state.times.length > 1;
1438
+ }}
1439
+ required
1440
+ errorText="Please provide available times."
1441
+ showError={
1442
+ this.state.showError &&
1443
+ this.state.isHome &&
1444
+ this.state.times.length < 2
1445
+ }
1446
+ minHeight={40}
1447
+ autoCorrect
1448
+ multiline
1449
+ autoGrow
1450
+ />
1451
+ )}
1452
+ </Components.FormCard>
1453
+ {this.renderImageList()}
1454
+ </>
1455
+ )}
1456
+ </View>
1457
+ </ScrollView>
1458
+ </View>
1459
+ );
1460
+ }
1461
+
1462
+ renderRegisterConfirmation() {
1463
+ return (
1464
+ <Components.ConfirmationPopup
1465
+ confirmText={`${values.textEntityName} submitted`}
1466
+ repeatText={"Submit another"}
1467
+ visible={this.state.confirmationToShow}
1468
+ onClose={this.onCloseConfirmationPopup.bind(this)}
1469
+ onPressAction={this.onConfirmationReset.bind(this)}
1470
+ />
1471
+ );
1472
+ }
1473
+
1474
+ renderVideoPlayerPopup() {
1475
+ const { showFullscreenVideo, currentVideoUrl } = this.state;
1476
+ if (!currentVideoUrl) return;
1477
+
1478
+ return (
1479
+ <Components.VideoPopup
1480
+ uri={currentVideoUrl}
1481
+ visible={showFullscreenVideo}
1482
+ showFullscreenButton={false}
1483
+ onClose={this.toggleFullscreenVideo}
1484
+ />
1485
+ );
1486
+ }
1487
+
1488
+ renderNoType() {
1489
+ if (!this.state.noType) {
1490
+ return null;
1491
+ }
1492
+ return (
1493
+ <Components.WarningPopup
1494
+ confirmText={"No forms are available"}
1495
+ infoText={"Check back later for forms."}
1496
+ visible={this.state.noType}
1497
+ onClose={this.onPressBack.bind(this)}
1498
+ padHorizontal
1499
+ />
1500
+ );
1501
+ }
1502
+
1503
+ render() {
1504
+ const { submitting, success, isDateTimePickerVisible, popUpType } =
1505
+ this.state;
1506
+
1507
+ return (
1508
+ <KeyboardAvoidingView behavior={"padding"} style={styles.viewContainer}>
1509
+ {this.renderImageUploader()}
1510
+ <View style={styles.container}>
1511
+ <Components.Header
1512
+ leftIcon="angle-left"
1513
+ onPressLeft={this.onPressBack.bind(this)}
1514
+ text={
1515
+ this.props.strings[`${values.featureKey}_textFeatureTitle`] ||
1516
+ values.textFeatureTitle
1517
+ }
1518
+ rightText={submitting || success ? null : "Done"}
1519
+ onPressRight={this.submitRequest.bind(this)}
1520
+ absoluteRight
1521
+ />
1522
+ {this.renderForm()}
1523
+ </View>
1524
+ {this.renderRegisterConfirmation()}
1525
+ {this.renderVideoPlayerPopup()}
1526
+ {this.renderNoType()}
1527
+ <DateTimePicker
1528
+ isVisible={isDateTimePickerVisible}
1529
+ onConfirm={this.onDateSelected}
1530
+ onCancel={() => this.setState({ isDateTimePickerVisible: false })}
1531
+ mode={popUpType}
1532
+ headerTextIOS={`Pick a ${popUpType}`}
1533
+ />
1534
+ </KeyboardAvoidingView>
1535
+ );
1536
+ }
1325
1537
  }
1326
1538
 
1327
1539
  const styles = {
1328
- viewContainer: {
1329
- flex: 1,
1330
- backgroundColor: '#fff',
1331
- },
1332
- container: {
1333
- flex: 1,
1334
- position: 'relative',
1335
- backgroundColor: '#f0f0f5',
1336
- },
1337
- errorText: {
1338
- fontFamily: 'sf-regular',
1339
- color: Colours.COLOUR_TANGERINE,
1340
- fontSize: 16,
1341
- },
1342
- requestSuccess: {
1343
- fontFamily: 'sf-regular',
1344
- color: Colours.TEXT_DARK,
1345
- fontSize: 17,
1346
- textAlign: 'center',
1347
- },
1348
- sectionTitle: {
1349
- fontFamily: 'sf-regular',
1350
- fontSize: 17,
1351
- color: Colours.TEXT_DARK,
1352
- },
1353
- imageListContainer: {
1354
- marginTop: 8,
1355
- padding: 8,
1356
- flexDirection: 'row',
1357
- backgroundColor: Colours.BOXGREY,
1358
- minHeight: 106,
1359
- },
1360
- imageListContainerEmpty: {
1361
- justifyContent: 'center',
1362
- alignItems: 'center',
1363
- flexDirection: 'column',
1364
- },
1365
- documentListContainer: {
1366
- marginTop: 8,
1367
- flexDirection: 'column',
1368
- alignItems: 'flex-start',
1369
- },
1370
- imageContainer: {
1371
- width: PHOTO_SIZE,
1372
- height: PHOTO_SIZE,
1373
- borderStyle: 'dashed',
1374
- justifyContent: 'center',
1375
- alignItems: 'center',
1376
- borderWidth: 1,
1377
- borderColor: Colours.LINEGREY,
1378
- borderRadius: 4,
1379
- marginLeft: 8,
1380
- },
1381
- imageContainerNotEmpty: {
1382
- borderWidth: 1,
1383
- borderColor: Colours.LINEGREY,
1384
- backgroundColor: '#fff',
1385
- borderStyle: 'dashed',
1386
- },
1387
- imageBackground: {
1388
- flex: 1,
1389
- height: '100%',
1390
- width: '100%',
1391
- borderRadius: 4,
1392
- },
1393
- imageCircle: {
1394
- width: 90,
1395
- height: 90,
1396
- borderRadius: 45,
1397
- backgroundColor: Colours.PINKISH_GREY,
1398
- justifyContent: 'center',
1399
- },
1400
- addImageIcon: {
1401
- color: '#fff',
1402
- fontSize: 32,
1403
- },
1404
- imagePlayContainer: {
1405
- position: 'absolute',
1406
- top: 0,
1407
- left: 0,
1408
- right: 0,
1409
- bottom: 0,
1410
- alignItems: 'center',
1411
- justifyContent: 'center',
1412
- },
1413
- imageControlIcon: {
1414
- color: '#fff',
1415
- fontSize: 20,
1416
- textShadowColor: 'rgba(0,0,0,0.3)',
1417
- textShadowOffset: { width: 2, height: 2 },
1418
- },
1419
- removeImage: {
1420
- position: 'absolute',
1421
- top: 0,
1422
- right: 0,
1423
- padding: 4,
1424
- width: 40,
1425
- height: 40,
1426
- alignItems: 'center',
1427
- justifyContent: 'center',
1428
- },
1429
- staticTitle: {
1430
- fontSize: 20,
1431
- fontFamily: 'sf-semibold',
1432
- color: Colours.TEXT_DARKEST,
1433
- },
1434
- staticText: {
1435
- fontSize: 17,
1436
- fontFamily: 'sf-regular',
1437
- color: Colours.TEXT_DARKEST,
1438
- lineHeight: 24,
1439
- },
1440
- multiChoiceOption: {
1441
- marginTop: 16,
1442
- flexDirection: 'row',
1443
- alignItems: 'center',
1444
- minHeight: 20,
1445
- },
1446
- multiChoiceText: {
1447
- flex: 1,
1448
- fontFamily: 'sf-medium',
1449
- fontSize: 14,
1450
- color: Colours.TEXT_DARK,
1451
- },
1452
- tick: {
1453
- marginRight: 10,
1454
- borderRadius: 4,
1455
- },
1456
- unticked: {
1457
- marginRight: 10,
1458
- width: 20,
1459
- height: 20,
1460
- borderColor: Colours.LINEGREY,
1461
- borderWidth: 1,
1462
- borderRadius: 4,
1463
- },
1464
- dateContainer: {
1465
- flexDirection: 'row',
1466
- alignItems: 'center',
1467
- },
1468
- dateFieldButton: {
1469
- flex: 1,
1470
- },
1471
- dateFieldContainer: {
1472
- flexDirection: 'row',
1473
- borderRadius: 2,
1474
- backgroundColor: '#ebeff2',
1475
- padding: 8,
1476
- marginTop: 8,
1477
- },
1478
- dateText: {
1479
- flex: 1,
1480
- fontFamily: 'sf-regular',
1481
- fontSize: 16,
1482
- color: '#65686D',
1483
- },
1484
- dateIcon: {
1485
- fontSize: 18,
1486
- color: Colours.TEXT_BLUEGREY,
1487
- },
1488
- dateClearButton: {
1489
- paddingLeft: 12,
1490
- },
1491
- removeIcon: {
1492
- fontSize: 26,
1493
- color: Colours.TEXT_BLUEGREY,
1494
- },
1495
- documentContainer: {
1496
- flexDirection: 'row',
1497
- alignItems: 'center',
1498
- justifyContent: 'space-between',
1499
- paddingVertical: 4,
1500
- },
1501
- documentTypeContainer: {
1502
- width: 50,
1503
- height: 60,
1504
- justifyContent: 'center',
1505
- alignItems: 'center',
1506
- borderRadius: 5,
1507
- marginRight: 8,
1508
- },
1509
- documentTypeText: {
1510
- color: '#fff',
1511
- fontFamily: 'sf-semibold',
1512
- textAlign: 'center',
1513
- },
1514
- documentText: {
1515
- flex: 1,
1516
- fontFamily: 'sf-semibold',
1517
- fontSize: 16,
1518
- color: '#65686D',
1519
- },
1520
- removeDocumentButton: {
1521
- padding: 4,
1522
- width: 40,
1523
- height: 40,
1524
- alignItems: 'center',
1525
- justifyContent: 'center',
1526
- marginLeft: 8,
1527
- },
1528
- removeDocumentIcon: {
1529
- fontSize: 24,
1530
- },
1531
- // PC-1255: User picker styles
1532
- userPickerContainer: {
1533
- flexDirection: 'row',
1534
- justifyContent: 'space-between',
1535
- alignItems: 'center',
1536
- },
1537
- profileContainer: {
1538
- flexDirection: 'row',
1539
- alignItems: 'center',
1540
- },
1541
- nameText: {
1542
- fontFamily: 'sf-medium',
1543
- fontSize: 16,
1544
- color: Colours.TEXT_DARK,
1545
- marginLeft: 8,
1546
- },
1540
+ viewContainer: {
1541
+ flex: 1,
1542
+ backgroundColor: "#fff",
1543
+ },
1544
+ container: {
1545
+ flex: 1,
1546
+ position: "relative",
1547
+ backgroundColor: "#f0f0f5",
1548
+ },
1549
+ errorText: {
1550
+ fontFamily: "sf-regular",
1551
+ color: Colours.COLOUR_TANGERINE,
1552
+ fontSize: 16,
1553
+ },
1554
+ requestSuccess: {
1555
+ fontFamily: "sf-regular",
1556
+ color: Colours.TEXT_DARK,
1557
+ fontSize: 17,
1558
+ textAlign: "center",
1559
+ },
1560
+ sectionTitle: {
1561
+ fontFamily: "sf-regular",
1562
+ fontSize: 17,
1563
+ color: Colours.TEXT_DARK,
1564
+ },
1565
+ imageListContainer: {
1566
+ marginTop: 8,
1567
+ padding: 8,
1568
+ flexDirection: "row",
1569
+ backgroundColor: Colours.BOXGREY,
1570
+ minHeight: 106,
1571
+ },
1572
+ imageListContainerEmpty: {
1573
+ justifyContent: "center",
1574
+ alignItems: "center",
1575
+ flexDirection: "column",
1576
+ },
1577
+ documentListContainer: {
1578
+ marginTop: 8,
1579
+ flexDirection: "column",
1580
+ alignItems: "flex-start",
1581
+ },
1582
+ imageContainer: {
1583
+ width: PHOTO_SIZE,
1584
+ height: PHOTO_SIZE,
1585
+ borderStyle: "dashed",
1586
+ justifyContent: "center",
1587
+ alignItems: "center",
1588
+ borderWidth: 1,
1589
+ borderColor: Colours.LINEGREY,
1590
+ borderRadius: 4,
1591
+ marginLeft: 8,
1592
+ },
1593
+ imageContainerNotEmpty: {
1594
+ borderWidth: 1,
1595
+ borderColor: Colours.LINEGREY,
1596
+ backgroundColor: "#fff",
1597
+ borderStyle: "dashed",
1598
+ },
1599
+ imageBackground: {
1600
+ flex: 1,
1601
+ height: "100%",
1602
+ width: "100%",
1603
+ borderRadius: 4,
1604
+ },
1605
+ imageCircle: {
1606
+ width: 90,
1607
+ height: 90,
1608
+ borderRadius: 45,
1609
+ backgroundColor: Colours.PINKISH_GREY,
1610
+ justifyContent: "center",
1611
+ },
1612
+ addImageIcon: {
1613
+ color: "#fff",
1614
+ fontSize: 32,
1615
+ },
1616
+ imagePlayContainer: {
1617
+ position: "absolute",
1618
+ top: 0,
1619
+ left: 0,
1620
+ right: 0,
1621
+ bottom: 0,
1622
+ alignItems: "center",
1623
+ justifyContent: "center",
1624
+ },
1625
+ imageControlIcon: {
1626
+ color: "#fff",
1627
+ fontSize: 20,
1628
+ textShadowColor: "rgba(0,0,0,0.3)",
1629
+ textShadowOffset: { width: 2, height: 2 },
1630
+ },
1631
+ removeImage: {
1632
+ position: "absolute",
1633
+ top: 0,
1634
+ right: 0,
1635
+ padding: 4,
1636
+ width: 40,
1637
+ height: 40,
1638
+ alignItems: "center",
1639
+ justifyContent: "center",
1640
+ },
1641
+ staticTitle: {
1642
+ fontSize: 20,
1643
+ fontFamily: "sf-semibold",
1644
+ color: Colours.TEXT_DARKEST,
1645
+ },
1646
+ staticText: {
1647
+ fontSize: 17,
1648
+ fontFamily: "sf-regular",
1649
+ color: Colours.TEXT_DARKEST,
1650
+ lineHeight: 24,
1651
+ },
1652
+ multiChoiceOption: {
1653
+ marginTop: 16,
1654
+ flexDirection: "row",
1655
+ alignItems: "center",
1656
+ minHeight: 20,
1657
+ },
1658
+ multiChoiceText: {
1659
+ flex: 1,
1660
+ fontFamily: "sf-medium",
1661
+ fontSize: 14,
1662
+ color: Colours.TEXT_DARK,
1663
+ },
1664
+ tick: {
1665
+ marginRight: 10,
1666
+ borderRadius: 4,
1667
+ },
1668
+ unticked: {
1669
+ marginRight: 10,
1670
+ width: 20,
1671
+ height: 20,
1672
+ borderColor: Colours.LINEGREY,
1673
+ borderWidth: 1,
1674
+ borderRadius: 4,
1675
+ },
1676
+ dateContainer: {
1677
+ flexDirection: "row",
1678
+ alignItems: "center",
1679
+ },
1680
+ dateFieldButton: {
1681
+ flex: 1,
1682
+ },
1683
+ dateFieldContainer: {
1684
+ flexDirection: "row",
1685
+ borderRadius: 2,
1686
+ backgroundColor: "#ebeff2",
1687
+ padding: 8,
1688
+ marginTop: 8,
1689
+ },
1690
+ dateText: {
1691
+ flex: 1,
1692
+ fontFamily: "sf-regular",
1693
+ fontSize: 16,
1694
+ color: "#65686D",
1695
+ },
1696
+ dateIcon: {
1697
+ fontSize: 18,
1698
+ color: Colours.TEXT_BLUEGREY,
1699
+ },
1700
+ dateClearButton: {
1701
+ paddingLeft: 12,
1702
+ },
1703
+ removeIcon: {
1704
+ fontSize: 26,
1705
+ color: Colours.TEXT_BLUEGREY,
1706
+ },
1707
+ documentContainer: {
1708
+ flexDirection: "row",
1709
+ alignItems: "center",
1710
+ justifyContent: "space-between",
1711
+ paddingVertical: 4,
1712
+ },
1713
+ documentTypeContainer: {
1714
+ width: 50,
1715
+ height: 60,
1716
+ justifyContent: "center",
1717
+ alignItems: "center",
1718
+ borderRadius: 5,
1719
+ marginRight: 8,
1720
+ },
1721
+ documentTypeText: {
1722
+ color: "#fff",
1723
+ fontFamily: "sf-semibold",
1724
+ textAlign: "center",
1725
+ },
1726
+ documentText: {
1727
+ flex: 1,
1728
+ fontFamily: "sf-semibold",
1729
+ fontSize: 16,
1730
+ color: "#65686D",
1731
+ },
1732
+ removeDocumentButton: {
1733
+ padding: 4,
1734
+ width: 40,
1735
+ height: 40,
1736
+ alignItems: "center",
1737
+ justifyContent: "center",
1738
+ marginLeft: 8,
1739
+ },
1740
+ removeDocumentIcon: {
1741
+ fontSize: 24,
1742
+ },
1743
+ // PC-1255: User picker styles
1744
+ userPickerContainer: {
1745
+ flexDirection: "row",
1746
+ justifyContent: "space-between",
1747
+ alignItems: "center",
1748
+ },
1749
+ profileContainer: {
1750
+ flexDirection: "row",
1751
+ alignItems: "center",
1752
+ },
1753
+ nameText: {
1754
+ fontFamily: "sf-medium",
1755
+ fontSize: 16,
1756
+ color: Colours.TEXT_DARK,
1757
+ marginLeft: 8,
1758
+ },
1547
1759
  };
1548
1760
 
1549
- const mapStateToProps = state => {
1550
- const { user, connection } = state;
1551
- const { displayName, profilePic, uid, site, unit, phoneNumber, permissions } = user;
1552
- return {
1553
- connected: connection.connected,
1554
- userType: user.type,
1555
- displayName,
1556
- profilePic,
1557
- uid,
1558
- site,
1559
- unit,
1560
- phoneNumber,
1561
- permissions,
1562
- colourBrandingMain: Colours.getMainBrandingColourFromState(state),
1563
- strings: state.strings?.config || {},
1564
- optionOnlyForResidents: Helper.getSiteSettingFromState(state, values.optionOnlyForResidents),
1565
- };
1761
+ const mapStateToProps = (state) => {
1762
+ const { user, connection } = state;
1763
+ const { displayName, profilePic, uid, site, unit, phoneNumber, permissions } =
1764
+ user;
1765
+ return {
1766
+ connected: connection.connected,
1767
+ userType: user.type,
1768
+ displayName,
1769
+ profilePic,
1770
+ uid,
1771
+ site,
1772
+ unit,
1773
+ phoneNumber,
1774
+ permissions,
1775
+ colourBrandingMain: Colours.getMainBrandingColourFromState(state),
1776
+ strings: state.strings?.config || {},
1777
+ optionOnlyForResidents: Helper.getSiteSettingFromState(
1778
+ state,
1779
+ values.optionOnlyForResidents,
1780
+ ),
1781
+ };
1566
1782
  };
1567
1783
 
1568
1784
  export default connect(mapStateToProps, { jobAdded })(MaintenanceRequest);