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