@tellescope/react-components 1.227.0 → 1.229.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.
- package/lib/cjs/Forms/forms.v2.d.ts +116 -0
- package/lib/cjs/Forms/forms.v2.d.ts.map +1 -0
- package/lib/cjs/Forms/forms.v2.js +760 -0
- package/lib/cjs/Forms/forms.v2.js.map +1 -0
- package/lib/cjs/Forms/hooks.d.ts.map +1 -1
- package/lib/cjs/Forms/hooks.js +8 -3
- package/lib/cjs/Forms/hooks.js.map +1 -1
- package/lib/cjs/Forms/index.d.ts +1 -0
- package/lib/cjs/Forms/index.d.ts.map +1 -1
- package/lib/cjs/Forms/index.js +6 -0
- package/lib/cjs/Forms/index.js.map +1 -1
- package/lib/cjs/Forms/inputs.v2.d.ts +81 -0
- package/lib/cjs/Forms/inputs.v2.d.ts.map +1 -0
- package/lib/cjs/Forms/inputs.v2.js +2289 -0
- package/lib/cjs/Forms/inputs.v2.js.map +1 -0
- package/lib/cjs/Forms/localization.d.ts.map +1 -1
- package/lib/cjs/Forms/localization.js +3 -0
- package/lib/cjs/Forms/localization.js.map +1 -1
- package/lib/cjs/Forms/types.d.ts +1 -0
- package/lib/cjs/Forms/types.d.ts.map +1 -1
- package/lib/cjs/state.d.ts +34 -0
- package/lib/cjs/state.d.ts.map +1 -1
- package/lib/cjs/state.js +16 -2
- package/lib/cjs/state.js.map +1 -1
- package/lib/esm/Forms/forms.v2.d.ts +116 -0
- package/lib/esm/Forms/forms.v2.d.ts.map +1 -0
- package/lib/esm/Forms/forms.v2.js +725 -0
- package/lib/esm/Forms/forms.v2.js.map +1 -0
- package/lib/esm/Forms/hooks.d.ts.map +1 -1
- package/lib/esm/Forms/hooks.js +8 -3
- package/lib/esm/Forms/hooks.js.map +1 -1
- package/lib/esm/Forms/index.d.ts +1 -0
- package/lib/esm/Forms/index.d.ts.map +1 -1
- package/lib/esm/Forms/index.js +2 -0
- package/lib/esm/Forms/index.js.map +1 -1
- package/lib/esm/Forms/inputs.v2.d.ts +81 -0
- package/lib/esm/Forms/inputs.v2.d.ts.map +1 -0
- package/lib/esm/Forms/inputs.v2.js +2218 -0
- package/lib/esm/Forms/inputs.v2.js.map +1 -0
- package/lib/esm/Forms/localization.d.ts.map +1 -1
- package/lib/esm/Forms/localization.js +3 -0
- package/lib/esm/Forms/localization.js.map +1 -1
- package/lib/esm/Forms/types.d.ts +1 -0
- package/lib/esm/Forms/types.d.ts.map +1 -1
- package/lib/esm/state.d.ts +34 -0
- package/lib/esm/state.d.ts.map +1 -1
- package/lib/esm/state.js +13 -0
- package/lib/esm/state.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/src/Forms/forms.v2.tsx +1321 -0
- package/src/Forms/hooks.tsx +10 -5
- package/src/Forms/index.ts +5 -2
- package/src/Forms/inputs.v2.tsx +3869 -0
- package/src/Forms/localization.ts +1 -0
- package/src/Forms/types.ts +1 -0
- package/src/state.tsx +25 -5
|
@@ -0,0 +1,725 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
49
|
+
var t = {};
|
|
50
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
51
|
+
t[p] = s[p];
|
|
52
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
53
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
54
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
55
|
+
t[p[i]] = s[p[i]];
|
|
56
|
+
}
|
|
57
|
+
return t;
|
|
58
|
+
};
|
|
59
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
60
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
61
|
+
if (ar || !(i in from)) {
|
|
62
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
63
|
+
ar[i] = from[i];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
67
|
+
};
|
|
68
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
69
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
70
|
+
import { Button, CircularProgress, Flex, LoadingButton, Modal, Typography, WithTheme, form_display_text_for_language, useFileUpload, useFormResponses, useSession } from "../index";
|
|
71
|
+
import { useListForFormFields, useOrganizationTheme, WithOrganizationTheme } from "./hooks";
|
|
72
|
+
import { AddressInput, AllergiesInput, AppointmentBookingInput, ChargeebeeInput, ConditionsInput, DatabaseSelectInput, DateInput, DateStringInput, DropdownInput, EmailInput, EmotiiInput, FileInput, FilesInput, HeightInput, HiddenValueInput, InsuranceInput, LanguageSelect, MedicationsInput, MultipleChoiceInput, NumberInput, PhoneInput, Progress, RankingInput, RatingInput, RedirectInput, RelatedContactsInput, RichTextInput, SignatureInput, StringInput, StringLongInput, StripeInput, TableInput, TimeInput, TimezoneInput, defaultButtonStyles } from "./inputs.v2";
|
|
73
|
+
import { PRIMARY_HEX } from "@tellescope/constants";
|
|
74
|
+
import { calculate_form_scoring, field_can_autosubmit, form_response_value_to_string, formatted_date, object_is_empty, objects_equivalent, read_local_storage, remove_script_tags, responses_satisfy_conditions, truncate_string } from "@tellescope/utilities";
|
|
75
|
+
import { Divider } from "@mui/material";
|
|
76
|
+
export var TellescopeFormContainerV2 = function (_a) {
|
|
77
|
+
var businessId = _a.businessId, organizationIds = _a.organizationIds, props = __rest(_a, ["businessId", "organizationIds"]);
|
|
78
|
+
// if context already is provided, no need to duplicate
|
|
79
|
+
if (props.dontAddContext)
|
|
80
|
+
return (_jsx(TellescopeFormContainerWithThemeV2, __assign({}, props)));
|
|
81
|
+
return (_jsx(WithOrganizationTheme, __assign({ businessId: businessId, organizationIds: organizationIds }, { children: _jsx(TellescopeFormContainerWithThemeV2, __assign({}, props)) })));
|
|
82
|
+
};
|
|
83
|
+
var TellescopeFormContainerWithThemeV2 = function (_a) {
|
|
84
|
+
var _b = _a.paperMinHeight, paperMinHeight = _b === void 0 ? 575 : _b, children = _a.children, language = _a.language, onChangeLanguage = _a.onChangeLanguage, style = _a.style, hideBg = _a.hideBg, backgroundColor = _a.backgroundColor, hideLogo = _a.hideLogo, logoHeight = _a.logoHeight, maxWidth = _a.maxWidth;
|
|
85
|
+
var theme = useOrganizationTheme();
|
|
86
|
+
// V2: No paper background by default, cleaner layout with light blue background
|
|
87
|
+
// Ignore theme colors or white backgrounds - use our V2 default light blue
|
|
88
|
+
var shouldUseCustomBg = backgroundColor && backgroundColor !== theme.themeColor && backgroundColor !== '#ffffff';
|
|
89
|
+
var finalBgColor = shouldUseCustomBg ? backgroundColor : '#F4F3FA';
|
|
90
|
+
return (_jsx(Flex, __assign({ flex: 1, column: true, alignItems: "center", style: __assign({ backgroundColor: finalBgColor, overflow: 'hidden', paddingTop: 40, paddingBottom: 40 }, style) }, { children: _jsxs(Flex, __assign({ flex: 1, column: true, style: { padding: '0 20px', maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : 650, minWidth: 250, width: '100%', height: '100%' } }, { children: [language && onChangeLanguage &&
|
|
91
|
+
_jsx(Flex, __assign({ style: { marginTop: 22 } }, { children: _jsx(LanguageSelect, { value: language, onChange: onChangeLanguage }) })), children] })) })));
|
|
92
|
+
};
|
|
93
|
+
var LOGO_HEIGHT = 40;
|
|
94
|
+
export var TellescopeFormV2 = function (props) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
return (_jsx(WithOrganizationTheme, { children: _jsx(TellescopeFormWithContextV2, __assign({}, props, { logoHeight: (props === null || props === void 0 ? void 0 : props.logoHeight) || ((_b = (_a = props === null || props === void 0 ? void 0 : props.form) === null || _a === void 0 ? void 0 : _a.customization) === null || _b === void 0 ? void 0 : _b.logoHeight) })) }));
|
|
97
|
+
};
|
|
98
|
+
export var QuestionForField = function (_a) {
|
|
99
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16;
|
|
100
|
+
var form = _a.form, value = _a.value, field = _a.field, file = _a.file, responses = _a.responses, selectedFiles = _a.selectedFiles, onAddFile = _a.onAddFile, onFieldChange = _a.onFieldChange, customInputs = _a.customInputs, fields = _a.fields, validateField = _a.validateField, repeats = _a.repeats, onRepeatsChange = _a.onRepeatsChange, setCustomerId = _a.setCustomerId, handleDatabaseSelect = _a.handleDatabaseSelect, enduser = _a.enduser, goToPreviousField = _a.goToPreviousField, isPreviousDisabled = _a.isPreviousDisabled, enduserId = _a.enduserId, formResponseId = _a.formResponseId, submit = _a.submit, groupId = _a.groupId, groupInstance = _a.groupInstance, goToNextField = _a.goToNextField, spacing = _a.spacing, isSinglePage = _a.isSinglePage, rootResponseId = _a.rootResponseId, isInQuestionGroup = _a.isInQuestionGroup, logicOptions = _a.logicOptions, uploadingFiles = _a.uploadingFiles, setUploadingFiles = _a.setUploadingFiles, handleFileUpload = _a.handleFileUpload, groupFields = _a.groupFields, AddToDatabase = _a.AddToDatabase;
|
|
101
|
+
var String = (_b = customInputs === null || customInputs === void 0 ? void 0 : customInputs['string']) !== null && _b !== void 0 ? _b : StringInput;
|
|
102
|
+
var StringLong = (_c = customInputs === null || customInputs === void 0 ? void 0 : customInputs['stringLong']) !== null && _c !== void 0 ? _c : StringLongInput;
|
|
103
|
+
var Email = (_d = customInputs === null || customInputs === void 0 ? void 0 : customInputs['email']) !== null && _d !== void 0 ? _d : EmailInput;
|
|
104
|
+
var Number = (_e = customInputs === null || customInputs === void 0 ? void 0 : customInputs['number']) !== null && _e !== void 0 ? _e : NumberInput;
|
|
105
|
+
var Phone = (_f = customInputs === null || customInputs === void 0 ? void 0 : customInputs['phone']) !== null && _f !== void 0 ? _f : PhoneInput;
|
|
106
|
+
var ResolvedDateInput = (_g = customInputs === null || customInputs === void 0 ? void 0 : customInputs['date']) !== null && _g !== void 0 ? _g : DateInput;
|
|
107
|
+
var Signature = (_h = customInputs === null || customInputs === void 0 ? void 0 : customInputs['signature']) !== null && _h !== void 0 ? _h : SignatureInput;
|
|
108
|
+
var MultipleChoice = (_j = customInputs === null || customInputs === void 0 ? void 0 : customInputs['multiple_choice']) !== null && _j !== void 0 ? _j : MultipleChoiceInput;
|
|
109
|
+
var Stripe = (_k = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Stripe']) !== null && _k !== void 0 ? _k : StripeInput;
|
|
110
|
+
var Chargebee = (_l = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Chargebee']) !== null && _l !== void 0 ? _l : ChargeebeeInput;
|
|
111
|
+
var File = (_m = customInputs === null || customInputs === void 0 ? void 0 : customInputs['file']) !== null && _m !== void 0 ? _m : FileInput;
|
|
112
|
+
var Files = (_o = customInputs === null || customInputs === void 0 ? void 0 : customInputs['files']) !== null && _o !== void 0 ? _o : FilesInput;
|
|
113
|
+
var Ranking = (_p = customInputs === null || customInputs === void 0 ? void 0 : customInputs['ranking']) !== null && _p !== void 0 ? _p : RankingInput;
|
|
114
|
+
var Rating = (_q = customInputs === null || customInputs === void 0 ? void 0 : customInputs['rating']) !== null && _q !== void 0 ? _q : RatingInput;
|
|
115
|
+
var Address = (_s = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Address']) !== null && _s !== void 0 ? _s : AddressInput;
|
|
116
|
+
var Time = (_t = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Time']) !== null && _t !== void 0 ? _t : TimeInput;
|
|
117
|
+
var TimeZone = (_u = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Timezone']) !== null && _u !== void 0 ? _u : TimezoneInput;
|
|
118
|
+
var Dropdown = (_v = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Dropdown']) !== null && _v !== void 0 ? _v : DropdownInput;
|
|
119
|
+
var DatabaseSelect = (_w = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Database Select']) !== null && _w !== void 0 ? _w : DatabaseSelectInput;
|
|
120
|
+
var Medications = (_x = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Medications']) !== null && _x !== void 0 ? _x : MedicationsInput;
|
|
121
|
+
var RelatedContacts = (_y = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Related Contacts']) !== null && _y !== void 0 ? _y : RelatedContactsInput;
|
|
122
|
+
var Insurance = (_z = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Insurance']) !== null && _z !== void 0 ? _z : InsuranceInput;
|
|
123
|
+
var AppointmentBooking = (_0 = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Appointment Booking']) !== null && _0 !== void 0 ? _0 : AppointmentBookingInput;
|
|
124
|
+
var Height = (_1 = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Height']) !== null && _1 !== void 0 ? _1 : HeightInput;
|
|
125
|
+
var Redirect = (_2 = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Redirect']) !== null && _2 !== void 0 ? _2 : RedirectInput;
|
|
126
|
+
var HiddenValue = (_3 = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Hidden Value']) !== null && _3 !== void 0 ? _3 : HiddenValueInput;
|
|
127
|
+
var Emotii = (_4 = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Emotii']) !== null && _4 !== void 0 ? _4 : EmotiiInput;
|
|
128
|
+
var Allergies = (_5 = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Allergies']) !== null && _5 !== void 0 ? _5 : AllergiesInput;
|
|
129
|
+
var Conditions = (_6 = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Conditions']) !== null && _6 !== void 0 ? _6 : ConditionsInput;
|
|
130
|
+
var RichText = (_7 = customInputs === null || customInputs === void 0 ? void 0 : customInputs['Rich Text']) !== null && _7 !== void 0 ? _7 : RichTextInput;
|
|
131
|
+
var validationMessage = validateField(field);
|
|
132
|
+
var feedback = useMemo(function () { return ((field.feedback || [])
|
|
133
|
+
.filter(function (_a) {
|
|
134
|
+
var display = _a.display, ifEquals = _a.ifEquals;
|
|
135
|
+
return (ifEquals === value.answer.value
|
|
136
|
+
|| (Array.isArray(value.answer.value) && value.answer.value.includes(ifEquals)));
|
|
137
|
+
})
|
|
138
|
+
.map(function (v) { return v.display; })); }, [field.feedback, value]);
|
|
139
|
+
if (!value)
|
|
140
|
+
return null;
|
|
141
|
+
if (isInQuestionGroup
|
|
142
|
+
&& field.groupShowCondition && !object_is_empty(field.groupShowCondition)
|
|
143
|
+
&& !responses_satisfy_conditions(responses, field.groupShowCondition, logicOptions)) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return (
|
|
147
|
+
// margin leaves room for error message in Question Group
|
|
148
|
+
_jsxs(Flex, __assign({ column: true, flex: 1, style: { marginBottom: spacing !== null && spacing !== void 0 ? spacing : 25 }, id: field.id }, { children: [field.type !== 'Redirect' && field.title &&
|
|
149
|
+
_jsxs(Typography, __assign({ component: "h4", style: {
|
|
150
|
+
marginTop: 15,
|
|
151
|
+
marginBottom: 14,
|
|
152
|
+
fontSize: field.titleFontSize || (field.type === 'Question Group' ? 22 : 20),
|
|
153
|
+
fontWeight: field.type === 'Question Group' ? 'bold' : undefined,
|
|
154
|
+
} }, { children: [field.title, !(field.isOptional || field.type === 'description' || field.type === 'Question Group' || field.type === 'Insurance') ? '*' : ''] })), !field.title && (field.type === 'Question Group' || field.type === 'signature') && !((_8 = form === null || form === void 0 ? void 0 : form.customization) === null || _8 === void 0 ? void 0 : _8.hideLogo) &&
|
|
155
|
+
// ensures PDF display doesn't push description into overlap with logo / title at top of form
|
|
156
|
+
// also ensures spacing between logo and question group
|
|
157
|
+
_jsx("div", { style: { marginTop: 15 } }), feedback.length > 0 &&
|
|
158
|
+
_jsx(Flex, __assign({ column: true, style: { marginBottom: 11, marginTop: 3, } }, { children: feedback.map(function (f, i) { return (_jsx(Typography, __assign({ color: "error", style: { fontSize: 20 } }, { children: f }), i)); }) })),
|
|
159
|
+
// If field has pre-populated value and is set to be disabled when pre-populated, show as underlined text
|
|
160
|
+
field.disabledWhenPrepopulated && value.answer.value !== undefined && value.answer.value !== null && value.answer.value !== '' ? (_jsx("div", __assign({ style: {
|
|
161
|
+
padding: '8px 0',
|
|
162
|
+
borderBottom: '1px solid rgba(0, 0, 0, 0.42)',
|
|
163
|
+
width: '100%'
|
|
164
|
+
} }, { children: _jsx(Typography, __assign({ style: {
|
|
165
|
+
fontSize: '1rem',
|
|
166
|
+
color: 'rgba(0, 0, 0, 0.87)',
|
|
167
|
+
whiteSpace: 'pre-wrap'
|
|
168
|
+
} }, { children: form_response_value_to_string(value.answer.value) })) })))
|
|
169
|
+
: field.type === 'file' ? (_jsx(File, { field: field, value: (_9 = file.blobs) === null || _9 === void 0 ? void 0 : _9[0], onChange: onAddFile, form: form, existingFileName: value.answer.type === 'file'
|
|
170
|
+
? (_10 = value.answer.value) === null || _10 === void 0 ? void 0 : _10.name
|
|
171
|
+
: '', handleFileUpload: handleFileUpload, uploadingFiles: uploadingFiles, setUploadingFiles: setUploadingFiles }))
|
|
172
|
+
: field.type === 'files' ? (_jsx(Files, { field: field, value: file.blobs, onChange: onAddFile, form: form,
|
|
173
|
+
// existingFileName={
|
|
174
|
+
// value.answer.type === 'files'
|
|
175
|
+
// ? value.answer.value?.name
|
|
176
|
+
// : ''
|
|
177
|
+
// }
|
|
178
|
+
handleFileUpload: handleFileUpload, uploadingFiles: uploadingFiles, setUploadingFiles: setUploadingFiles }))
|
|
179
|
+
: field.type === 'dateString' ? (_jsx(DateStringInput, { field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
180
|
+
: field.type === 'Hidden Value' ? (_jsx(HiddenValue, { groupFields: groupFields, isSinglePage: isSinglePage, goToNextField: goToNextField, goToPreviousField: goToPreviousField, field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
181
|
+
: field.type === 'Address' ? (_jsx(Address, { field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
182
|
+
: field.type === 'Emotii' ? (_jsx(Emotii, { enduser: enduser, enduserId: enduserId, field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
183
|
+
: field.type === 'Allergies' ? (_jsx(Allergies, { enduser: enduser, enduserId: enduserId, field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
184
|
+
: field.type === 'Conditions' ? (_jsx(Conditions, { enduser: enduser, enduserId: enduserId, field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
185
|
+
: field.type === 'Height' ? (_jsx(Height, { field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
186
|
+
: field.type === 'Redirect' ? (_jsx(Redirect, { enduserId: enduserId, rootResponseId: rootResponseId, formResponseId: formResponseId, responses: responses, enduser: enduser, groupId: groupId, groupInsance: groupInstance, submit: submit, field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
187
|
+
: field.type === 'Related Contacts' ? (_jsx(RelatedContacts, { field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
188
|
+
: field.type === 'string' ? (_jsx(String, { field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form, error: !!validationMessage && (!['A response is required', 'A value must be checked', 'A file is required', 'Enter a valid phone number', 'Insurer is required'].includes(validationMessage) || value.touched) }))
|
|
189
|
+
: field.type === 'Appointment Booking' ? (_jsx(AppointmentBooking, { formResponseId: formResponseId, enduserId: enduserId, goToPreviousField: goToPreviousField, isPreviousDisabled: isPreviousDisabled, responses: responses, field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
190
|
+
: field.type === 'Stripe' ? (_jsx(Stripe, { enduserId: enduserId, field: field, value: value.answer.value, onChange: onFieldChange, setCustomerId: setCustomerId, form: form }))
|
|
191
|
+
: field.type === 'Chargebee' ? (_jsx(Chargebee, { field: field, value: value.answer.value, onChange: onFieldChange, setCustomerId: setCustomerId, form: form }))
|
|
192
|
+
: field.type === 'stringLong' ? (_jsx(StringLong, { field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form, error: !!validationMessage && (!['A response is required', 'A value must be checked', 'A file is required', 'Enter a valid phone number', 'Insurer is required'].includes(validationMessage) || value.touched) }))
|
|
193
|
+
: field.type === 'Rich Text' ? (_jsx(RichText, { field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
194
|
+
: field.type === 'email' ? (_jsx(Email, { field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form, error: !!validationMessage && (!['A response is required', 'A value must be checked', 'A file is required', 'Enter a valid phone number', 'Insurer is required'].includes(validationMessage) || value.touched) }))
|
|
195
|
+
: field.type === 'number' ? (_jsx(Number, { field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form, error: !!validationMessage && (!['A response is required', 'A value must be checked', 'A file is required', 'Enter a valid phone number', 'Insurer is required'].includes(validationMessage) || value.touched) }))
|
|
196
|
+
: field.type === 'phone' ? (_jsx(Phone, { field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, form: form, error: !!validationMessage && (!['A response is required', 'A value must be checked', 'A file is required', 'Enter a valid phone number', 'Insurer is required'].includes(validationMessage) || value.touched) }))
|
|
197
|
+
: field.type === 'date' ? (_jsx(ResolvedDateInput, { field: field, disabled: value.disabled, value: value.answer.value ? new Date(value.answer.value) : undefined, onChange: onFieldChange, form: form }))
|
|
198
|
+
: field.type === 'signature' ? (_jsx(Signature, { enduser: enduser, field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
199
|
+
: field.type === 'multiple_choice' ? (_jsx(MultipleChoice, { field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
200
|
+
: field.type === 'Dropdown' ? (_jsx(Dropdown, { field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
201
|
+
: field.type === 'Database Select' ? (_jsx(DatabaseSelect, { field: field, disabled: value.disabled, value: value.answer.value, onChange: onFieldChange, onDatabaseSelect: handleDatabaseSelect, responses: responses, form: form, AddToDatabase: AddToDatabase }))
|
|
202
|
+
: field.type === 'Medications' ? (_jsx(Medications, { field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
203
|
+
: field.type === 'Insurance' ? (_jsx(Insurance, { field: field, value: value.answer.value, form: form, onDatabaseSelect: handleDatabaseSelect, enduser: enduser, responses: responses, onChange: function (v, fieldId) { return onFieldChange(__assign(__assign({}, v), { relationship: (v === null || v === void 0 ? void 0 : v.relationship) || 'Self' }), fieldId); } }))
|
|
204
|
+
: field.type === 'rating' ? (_jsx(Rating, { field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
205
|
+
: field.type === 'ranking' ? (_jsx(Ranking, { field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
206
|
+
: field.type === 'Table Input' ? (_jsx(TableInput, { field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
207
|
+
: field.type === 'Timezone' ? (_jsx(TimezoneInput, { field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
208
|
+
: field.type === 'Time' ? (_jsx(Time, { field: field, value: value.answer.value, onChange: onFieldChange, form: form }))
|
|
209
|
+
: field.type === 'Question Group' ? (_jsx(Flex, __assign({ column: true, flex: 1 }, { children: ((_12 = (_11 = field.options) === null || _11 === void 0 ? void 0 : _11.subFields) !== null && _12 !== void 0 ? _12 : []).map(function (_a, indexInGroup) {
|
|
210
|
+
var _b, _c, _d;
|
|
211
|
+
var id = _a.id;
|
|
212
|
+
var match = fields.find(function (f) { return f.id === id; });
|
|
213
|
+
if (!match)
|
|
214
|
+
return null;
|
|
215
|
+
var value = responses.find(function (r) { return r.fieldId === match.id; });
|
|
216
|
+
var file = selectedFiles.find(function (r) { return r.fieldId === match.id; });
|
|
217
|
+
if (!value)
|
|
218
|
+
return null;
|
|
219
|
+
if (!file)
|
|
220
|
+
return null;
|
|
221
|
+
return (_jsx(Flex, __assign({ flex: 1 }, { children: _jsx(QuestionForField, { groupId: groupId, groupInstance: groupInstance, customInputs: customInputs, field: match, fields: fields, handleDatabaseSelect: handleDatabaseSelect, enduser: enduser, goToPreviousField: goToPreviousField, isPreviousDisabled: isPreviousDisabled, goToNextField: goToNextField, form: form, formResponseId: formResponseId, rootResponseId: rootResponseId, submit: submit, repeats: repeats, onRepeatsChange: onRepeatsChange, setCustomerId: setCustomerId, value: value, file: file, onAddFile: onAddFile, onFieldChange: onFieldChange, responses: responses, selectedFiles: selectedFiles, validateField: validateField, enduserId: enduserId, spacing: (_b = field.options) === null || _b === void 0 ? void 0 : _b.groupPadding, logicOptions: logicOptions, isInQuestionGroup: true, groupFields: fields.filter(function (f) { var _a, _b; return (_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.subFields) === null || _b === void 0 ? void 0 : _b.find(function (s) { return s.id === f.id; }); }), questionGroupSize: (_d = (_c = field.options) === null || _c === void 0 ? void 0 : _c.subFields) === null || _d === void 0 ? void 0 : _d.length, uploadingFiles: uploadingFiles, setUploadingFiles: setUploadingFiles, handleFileUpload: handleFileUpload, AddToDatabase: AddToDatabase }) }), id));
|
|
222
|
+
}) })))
|
|
223
|
+
: null, ((_13 = field.options) === null || _13 === void 0 ? void 0 : _13.repeat) && (_jsx(Flex, __assign({ style: { marginTop: '8px' } }, { children: field.type === 'string' ? (_jsx(String, { field: field, label: "Repeat", value: (_14 = repeats[field.id]) !== null && _14 !== void 0 ? _14 : '', onChange: function (u) {
|
|
224
|
+
var _a;
|
|
225
|
+
return onRepeatsChange(__assign(__assign({}, repeats), (_a = {}, _a[field.id] = u, _a)));
|
|
226
|
+
}, form: form }))
|
|
227
|
+
: field.type === 'stringLong' ? (_jsx(StringLong, { field: field, label: "Repeat", value: (_15 = repeats[field.id]) !== null && _15 !== void 0 ? _15 : '', onChange: function (u) {
|
|
228
|
+
var _a;
|
|
229
|
+
return onRepeatsChange(__assign(__assign({}, repeats), (_a = {}, _a[field.id] = u, _a)));
|
|
230
|
+
}, form: form }))
|
|
231
|
+
: field.type === 'number' ? (_jsx(Number, { field: field, label: "Repeat", value: (_16 = repeats[field.id]) !== null && _16 !== void 0 ? _16 : '', onChange: function (u) {
|
|
232
|
+
var _a;
|
|
233
|
+
return onRepeatsChange(__assign(__assign({}, repeats), (_a = {}, _a[field.id] = u, _a)));
|
|
234
|
+
}, form: form }))
|
|
235
|
+
: null }))), _jsx(Description, { field: field, style: { fontSize: 14, color: '#00000099', marginTop: 4 } }), field.type !== 'Question Group' &&
|
|
236
|
+
_jsx(Typography, __assign({ color: "error", style: { marginTop: 3, height: 10, fontSize: 14, marginBottom: -10 } }, { children: (validationMessage === 'A response is required' || validationMessage === 'A value must be checked' || validationMessage === 'A file is required' || 'Enter a valid phone number' || 'Insurer is required')
|
|
237
|
+
? value.touched
|
|
238
|
+
? form_display_text_for_language(form, validationMessage)
|
|
239
|
+
: null
|
|
240
|
+
: form_display_text_for_language(form, validationMessage) }))] })));
|
|
241
|
+
};
|
|
242
|
+
export var TellescopeSingleQuestionFlowV2 = function (_a) {
|
|
243
|
+
var _b, _c, _d, _e;
|
|
244
|
+
var form = _a.form, activeField = _a.activeField, currentFileValue = _a.currentFileValue, customInputs = _a.customInputs, currentValue = _a.currentValue, submitErrorMessage = _a.submitErrorMessage, onAddFile = _a.onAddFile, onFieldChange = _a.onFieldChange, goToNextField = _a.goToNextField, goToPreviousField = _a.goToPreviousField, isAutoAdvancing = _a.isAutoAdvancing, isNextDisabled = _a.isNextDisabled, isPreviousDisabled = _a.isPreviousDisabled, submit = _a.submit, showSubmit = _a.showSubmit, submittingStatus = _a.submittingStatus, validateField = _a.validateField, _f = _a.thanksMessage, thanksMessage = _f === void 0 ? "Your response was successfully recorded" : _f, htmlThanksMessage = _a.htmlThanksMessage, submitted = _a.submitted, onSuccess = _a.onSuccess, isPreview = _a.isPreview, theme = _a.theme, fields = _a.fields, responses = _a.responses, selectedFiles = _a.selectedFiles, inputStyle = _a.inputStyle, repeats = _a.repeats, setRepeats = _a.setRepeats, currentPageIndex = _a.currentPageIndex, getNumberOfRemainingPages = _a.getNumberOfRemainingPages, validateCurrentField = _a.validateCurrentField, handleDatabaseSelect = _a.handleDatabaseSelect, setCustomerId = _a.setCustomerId, customization = _a.customization, enduserId = _a.enduserId, enduser = _a.enduser, formResponseId = _a.formResponseId, groupId = _a.groupId, groupInstance = _a.groupInstance, logicOptions = _a.logicOptions, uploadingFiles = _a.uploadingFiles, setUploadingFiles = _a.setUploadingFiles, handleFileUpload = _a.handleFileUpload;
|
|
245
|
+
var beforeunloadHandler = React.useCallback(function (e) {
|
|
246
|
+
try {
|
|
247
|
+
e.preventDefault();
|
|
248
|
+
e.returnValue = 'You have unsaved changes';
|
|
249
|
+
}
|
|
250
|
+
catch (err) { }
|
|
251
|
+
return '';
|
|
252
|
+
}, []);
|
|
253
|
+
var _g = useState(false), uploading = _g[0], setUploading = _g[1];
|
|
254
|
+
var _h = useState(false), autosubmitting = _h[0], setAutoSubmitting = _h[1];
|
|
255
|
+
useEffect(function () {
|
|
256
|
+
// ensure redirect question doesn't trip this alert
|
|
257
|
+
if (activeField.value.type === 'Redirect') {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
window.addEventListener('beforeunload', beforeunloadHandler);
|
|
261
|
+
return function () { window.removeEventListener('beforeunload', beforeunloadHandler); };
|
|
262
|
+
}, [beforeunloadHandler, activeField]);
|
|
263
|
+
var handleSubmit = useCallback(function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
264
|
+
return __generator(this, function (_a) {
|
|
265
|
+
switch (_a.label) {
|
|
266
|
+
case 0:
|
|
267
|
+
if (isPreview) {
|
|
268
|
+
return [2 /*return*/, onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess({})];
|
|
269
|
+
}
|
|
270
|
+
return [4 /*yield*/, submit(__assign(__assign({ onSuccess: onSuccess }, options), { onPreRedirect: function () {
|
|
271
|
+
// submission may trigger a redirect, so don't block with warning message
|
|
272
|
+
try {
|
|
273
|
+
window.removeEventListener('beforeunload', beforeunloadHandler);
|
|
274
|
+
}
|
|
275
|
+
catch (err) { }
|
|
276
|
+
} }))];
|
|
277
|
+
case 1:
|
|
278
|
+
_a.sent();
|
|
279
|
+
return [2 /*return*/];
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}); }, [isPreview, onSuccess, submit, beforeunloadHandler]);
|
|
283
|
+
var autoSubmitRef = useRef(false);
|
|
284
|
+
useEffect(function () {
|
|
285
|
+
var _a;
|
|
286
|
+
if (!((_a = activeField.value.options) === null || _a === void 0 ? void 0 : _a.autoSubmit)) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (autoSubmitRef.current)
|
|
290
|
+
return;
|
|
291
|
+
if (responses.find(function (r) { return r.fieldId === activeField.value.id && field_can_autosubmit(activeField.value) && r.answer.value; })) {
|
|
292
|
+
autoSubmitRef.current = true;
|
|
293
|
+
setAutoSubmitting(true);
|
|
294
|
+
handleSubmit()
|
|
295
|
+
.finally(function () { return setAutoSubmitting(false); });
|
|
296
|
+
}
|
|
297
|
+
}, [handleSubmit, responses, activeField]);
|
|
298
|
+
var validationMessage = validateField(activeField.value);
|
|
299
|
+
var handleKeyPress = useCallback(function (e) {
|
|
300
|
+
var _a, _b;
|
|
301
|
+
if (e.key === 'Enter'
|
|
302
|
+
&& !(activeField.value.type === 'Dropdown' && ((_a = activeField.value.options) === null || _a === void 0 ? void 0 : _a.other) && !((_b = activeField.value.options) === null || _b === void 0 ? void 0 : _b.radio))) {
|
|
303
|
+
if (activeField.value.type === 'stringLong')
|
|
304
|
+
return; //
|
|
305
|
+
if (activeField.value.type === 'Question Group')
|
|
306
|
+
return; // ensure enter is allowed in stringLong at end of a question group before next
|
|
307
|
+
if (isNextDisabled())
|
|
308
|
+
return;
|
|
309
|
+
goToNextField(undefined);
|
|
310
|
+
}
|
|
311
|
+
}, [activeField, isNextDisabled, goToNextField, isPreviousDisabled, goToPreviousField]);
|
|
312
|
+
useEffect(function () {
|
|
313
|
+
window.addEventListener('keydown', handleKeyPress);
|
|
314
|
+
return function () { window.removeEventListener('keydown', handleKeyPress); };
|
|
315
|
+
}, [handleKeyPress]);
|
|
316
|
+
var numRemainingPages = getNumberOfRemainingPages();
|
|
317
|
+
// Calculate current score if real-time scoring is enabled
|
|
318
|
+
var currentScores = useMemo(function () {
|
|
319
|
+
var _a;
|
|
320
|
+
if (!(form === null || form === void 0 ? void 0 : form.realTimeScoring) || !((_a = form.scoring) === null || _a === void 0 ? void 0 : _a.length))
|
|
321
|
+
return null;
|
|
322
|
+
return calculate_form_scoring({
|
|
323
|
+
response: { responses: responses },
|
|
324
|
+
form: { scoring: form.scoring }
|
|
325
|
+
});
|
|
326
|
+
}, [form === null || form === void 0 ? void 0 : form.realTimeScoring, form === null || form === void 0 ? void 0 : form.scoring, responses]);
|
|
327
|
+
if (!(currentValue && currentFileValue))
|
|
328
|
+
return _jsx(_Fragment, {});
|
|
329
|
+
// Show loading state while auto-advancing to target question
|
|
330
|
+
if (isAutoAdvancing) {
|
|
331
|
+
return (_jsxs(Flex, __assign({ column: true, alignItems: "center", style: { minHeight: 200, justifyContent: 'center' } }, { children: [_jsx(CircularProgress, { size: 40 }), _jsx(Typography, __assign({ style: { marginTop: 16, textAlign: 'center' } }, { children: "Picking up where you left off..." }))] })));
|
|
332
|
+
}
|
|
333
|
+
return (submitted
|
|
334
|
+
? _jsx(ThanksMessage, { htmlThanksMessage: htmlThanksMessage, thanksMessage: thanksMessage, showRestartAtEnd: customization === null || customization === void 0 ? void 0 : customization.showRestartAtEnd })
|
|
335
|
+
: (_jsxs(Flex, __assign({ column: true, flex: 1, style: { justifyContent: 'space-between' } }, { children: [_jsxs(Flex, __assign({ column: true }, { children: [!(customization === null || customization === void 0 ? void 0 : customization.hideProgressBar) &&
|
|
336
|
+
_jsx(Progress, { numerator: currentPageIndex + (validateCurrentField() ? 0 : 1), denominator: currentPageIndex + 1 + numRemainingPages, style: { marginBottom: '20px' }, color: (_c = (_b = customization === null || customization === void 0 ? void 0 : customization.primaryColor) !== null && _b !== void 0 ? _b : theme === null || theme === void 0 ? void 0 : theme.themeColor) !== null && _c !== void 0 ? _c : '#798ED0' }), !(customization === null || customization === void 0 ? void 0 : customization.hideLogo) && ((theme === null || theme === void 0 ? void 0 : theme.logoURL)
|
|
337
|
+
? (_jsx(Flex, __assign({ alignItems: "flex-start", style: { marginBottom: '20px' } }, { children: _jsx("img", { src: theme.logoURL, alt: theme.name, style: { maxHeight: (customization === null || customization === void 0 ? void 0 : customization.logoHeight) || LOGO_HEIGHT, maxWidth: 225 } }) })))
|
|
338
|
+
: (_jsx(Typography, __assign({ style: { fontSize: 22, marginBottom: '20px', textAlign: 'left', fontWeight: 600 } }, { children: theme === null || theme === void 0 ? void 0 : theme.name })))), _jsx(Flex, __assign({ column: true }, { children: _jsx(Flex, __assign({ style: inputStyle }, { children: _jsx(QuestionForField, { form: form, fields: fields, field: activeField.value, submit: submit, enduserId: enduserId, formResponseId: formResponseId, enduser: enduser, goToPreviousField: goToPreviousField, isPreviousDisabled: isPreviousDisabled, goToNextField: goToNextField, handleDatabaseSelect: handleDatabaseSelect, setCustomerId: setCustomerId, repeats: repeats, onRepeatsChange: setRepeats, value: currentValue, file: currentFileValue, customInputs: customInputs, onAddFile: onAddFile, onFieldChange: onFieldChange, responses: responses, selectedFiles: selectedFiles, validateField: validateField, groupId: groupId, groupInstance: groupInstance, logicOptions: logicOptions, uploadingFiles: uploadingFiles, setUploadingFiles: setUploadingFiles, handleFileUpload: handleFileUpload }) })) }))] })), _jsxs(Flex, __assign({ flex: 1, alignItems: 'flex-end', justifyContent: "space-between", style: { gap: 10, marginTop: '20px' } }, { children: [!isPreviousDisabled() && (_jsx(Button, __assign({ variant: "outlined", color: "secondary", disabled: isPreviousDisabled(), onClick: goToPreviousField, style: __assign(__assign({}, defaultButtonStyles), { flex: 1 }) }, { children: form_display_text_for_language(form, "Previous") }))), uploading &&
|
|
339
|
+
_jsx(Modal, __assign({ open: true, setOpen: function () { return undefined; } }, { children: _jsxs(Flex, __assign({ style: {}, justifyContent: "center" }, { children: [_jsx(Typography, __assign({ style: { fontSize: 20, width: 250, fontWeight: 'bold', textAlign: 'center' } }, { children: "Uploading files..." })), _jsx(CircularProgress, { size: 75, style: { marginTop: 10, marginBottom: 10 } }), _jsx(Typography, __assign({ style: { fontSize: 20, width: 250, fontWeight: 'bold', textAlign: 'center' } }, { children: "Please stay on this page until your submission is complete!" }))] })) })), showSubmit
|
|
340
|
+
? (_jsx(LoadingButton, { muiColor: "secondary", onClick: function () {
|
|
341
|
+
setUploading(!!selectedFiles.find(function (r) { var _a; return !!((_a = r.blobs) === null || _a === void 0 ? void 0 : _a.length); }));
|
|
342
|
+
return handleSubmit({ onFileUploadsDone: function () { return setUploading(false); } });
|
|
343
|
+
}, disabled: !!validationMessage || ((_e = (_d = currentValue.field) === null || _d === void 0 ? void 0 : _d.options) === null || _e === void 0 ? void 0 : _e.disableNext) === true || autosubmitting, submitText: form_display_text_for_language(form, "Submit"), submittingText: submittingStatus === 'uploading-files'
|
|
344
|
+
? 'Uploading files...'
|
|
345
|
+
: "Submitting...", style: __assign(__assign({}, defaultButtonStyles), { flex: 1 }) }))
|
|
346
|
+
: (_jsx(Button, __assign({ variant: "contained", disabled: isNextDisabled(), onClick: function () { return goToNextField(undefined); }, color: "secondary", style: __assign(__assign({}, defaultButtonStyles), { flex: 1 }) }, { children: form_display_text_for_language(form, "Continue") })))] })), currentScores && currentScores.length > 0 && (_jsx(Flex, __assign({ style: { marginTop: 10, marginBottom: 5, width: '100%' } }, { children: currentScores.map(function (score, index) {
|
|
347
|
+
var _a, _b;
|
|
348
|
+
var primaryColor = (_b = (_a = customization === null || customization === void 0 ? void 0 : customization.primaryColor) !== null && _a !== void 0 ? _a : theme === null || theme === void 0 ? void 0 : theme.themeColor) !== null && _b !== void 0 ? _b : '#798ED0';
|
|
349
|
+
return (_jsxs(Flex, __assign({ style: {
|
|
350
|
+
padding: '10px 14px',
|
|
351
|
+
backgroundColor: '#f8f9fa',
|
|
352
|
+
borderRadius: 8,
|
|
353
|
+
border: "1px solid ".concat(primaryColor, "20"),
|
|
354
|
+
marginRight: index < currentScores.length - 1 ? 12 : 0,
|
|
355
|
+
minWidth: 120,
|
|
356
|
+
flexDirection: 'column',
|
|
357
|
+
alignItems: 'center'
|
|
358
|
+
} }, { children: [_jsx(Typography, __assign({ style: {
|
|
359
|
+
fontSize: 12,
|
|
360
|
+
fontWeight: 'medium',
|
|
361
|
+
textAlign: 'center',
|
|
362
|
+
lineHeight: 1.2,
|
|
363
|
+
marginBottom: 4
|
|
364
|
+
} }, { children: score.title })), _jsx(Typography, __assign({ style: {
|
|
365
|
+
fontWeight: 'bold',
|
|
366
|
+
color: primaryColor,
|
|
367
|
+
fontSize: 18
|
|
368
|
+
} }, { children: score.value }))] }), index));
|
|
369
|
+
}) }))), _jsx(Typography, __assign({ color: "error", style: { alignText: 'center', marginTop: 3 } }, { children: submitErrorMessage }))] }))));
|
|
370
|
+
};
|
|
371
|
+
export var DEFAULT_THANKS_MESSAGE = "Your response was successfully recorded";
|
|
372
|
+
export var ThanksMessage = function (_a) {
|
|
373
|
+
var thanksMessage = _a.thanksMessage, htmlThanksMessage = _a.htmlThanksMessage, showRestartAtEnd = _a.showRestartAtEnd, downloadComponent = _a.downloadComponent;
|
|
374
|
+
return (_jsxs(Flex, __assign({ column: true }, { children: [htmlThanksMessage
|
|
375
|
+
? (_jsx("div", { style: { textAlign: 'center' }, dangerouslySetInnerHTML: {
|
|
376
|
+
__html: remove_script_tags(htmlThanksMessage)
|
|
377
|
+
} })) : (_jsx(Typography, __assign({ style: { marginTop: 25, alignSelf: 'center' } }, { children: thanksMessage || DEFAULT_THANKS_MESSAGE }))), read_local_storage('redirecting_public_group') === 'true' &&
|
|
378
|
+
_jsx(_Fragment, { children: _jsxs(Typography, __assign({ style: { marginTop: 25, alignSelf: 'center' } }, { children: ["Redirecting to next form... ", _jsx(CircularProgress, { size: 20, color: "primary" })] })) }), downloadComponent &&
|
|
379
|
+
_jsx(Flex, __assign({ justifyContent: "center", style: { marginTop: 15, marginBottom: 15 } }, { children: downloadComponent })), showRestartAtEnd && window.localStorage["ts_form_url"] &&
|
|
380
|
+
_jsx(Button, __assign({ variant: "outlined", style: __assign(__assign({}, defaultButtonStyles), { maxWidth: 200, marginTop: 25, alignSelf: 'center' }), onClick: function () { return window.location.href = window.localStorage["ts_form_url"]; } }, { children: "Submit Again" }))] })));
|
|
381
|
+
};
|
|
382
|
+
var TellescopeFormWithContextV2 = function (props) {
|
|
383
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
384
|
+
var theme = useOrganizationTheme();
|
|
385
|
+
// V2: Override MUI theme with customization colors
|
|
386
|
+
var primaryColor = (_c = (_b = (_a = props.customization) === null || _a === void 0 ? void 0 : _a.primaryColor) !== null && _b !== void 0 ? _b : theme === null || theme === void 0 ? void 0 : theme.themeColor) !== null && _c !== void 0 ? _c : '#798ED0';
|
|
387
|
+
var secondaryColor = (_f = (_e = (_d = props.customization) === null || _d === void 0 ? void 0 : _d.secondaryColor) !== null && _e !== void 0 ? _e : theme === null || theme === void 0 ? void 0 : theme.themeColorSecondary) !== null && _f !== void 0 ? _f : '#585E72';
|
|
388
|
+
return (_jsx(WithTheme, __assign({ theme: { primary: primaryColor, secondary: secondaryColor } }, { children: _jsx(TellescopeFormContainerV2, __assign({ style: props.style, dontAddContext: true, hideBg: props.hideBg || ((_h = (_g = props.form) === null || _g === void 0 ? void 0 : _g.customization) === null || _h === void 0 ? void 0 : _h.hideBg), logoHeight: props.logoHeight, backgroundColor: props.backgroundColor, hideLogo: (_j = props === null || props === void 0 ? void 0 : props.customization) === null || _j === void 0 ? void 0 : _j.hideLogo, maxWidth: (_l = (_k = props.form) === null || _k === void 0 ? void 0 : _k.customization) === null || _l === void 0 ? void 0 : _l.maxWidth }, { children: props.submitted
|
|
389
|
+
? _jsx(ThanksMessage, __assign({}, props, { showRestartAtEnd: (_m = props === null || props === void 0 ? void 0 : props.customization) === null || _m === void 0 ? void 0 : _m.showRestartAtEnd }))
|
|
390
|
+
: (_jsx(TellescopeSingleQuestionFlowV2, __assign({}, props, { theme: theme }))) })) })));
|
|
391
|
+
};
|
|
392
|
+
export var SaveDraft = function (_a) {
|
|
393
|
+
var selectedFiles = _a.selectedFiles, enduserId = _a.enduserId, responses = _a.responses, existingResponses = _a.existingResponses, fields = _a.fields, onSuccess = _a.onSuccess, formResponseId = _a.formResponseId, includedFieldIds = _a.includedFieldIds, formId = _a.formId, style = _a.style, disabled = _a.disabled, getResponsesWithQuestionGroupAnswers = _a.getResponsesWithQuestionGroupAnswers, isInternalNote = _a.isInternalNote, formTitle = _a.formTitle, rootResponseId = _a.rootResponseId, parentResponseId = _a.parentResponseId;
|
|
394
|
+
var _b = useFormResponses({ dontFetch: true }), updateFormResponse = _b[1].updateElement;
|
|
395
|
+
var session = useSession();
|
|
396
|
+
var handleUpload = useFileUpload({}).handleUpload;
|
|
397
|
+
return (_jsx(LoadingButton, { style: style, disabled: disabled, variant: 'outlined', onClick: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
398
|
+
var hasFile, _loop_1, _i, selectedFiles_1, blobInfo, err_1, response, _a, _b, err_2;
|
|
399
|
+
var _c, _d, _e;
|
|
400
|
+
return __generator(this, function (_f) {
|
|
401
|
+
switch (_f.label) {
|
|
402
|
+
case 0:
|
|
403
|
+
hasFile = selectedFiles.find(function (f) { var _a; return !!((_a = f.blobs) === null || _a === void 0 ? void 0 : _a.length); }) !== undefined;
|
|
404
|
+
if (!hasFile) return [3 /*break*/, 8];
|
|
405
|
+
_f.label = 1;
|
|
406
|
+
case 1:
|
|
407
|
+
_f.trys.push([1, 6, 7, 8]);
|
|
408
|
+
_loop_1 = function (blobInfo) {
|
|
409
|
+
var blobs, fieldId, _g, blobs_1, blob, result, secureName, responseIndex;
|
|
410
|
+
return __generator(this, function (_h) {
|
|
411
|
+
switch (_h.label) {
|
|
412
|
+
case 0:
|
|
413
|
+
blobs = blobInfo.blobs, fieldId = blobInfo.fieldId;
|
|
414
|
+
if (!blobs)
|
|
415
|
+
return [2 /*return*/, "continue"];
|
|
416
|
+
_g = 0, blobs_1 = blobs;
|
|
417
|
+
_h.label = 1;
|
|
418
|
+
case 1:
|
|
419
|
+
if (!(_g < blobs_1.length)) return [3 /*break*/, 4];
|
|
420
|
+
blob = blobs_1[_g];
|
|
421
|
+
result = { name: blob.name, secureName: '' };
|
|
422
|
+
return [4 /*yield*/, handleUpload({
|
|
423
|
+
name: blob.name,
|
|
424
|
+
size: blob.size,
|
|
425
|
+
type: blob.type,
|
|
426
|
+
enduserId: enduserId,
|
|
427
|
+
}, blob)];
|
|
428
|
+
case 2:
|
|
429
|
+
secureName = (_h.sent()).secureName;
|
|
430
|
+
responseIndex = responses.findIndex(function (f) { return f.fieldId === fieldId; });
|
|
431
|
+
if (responses[responseIndex].answer.type === 'files') {
|
|
432
|
+
if (!responses[responseIndex].answer.value) {
|
|
433
|
+
responses[responseIndex].answer.value = [];
|
|
434
|
+
}
|
|
435
|
+
responses[responseIndex].answer.value.push(__assign(__assign({}, result), { type: blob.type, secureName: secureName, name: (_c = result.name) !== null && _c !== void 0 ? _c : '' }));
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
responses[responseIndex].answer.value = __assign(__assign({}, result), { type: blob.type, secureName: secureName, name: (_d = result.name) !== null && _d !== void 0 ? _d : '' });
|
|
439
|
+
}
|
|
440
|
+
_h.label = 3;
|
|
441
|
+
case 3:
|
|
442
|
+
_g++;
|
|
443
|
+
return [3 /*break*/, 1];
|
|
444
|
+
case 4: return [2 /*return*/];
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
_i = 0, selectedFiles_1 = selectedFiles;
|
|
449
|
+
_f.label = 2;
|
|
450
|
+
case 2:
|
|
451
|
+
if (!(_i < selectedFiles_1.length)) return [3 /*break*/, 5];
|
|
452
|
+
blobInfo = selectedFiles_1[_i];
|
|
453
|
+
return [5 /*yield**/, _loop_1(blobInfo)];
|
|
454
|
+
case 3:
|
|
455
|
+
_f.sent();
|
|
456
|
+
_f.label = 4;
|
|
457
|
+
case 4:
|
|
458
|
+
_i++;
|
|
459
|
+
return [3 /*break*/, 2];
|
|
460
|
+
case 5: return [3 /*break*/, 8];
|
|
461
|
+
case 6:
|
|
462
|
+
err_1 = _f.sent();
|
|
463
|
+
return [3 /*break*/, 8];
|
|
464
|
+
case 7: return [7 /*endfinally*/];
|
|
465
|
+
case 8:
|
|
466
|
+
_f.trys.push([8, 13, 14, 15]);
|
|
467
|
+
_a = updateFormResponse;
|
|
468
|
+
if (!(formResponseId !== null && formResponseId !== void 0)) return [3 /*break*/, 9];
|
|
469
|
+
_b = formResponseId;
|
|
470
|
+
return [3 /*break*/, 11];
|
|
471
|
+
case 9: return [4 /*yield*/, session.api.form_responses.prepare_form_response({ rootResponseId: rootResponseId, parentResponseId: parentResponseId, isInternalNote: isInternalNote, formId: formId, enduserId: enduserId, title: formTitle })];
|
|
472
|
+
case 10:
|
|
473
|
+
_b = (_f.sent()).response.id;
|
|
474
|
+
_f.label = 11;
|
|
475
|
+
case 11: return [4 /*yield*/, _a.apply(void 0, [(_b),
|
|
476
|
+
{
|
|
477
|
+
draftSavedAt: new Date(),
|
|
478
|
+
draftSavedBy: (_e = session === null || session === void 0 ? void 0 : session.userInfo) === null || _e === void 0 ? void 0 : _e.id,
|
|
479
|
+
responses: __spreadArray(__spreadArray([], (existingResponses !== null && existingResponses !== void 0 ? existingResponses : []).filter(function (r) { return !fields.find(function (f) { return f.id === r.fieldId; }); }), true), getResponsesWithQuestionGroupAnswers(includedFieldIds.map(function (id) { return responses.find(function (r) { return r.fieldId === id; }); })), true)
|
|
480
|
+
},
|
|
481
|
+
{ replaceObjectFields: true }])];
|
|
482
|
+
case 12:
|
|
483
|
+
response = _f.sent();
|
|
484
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
|
|
485
|
+
return [3 /*break*/, 15];
|
|
486
|
+
case 13:
|
|
487
|
+
err_2 = _f.sent();
|
|
488
|
+
return [3 /*break*/, 15];
|
|
489
|
+
case 14: return [7 /*endfinally*/];
|
|
490
|
+
case 15: return [2 /*return*/];
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}); }, submitText: "Save Draft", submittingText: "Saving..." }));
|
|
494
|
+
};
|
|
495
|
+
export var UpdateResponse = function (_a) {
|
|
496
|
+
var selectedFiles = _a.selectedFiles, enduserId = _a.enduserId, responses = _a.responses, onSuccess = _a.onSuccess, formResponseId = _a.formResponseId, includedFieldIds = _a.includedFieldIds, formId = _a.formId, style = _a.style, disabled = _a.disabled, getResponsesWithQuestionGroupAnswers = _a.getResponsesWithQuestionGroupAnswers, existingResponses = _a.existingResponses, fields = _a.fields;
|
|
497
|
+
var _b = useFormResponses({ dontFetch: true }), updateFormResponse = _b[1].updateElement;
|
|
498
|
+
var session = useSession();
|
|
499
|
+
var handleUpload = useFileUpload({}).handleUpload;
|
|
500
|
+
return (_jsx(LoadingButton, { style: style, disabled: disabled, variant: 'contained', onClick: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
501
|
+
var hasFile, _loop_2, _i, selectedFiles_2, blobInfo, err_3, response, _a, _b;
|
|
502
|
+
var _c, _d;
|
|
503
|
+
return __generator(this, function (_e) {
|
|
504
|
+
switch (_e.label) {
|
|
505
|
+
case 0:
|
|
506
|
+
hasFile = selectedFiles.find(function (f) { var _a; return !!((_a = f.blobs) === null || _a === void 0 ? void 0 : _a.length); }) !== undefined;
|
|
507
|
+
if (!hasFile) return [3 /*break*/, 8];
|
|
508
|
+
_e.label = 1;
|
|
509
|
+
case 1:
|
|
510
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
511
|
+
_loop_2 = function (blobInfo) {
|
|
512
|
+
var blobs, fieldId, _f, blobs_2, blob, result, secureName, responseIndex;
|
|
513
|
+
return __generator(this, function (_g) {
|
|
514
|
+
switch (_g.label) {
|
|
515
|
+
case 0:
|
|
516
|
+
blobs = blobInfo.blobs, fieldId = blobInfo.fieldId;
|
|
517
|
+
if (!blobs)
|
|
518
|
+
return [2 /*return*/, "continue"];
|
|
519
|
+
_f = 0, blobs_2 = blobs;
|
|
520
|
+
_g.label = 1;
|
|
521
|
+
case 1:
|
|
522
|
+
if (!(_f < blobs_2.length)) return [3 /*break*/, 4];
|
|
523
|
+
blob = blobs_2[_f];
|
|
524
|
+
result = { name: blob.name, secureName: '' };
|
|
525
|
+
return [4 /*yield*/, handleUpload({
|
|
526
|
+
name: blob.name,
|
|
527
|
+
size: blob.size,
|
|
528
|
+
type: blob.type,
|
|
529
|
+
enduserId: enduserId,
|
|
530
|
+
}, blob)];
|
|
531
|
+
case 2:
|
|
532
|
+
secureName = (_g.sent()).secureName;
|
|
533
|
+
responseIndex = responses.findIndex(function (f) { return f.fieldId === fieldId; });
|
|
534
|
+
if (responses[responseIndex].answer.type === 'files') {
|
|
535
|
+
if (!responses[responseIndex].answer.value) {
|
|
536
|
+
responses[responseIndex].answer.value = [];
|
|
537
|
+
}
|
|
538
|
+
responses[responseIndex].answer.value.push(__assign(__assign({}, result), { type: blob.type, secureName: secureName, name: (_c = result.name) !== null && _c !== void 0 ? _c : '' }));
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
responses[responseIndex].answer.value = __assign(__assign({}, result), { type: blob.type, secureName: secureName, name: (_d = result.name) !== null && _d !== void 0 ? _d : '' });
|
|
542
|
+
}
|
|
543
|
+
_g.label = 3;
|
|
544
|
+
case 3:
|
|
545
|
+
_f++;
|
|
546
|
+
return [3 /*break*/, 1];
|
|
547
|
+
case 4: return [2 /*return*/];
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
};
|
|
551
|
+
_i = 0, selectedFiles_2 = selectedFiles;
|
|
552
|
+
_e.label = 2;
|
|
553
|
+
case 2:
|
|
554
|
+
if (!(_i < selectedFiles_2.length)) return [3 /*break*/, 5];
|
|
555
|
+
blobInfo = selectedFiles_2[_i];
|
|
556
|
+
return [5 /*yield**/, _loop_2(blobInfo)];
|
|
557
|
+
case 3:
|
|
558
|
+
_e.sent();
|
|
559
|
+
_e.label = 4;
|
|
560
|
+
case 4:
|
|
561
|
+
_i++;
|
|
562
|
+
return [3 /*break*/, 2];
|
|
563
|
+
case 5: return [3 /*break*/, 8];
|
|
564
|
+
case 6:
|
|
565
|
+
err_3 = _e.sent();
|
|
566
|
+
return [3 /*break*/, 8];
|
|
567
|
+
case 7: return [7 /*endfinally*/];
|
|
568
|
+
case 8:
|
|
569
|
+
_a = updateFormResponse;
|
|
570
|
+
if (!(formResponseId !== null && formResponseId !== void 0)) return [3 /*break*/, 9];
|
|
571
|
+
_b = formResponseId;
|
|
572
|
+
return [3 /*break*/, 11];
|
|
573
|
+
case 9: return [4 /*yield*/, session.api.form_responses.prepare_form_response({ formId: formId, enduserId: enduserId })];
|
|
574
|
+
case 10:
|
|
575
|
+
_b = (_e.sent()).response.id;
|
|
576
|
+
_e.label = 11;
|
|
577
|
+
case 11: return [4 /*yield*/, _a.apply(void 0, [(_b),
|
|
578
|
+
{
|
|
579
|
+
responses: __spreadArray(__spreadArray([], (existingResponses !== null && existingResponses !== void 0 ? existingResponses : []).filter(function (r) { return !fields.find(function (f) { return f.id === r.fieldId; }); }), true), getResponsesWithQuestionGroupAnswers(includedFieldIds.map(function (id) { return responses.find(function (r) { return r.fieldId === id; }); })), true)
|
|
580
|
+
},
|
|
581
|
+
{ replaceObjectFields: true }])];
|
|
582
|
+
case 12:
|
|
583
|
+
response = _e.sent();
|
|
584
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
|
|
585
|
+
return [2 /*return*/];
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
}); }, submitText: "Update", submittingText: "Saving..." }));
|
|
589
|
+
};
|
|
590
|
+
export var Description = function (_a) {
|
|
591
|
+
var field = _a.field, _b = _a.color, color = _b === void 0 ? "primary" : _b, style = _a.style;
|
|
592
|
+
if (!field.htmlDescription && field.description) {
|
|
593
|
+
return (_jsx(Typography, __assign({ color: color, style: style }, { children: field.description })));
|
|
594
|
+
}
|
|
595
|
+
if (!field.htmlDescription)
|
|
596
|
+
return null;
|
|
597
|
+
return (_jsx("span", { style: style, dangerouslySetInnerHTML: {
|
|
598
|
+
__html: remove_script_tags(field.htmlDescription)
|
|
599
|
+
} }));
|
|
600
|
+
};
|
|
601
|
+
export var TellescopeSinglePageForm = function (_a) {
|
|
602
|
+
var _b, _c, _d;
|
|
603
|
+
var customInputs = _a.customInputs, submitErrorMessage = _a.submitErrorMessage, onAddFile = _a.onAddFile, onFieldChange = _a.onFieldChange, goToNextField = _a.goToNextField, goToPreviousField = _a.goToPreviousField, isNextDisabled = _a.isNextDisabled, isPreviousDisabled = _a.isPreviousDisabled, submit = _a.submit, showSubmit = _a.showSubmit, showSaveDraft = _a.showSaveDraft, submittingStatus = _a.submittingStatus, updating = _a.updating, validateField = _a.validateField, validateResponsesForFields = _a.validateResponsesForFields, formTitle = _a.formTitle, _e = _a.thanksMessage, thanksMessage = _e === void 0 ? DEFAULT_THANKS_MESSAGE : _e, htmlThanksMessage = _a.htmlThanksMessage, submitted = _a.submitted, style = _a.style, onSuccess = _a.onSuccess, isPreview = _a.isPreview, fields = _a.fields, selectedFiles = _a.selectedFiles, responses = _a.responses, isInternalNote = _a.isInternalNote, existingResponses = _a.existingResponses, repeats = _a.repeats, setRepeats = _a.setRepeats, setCustomerId = _a.setCustomerId, rootResponseId = _a.rootResponseId, parentResponseId = _a.parentResponseId, handleDatabaseSelect = _a.handleDatabaseSelect, submittedAt = _a.submittedAt, updatedAt = _a.updatedAt, otherEnduserIds = _a.otherEnduserIds, onBulkErrors = _a.onBulkErrors, enduser = _a.enduser, groupId = _a.groupId, groupInstance = _a.groupInstance, uploadingFiles = _a.uploadingFiles, setUploadingFiles = _a.setUploadingFiles, handleFileUpload = _a.handleFileUpload, AddToDatabase = _a.AddToDatabase, props = __rest(_a, ["customInputs", "submitErrorMessage", "onAddFile", "onFieldChange", "goToNextField", "goToPreviousField", "isNextDisabled", "isPreviousDisabled", "submit", "showSubmit", "showSaveDraft", "submittingStatus", "updating", "validateField", "validateResponsesForFields", "formTitle", "thanksMessage", "htmlThanksMessage", "submitted", "style", "onSuccess", "isPreview", "fields", "selectedFiles", "responses", "isInternalNote", "existingResponses", "repeats", "setRepeats", "setCustomerId", "rootResponseId", "parentResponseId", "handleDatabaseSelect", "submittedAt", "updatedAt", "otherEnduserIds", "onBulkErrors", "enduser", "groupId", "groupInstance", "uploadingFiles", "setUploadingFiles", "handleFileUpload", "AddToDatabase"]);
|
|
604
|
+
var list = useListForFormFields(fields, responses, { form: props.form, gender: enduser === null || enduser === void 0 ? void 0 : enduser.gender });
|
|
605
|
+
var includedFieldIds = (Array.from(new Set(__spreadArray(__spreadArray([], list.map(function (f) { return f.id; }), true), (existingResponses !== null && existingResponses !== void 0 ? existingResponses : []).filter(function (e) { return !e.isPrepopulatedFromEnduserField; }).map(function (e) { return e.fieldId; }), true))));
|
|
606
|
+
var handleSubmit = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
607
|
+
return __generator(this, function (_a) {
|
|
608
|
+
switch (_a.label) {
|
|
609
|
+
case 0:
|
|
610
|
+
if (isPreview) {
|
|
611
|
+
return [2 /*return*/, onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess({})];
|
|
612
|
+
}
|
|
613
|
+
return [4 /*yield*/, submit({
|
|
614
|
+
onSuccess: onSuccess,
|
|
615
|
+
includedFieldIds: includedFieldIds,
|
|
616
|
+
otherEnduserIds: otherEnduserIds,
|
|
617
|
+
onBulkErrors: onBulkErrors,
|
|
618
|
+
})];
|
|
619
|
+
case 1:
|
|
620
|
+
_a.sent();
|
|
621
|
+
return [2 /*return*/];
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
}); }, [isPreview, onSuccess, submit, otherEnduserIds, onBulkErrors]);
|
|
625
|
+
var errors = useMemo(function () {
|
|
626
|
+
var es = [];
|
|
627
|
+
try {
|
|
628
|
+
list.forEach(function (field) {
|
|
629
|
+
var error = validateField(field);
|
|
630
|
+
if (error && typeof error === 'string')
|
|
631
|
+
es.push({
|
|
632
|
+
id: field.id,
|
|
633
|
+
title: field.title,
|
|
634
|
+
error: error,
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
catch (err) {
|
|
639
|
+
console.error(err);
|
|
640
|
+
}
|
|
641
|
+
return es;
|
|
642
|
+
}, [list, validateField]);
|
|
643
|
+
var updatesDisabled = true;
|
|
644
|
+
var _loop_3 = function (r) {
|
|
645
|
+
var match = existingResponses === null || existingResponses === void 0 ? void 0 : existingResponses.find(function (_r) { return _r.fieldId === r.fieldId; });
|
|
646
|
+
if (!match) {
|
|
647
|
+
updatesDisabled = false;
|
|
648
|
+
return "break";
|
|
649
|
+
}
|
|
650
|
+
if (!objects_equivalent(r.answer, match.answer)) {
|
|
651
|
+
updatesDisabled = false;
|
|
652
|
+
return "break";
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
for (var _i = 0, _f = responses !== null && responses !== void 0 ? responses : []; _i < _f.length; _i++) {
|
|
656
|
+
var r = _f[_i];
|
|
657
|
+
var state_1 = _loop_3(r);
|
|
658
|
+
if (state_1 === "break")
|
|
659
|
+
break;
|
|
660
|
+
}
|
|
661
|
+
// Calculate current score if real-time scoring is enabled
|
|
662
|
+
var currentScores = useMemo(function () {
|
|
663
|
+
var _a, _b;
|
|
664
|
+
if (!((_a = props.form) === null || _a === void 0 ? void 0 : _a.realTimeScoring) || !((_b = props.form.scoring) === null || _b === void 0 ? void 0 : _b.length))
|
|
665
|
+
return null;
|
|
666
|
+
return calculate_form_scoring({
|
|
667
|
+
response: { responses: responses },
|
|
668
|
+
form: { scoring: props.form.scoring }
|
|
669
|
+
});
|
|
670
|
+
}, [(_b = props.form) === null || _b === void 0 ? void 0 : _b.realTimeScoring, (_c = props.form) === null || _c === void 0 ? void 0 : _c.scoring, responses]);
|
|
671
|
+
return (_jsx(Flex, __assign({ flex: 1, column: true }, { children: submitted
|
|
672
|
+
? _jsx(ThanksMessage, { htmlThanksMessage: htmlThanksMessage, thanksMessage: thanksMessage, showRestartAtEnd: (_d = props === null || props === void 0 ? void 0 : props.customization) === null || _d === void 0 ? void 0 : _d.showRestartAtEnd })
|
|
673
|
+
: (_jsxs(_Fragment, { children: [currentScores && currentScores.length > 0 && (_jsx(Flex, __assign({ style: {
|
|
674
|
+
position: 'sticky',
|
|
675
|
+
top: 0,
|
|
676
|
+
zIndex: 1000,
|
|
677
|
+
backgroundColor: 'white',
|
|
678
|
+
borderBottom: '1px solid #e0e0e0',
|
|
679
|
+
padding: '12px 0',
|
|
680
|
+
marginBottom: '16px',
|
|
681
|
+
width: '100%',
|
|
682
|
+
justifyContent: 'center'
|
|
683
|
+
} }, { children: currentScores.map(function (score, index) { return (_jsxs(Flex, __assign({ style: {
|
|
684
|
+
padding: '10px 14px',
|
|
685
|
+
backgroundColor: '#f8f9fa',
|
|
686
|
+
borderRadius: 8,
|
|
687
|
+
border: "1px solid ".concat(PRIMARY_HEX, "20"),
|
|
688
|
+
marginRight: index < currentScores.length - 1 ? 12 : 0,
|
|
689
|
+
minWidth: 120,
|
|
690
|
+
flexDirection: 'column',
|
|
691
|
+
alignItems: 'center'
|
|
692
|
+
} }, { children: [_jsx(Typography, __assign({ style: {
|
|
693
|
+
fontSize: 12,
|
|
694
|
+
fontWeight: 'medium',
|
|
695
|
+
textAlign: 'center',
|
|
696
|
+
lineHeight: 1.2,
|
|
697
|
+
marginBottom: 4
|
|
698
|
+
} }, { children: score.title })), _jsx(Typography, __assign({ style: {
|
|
699
|
+
fontWeight: 'bold',
|
|
700
|
+
color: PRIMARY_HEX,
|
|
701
|
+
fontSize: 18
|
|
702
|
+
} }, { children: score.value }))] }), index)); }) }))), _jsx(Flex, __assign({ flex: 1, justifyContent: "center", column: true, style: { marginBottom: 15 } }, { children: list.map(function (activeField) {
|
|
703
|
+
var value = responses.find(function (r) { return r.fieldId === activeField.id; });
|
|
704
|
+
var file = selectedFiles.find(function (r) { return r.fieldId === activeField.id; });
|
|
705
|
+
return (_jsx(Flex, __assign({ style: { marginBottom: 5 } }, { children: _jsx(Flex, __assign({ column: true, flex: 1 }, { children: _jsx(QuestionForField, { isSinglePage: true, fields: fields, field: activeField, handleDatabaseSelect: handleDatabaseSelect, enduserId: props.enduserId, formResponseId: props.formResponseId, rootResponseId: rootResponseId, submit: submit, enduser: enduser, goToPreviousField: goToPreviousField, isPreviousDisabled: isPreviousDisabled, goToNextField: goToNextField, repeats: repeats, onRepeatsChange: setRepeats, setCustomerId: setCustomerId, value: value, file: file, customInputs: customInputs, onAddFile: onAddFile, onFieldChange: onFieldChange, responses: responses, selectedFiles: selectedFiles, validateField: validateField, groupId: groupId, groupInstance: groupInstance, uploadingFiles: uploadingFiles, setUploadingFiles: setUploadingFiles, handleFileUpload: handleFileUpload, AddToDatabase: AddToDatabase }) })) }), activeField.id));
|
|
706
|
+
}) })), _jsx(Flex, __assign({ flex: 1, wrap: "nowrap" }, { children: updating
|
|
707
|
+
? (_jsxs(Flex, __assign({ flex: 1, column: true }, { children: [_jsx(UpdateResponse, __assign({}, props, { fields: fields, existingResponses: existingResponses, includedFieldIds: includedFieldIds,
|
|
708
|
+
// style={{ width: 200, marginRight: 5, height: 42 }}
|
|
709
|
+
formId: fields[0].formId, responses: responses, selectedFiles: selectedFiles, onSuccess: onSuccess, disabled: updatesDisabled })), submittedAt &&
|
|
710
|
+
_jsxs(Typography, __assign({ style: { marginTop: 5 } }, { children: ["Originally Submitted: ", formatted_date(new Date(submittedAt))] })), updatedAt &&
|
|
711
|
+
_jsxs(Typography, { children: ["Last Updated: ", formatted_date(new Date(updatedAt))] })] }))) : (_jsxs(_Fragment, { children: [showSaveDraft &&
|
|
712
|
+
_jsx(SaveDraft, __assign({ existingResponses: existingResponses, fields: fields }, props, { formTitle: formTitle, isInternalNote: isInternalNote, includedFieldIds: includedFieldIds, style: { width: 200, marginRight: 5, height: 42 }, formId: fields[0].formId, responses: responses, selectedFiles: selectedFiles, onSuccess: onSuccess, rootResponseId: rootResponseId, parentResponseId: parentResponseId })), _jsx(LoadingButton, { onClick: handleSubmit, disabled: !!validateResponsesForFields(list), style: { height: 42, width: '100%' }, submitText: "Submit Response", submittingText: submittingStatus === 'uploading-files'
|
|
713
|
+
? 'Uploading files...'
|
|
714
|
+
: "Submitting..." })] })) })), _jsx(Typography, __assign({ color: "error", style: { alignText: 'center', marginTop: 3 } }, { children: submitErrorMessage })), errors.length > 0 &&
|
|
715
|
+
_jsxs(_Fragment, { children: [_jsx(Divider, { flexItem: true, sx: { my: 1 } }), _jsxs(Flex, __assign({ alignItems: "center", wrap: "nowrap" }, { children: [_jsx(Typography, __assign({ noWrap: true, style: { width: 200 } }, { children: "Question" })), _jsx(Typography, __assign({ noWrap: true, style: {} }, { children: "Error" }))] }))] }), errors.map(function (e) { return (_jsxs(Flex, __assign({ alignItems: "center", wrap: "nowrap" }, { children: [_jsx(Typography, __assign({ noWrap: true, style: { width: 200, textDecoration: 'underline', cursor: 'pointer' }, onClick: function () {
|
|
716
|
+
var _a;
|
|
717
|
+
try {
|
|
718
|
+
(_a = document.getElementById(e.id)) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ behavior: 'smooth' });
|
|
719
|
+
}
|
|
720
|
+
catch (err) {
|
|
721
|
+
console.error(err);
|
|
722
|
+
}
|
|
723
|
+
} }, { children: truncate_string(e.title, { length: 50 }) })), _jsx(Typography, __assign({ color: "error", style: { width: 300 } }, { children: e.error }))] }), e.id)); })] })) })));
|
|
724
|
+
};
|
|
725
|
+
//# sourceMappingURL=forms.v2.js.map
|