@plusscommunities/pluss-maintenance-app 6.0.21-beta.0 → 6.0.22-beta.0

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