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