@tellescope/react-components 1.228.0 → 1.230.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,2289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
6
|
+
var __assign = (this && this.__assign) || function () {
|
|
7
|
+
__assign = Object.assign || function(t) {
|
|
8
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
+
s = arguments[i];
|
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
+
t[p] = s[p];
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
return __assign.apply(this, arguments);
|
|
16
|
+
};
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
50
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
51
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
52
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
53
|
+
function step(op) {
|
|
54
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
55
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
56
|
+
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;
|
|
57
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
58
|
+
switch (op[0]) {
|
|
59
|
+
case 0: case 1: t = op; break;
|
|
60
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
61
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
62
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
63
|
+
default:
|
|
64
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
65
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
66
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
67
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
68
|
+
if (t[2]) _.ops.pop();
|
|
69
|
+
_.trys.pop(); continue;
|
|
70
|
+
}
|
|
71
|
+
op = body.call(thisArg, _);
|
|
72
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
73
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
77
|
+
var t = {};
|
|
78
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
79
|
+
t[p] = s[p];
|
|
80
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
81
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
82
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
83
|
+
t[p[i]] = s[p[i]];
|
|
84
|
+
}
|
|
85
|
+
return t;
|
|
86
|
+
};
|
|
87
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
88
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
89
|
+
if (ar || !(i in from)) {
|
|
90
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
91
|
+
ar[i] = from[i];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
95
|
+
};
|
|
96
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
97
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
98
|
+
};
|
|
99
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
100
|
+
exports.ChargeebeeInput = exports.RichTextInput = exports.ConditionsInput = exports.AllergiesInput = exports.EmotiiInput = exports.HiddenValueInput = exports.RedirectInput = exports.include_current_url_parameters_if_templated = exports.HeightInput = exports.AppointmentBookingInput = exports.RelatedContactsInput = exports.contact_is_valid = exports.MedicationsInput = exports.CanvasMedicationsInput = exports.DatabaseSelectInput = exports.DropdownInput = exports.Progress = exports.StripeInput = exports.MultipleChoiceInput = exports.FilesInput = exports.safe_create_url = exports.FileInput = exports.convertHEIC = exports.SignatureInput = exports.ESignatureTerms = exports.AddressInput = exports.TimezoneInput = exports.TimeInput = exports.InsuranceInput = exports.NumberInput = exports.EmailInput = exports.PhoneInput = exports.StringLongInput = exports.StringInput = exports.DateStringInput = exports.AutoFocusTextField = exports.TableInput = exports.DateInput = exports.RankingInput = exports.RatingInput = exports.PdfViewer = exports.defaultButtonStyles = exports.defaultInputProps = exports.LanguageSelect = void 0;
|
|
101
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
102
|
+
var react_1 = __importStar(require("react"));
|
|
103
|
+
var axios_1 = __importDefault(require("axios"));
|
|
104
|
+
var material_1 = require("@mui/material");
|
|
105
|
+
var react_dropzone_1 = require("react-dropzone");
|
|
106
|
+
var constants_1 = require("@tellescope/constants");
|
|
107
|
+
var utilities_1 = require("@tellescope/utilities");
|
|
108
|
+
var types_models_1 = require("@tellescope/types-models");
|
|
109
|
+
var validation_1 = require("@tellescope/validation");
|
|
110
|
+
var Slider_1 = __importDefault(require("@mui/material/Slider"));
|
|
111
|
+
var LinearProgress_1 = __importDefault(require("@mui/material/LinearProgress"));
|
|
112
|
+
var react_datepicker_1 = __importDefault(require("react-datepicker"));
|
|
113
|
+
var react_datepicker_2 = require("./css/react-datepicker"); // avoids build issue with RN
|
|
114
|
+
var __1 = require("..");
|
|
115
|
+
var css_1 = require("@emotion/css");
|
|
116
|
+
var react_beautiful_dnd_1 = require("react-beautiful-dnd");
|
|
117
|
+
var DragIndicator_1 = __importDefault(require("@mui/icons-material/DragIndicator"));
|
|
118
|
+
var heic2any_1 = __importDefault(require("heic2any"));
|
|
119
|
+
var AddPhotoAlternate_1 = __importDefault(require("@mui/icons-material/AddPhotoAlternate"));
|
|
120
|
+
var Language_1 = __importDefault(require("@mui/icons-material/Language"));
|
|
121
|
+
var react_stripe_js_1 = require("@stripe/react-stripe-js");
|
|
122
|
+
var stripe_js_1 = require("@stripe/stripe-js");
|
|
123
|
+
var icons_material_1 = require("@mui/icons-material");
|
|
124
|
+
var wysiwyg_1 = require("./wysiwyg");
|
|
125
|
+
var LanguageSelect = function (_a) {
|
|
126
|
+
var value = _a.value, props = __rest(_a, ["value"]);
|
|
127
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", justifyContent: "center", wrap: "nowrap", spacing: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(Language_1.default, { color: "primary" }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, style: { width: 150 } }, { children: (0, jsx_runtime_1.jsx)(StringSelector, __assign({}, props, { options: ["English", "Español"], size: "small", value: value === 'Spanish' ? 'Español' : value, label: (value === 'Español' || value === 'Spanish') ? 'Idioma'
|
|
128
|
+
: "Language" })) }))] })));
|
|
129
|
+
};
|
|
130
|
+
exports.LanguageSelect = LanguageSelect;
|
|
131
|
+
exports.defaultInputProps = { sx: {
|
|
132
|
+
borderRadius: 1.5,
|
|
133
|
+
backgroundColor: '#FFFFFF',
|
|
134
|
+
'& .MuiOutlinedInput-root': {
|
|
135
|
+
backgroundColor: '#FFFFFF',
|
|
136
|
+
'&.Mui-error': {
|
|
137
|
+
boxShadow: '0 0 8px 2px rgba(211, 47, 47, 0.3)',
|
|
138
|
+
},
|
|
139
|
+
'&.Mui-error .MuiOutlinedInput-notchedOutline': {
|
|
140
|
+
borderColor: '#d32f2f',
|
|
141
|
+
borderWidth: '2px',
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
'& .MuiInputBase-input': {
|
|
145
|
+
padding: '10px 14px',
|
|
146
|
+
},
|
|
147
|
+
} };
|
|
148
|
+
exports.defaultButtonStyles = {
|
|
149
|
+
borderRadius: '10px',
|
|
150
|
+
};
|
|
151
|
+
var PdfViewer = function (_a) {
|
|
152
|
+
// const [numPages, setNumPages] = useState<number>();
|
|
153
|
+
// const [page, setPage] = useState(1);
|
|
154
|
+
var url = _a.url, _b = _a.height, height = _b === void 0 ? 420 : _b;
|
|
155
|
+
// const parentRef = useRef<HTMLDivElement | null>(null);
|
|
156
|
+
// const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
|
157
|
+
// function onDocumentLoadSuccess({ numPages }: { numPages: number }): void {
|
|
158
|
+
// setNumPages(numPages);
|
|
159
|
+
// }
|
|
160
|
+
// const pdfHeight: number | undefined = pdfPage?._pageInfo?.view?.[3]
|
|
161
|
+
// const pdfWidth: number | undefined = pdfPage?._pageInfo?.view?.[2]
|
|
162
|
+
// const parentWidth = parentRef.current?.clientWidth
|
|
163
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column" }, { children: [(0, jsx_runtime_1.jsx)("iframe", { src:
|
|
164
|
+
// url
|
|
165
|
+
// encodeURI(`http://localhost:5173?url=${url}`)
|
|
166
|
+
// encodeURI(`http://tellescope-pdf-renderer.s3-website.us-east-2.amazonaws.com?url=${url}`)
|
|
167
|
+
encodeURI("https://pdf.tellescope.com?url=".concat(url)), title: "PDF Viewer", style: {
|
|
168
|
+
border: 'none',
|
|
169
|
+
height: height,
|
|
170
|
+
width: '100%',
|
|
171
|
+
marginBottom: '5px'
|
|
172
|
+
} }), (0, jsx_runtime_1.jsx)("a", __assign({ href: url, target: "__blank", rel: "noopener noreferrer", style: { marginTop: 5 } }, { children: "View in new tab or download here" }))] })));
|
|
173
|
+
};
|
|
174
|
+
exports.PdfViewer = PdfViewer;
|
|
175
|
+
var RatingInput = function (_a) {
|
|
176
|
+
var _b, _d, _e, _f, _g;
|
|
177
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange;
|
|
178
|
+
var from = (_d = (_b = field === null || field === void 0 ? void 0 : field.options) === null || _b === void 0 ? void 0 : _b.from) !== null && _d !== void 0 ? _d : 1; // allow 0
|
|
179
|
+
var to = (_f = (_e = field === null || field === void 0 ? void 0 : field.options) === null || _e === void 0 ? void 0 : _e.to) !== null && _f !== void 0 ? _f : 10; // allow 0
|
|
180
|
+
var step = ((_g = field.options) === null || _g === void 0 ? void 0 : _g.rangeStepSize) || 1;
|
|
181
|
+
var allMarks = [];
|
|
182
|
+
for (var i = from; i <= to; i += (step)) {
|
|
183
|
+
allMarks.push({ value: i, label: i });
|
|
184
|
+
}
|
|
185
|
+
var marks = __spreadArray([], allMarks, true);
|
|
186
|
+
while (marks.length > 25) {
|
|
187
|
+
marks = marks.filter(function (_, i) { return i % 2 === 0; });
|
|
188
|
+
}
|
|
189
|
+
return ((0, jsx_runtime_1.jsx)(Slider_1.default, { min: from, max: to, step: step, marks: marks, valueLabelDisplay: marks.length < allMarks.length ? 'auto' : "off", value: value, onChange: function (e, v) { return onChange(v, field.id); }, sx: {
|
|
190
|
+
'& .MuiSlider-thumb': value === undefined ? { display: 'none' } : {}, // Hide thumb until value is set
|
|
191
|
+
} }, field.id));
|
|
192
|
+
};
|
|
193
|
+
exports.RatingInput = RatingInput;
|
|
194
|
+
// a little function to help us with reordering the result
|
|
195
|
+
var reorder = function (list, startIndex, endIndex) {
|
|
196
|
+
var result = Array.from(list);
|
|
197
|
+
var removed = result.splice(startIndex, 1)[0];
|
|
198
|
+
result.splice(endIndex, 0, removed);
|
|
199
|
+
return result;
|
|
200
|
+
};
|
|
201
|
+
var grid = 8;
|
|
202
|
+
var getItemStyle = function (isDragging, draggableStyle) { return (__assign({
|
|
203
|
+
// some basic styles to make the items look a bit nicer
|
|
204
|
+
userSelect: "none", padding: "".concat(grid * 2, "px"), margin: "0 0 ".concat(grid, "px 0"),
|
|
205
|
+
// change background colour if dragging
|
|
206
|
+
backgroundColor: isDragging ? "#ffffff88" : undefined, border: '1px solid', borderColor: "primary.main", borderRadius: 5 }, draggableStyle)); };
|
|
207
|
+
var getListStyle = function (isDraggingOver) { return ({
|
|
208
|
+
// background: isDraggingOver ? "#ffffff44" : undefined,
|
|
209
|
+
// padding: `${grid}px`,
|
|
210
|
+
// width: '250px'
|
|
211
|
+
}); };
|
|
212
|
+
var RankingInput = function (_a) {
|
|
213
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange;
|
|
214
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: 'column' }, { children: [(0, jsx_runtime_1.jsx)(react_beautiful_dnd_1.DragDropContext, __assign({ onDragEnd: function (result) {
|
|
215
|
+
if (!value)
|
|
216
|
+
return;
|
|
217
|
+
if (!result.destination) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
onChange(reorder(value, result.source.index, result.destination.index), field.id);
|
|
221
|
+
} }, { children: (0, jsx_runtime_1.jsx)(react_beautiful_dnd_1.Droppable, __assign({ droppableId: "droppable" }, { children: function (provided, snapshot) { return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({}, provided.droppableProps, { ref: provided.innerRef, sx: getListStyle(snapshot.isDraggingOver) }, { children: [(value !== null && value !== void 0 ? value : []).map(function (item, index) { return ((0, jsx_runtime_1.jsx)(react_beautiful_dnd_1.Draggable, __assign({ draggableId: item, index: index }, { children: function (provided, snapshot) { return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", justifyContent: "space-between", ref: provided.innerRef }, provided.draggableProps, provided.dragHandleProps, { sx: getItemStyle(snapshot.isDragging, provided.draggableProps.style) }, { children: [item, (0, jsx_runtime_1.jsx)(DragIndicator_1.default, { color: "primary" })] }))); } }), item)); }), provided.placeholder] }))); } })) })), (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "primary", style: { marginTop: 3 } }, { children: "Drag and drop to re-order the above options" }))] })));
|
|
222
|
+
};
|
|
223
|
+
exports.RankingInput = RankingInput;
|
|
224
|
+
var CustomDateInput = (0, react_1.forwardRef)(function (props, ref) { return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({ InputProps: exports.defaultInputProps, fullWidth: true, inputRef: ref }, props))); });
|
|
225
|
+
var DateInput = function (_a) {
|
|
226
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange, _b = _a.placement, placement = _b === void 0 ? 'top' : _b, props = __rest(_a, ["field", "value", "onChange", "placement"]);
|
|
227
|
+
var inputRef = (0, react_1.useRef)(null);
|
|
228
|
+
return ((0, jsx_runtime_1.jsx)(react_datepicker_1.default // wrap in item to prevent movement on focused
|
|
229
|
+
, { selected: value, onChange: function (d) { return onChange === null || onChange === void 0 ? void 0 : onChange(d, field.id); }, showTimeSelect: true, required: !field.isOptional, dateFormat: "Pp", autoComplete: "off", timeIntervals: 15, popperPlacement: placement, customInput: (0, jsx_runtime_1.jsx)(CustomDateInput, __assign({ inputRef: inputRef }, props)),
|
|
230
|
+
// className={css`width: 100%;`}
|
|
231
|
+
className: (0, css_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", ""], ["", ""])), react_datepicker_2.datepickerCSS) }));
|
|
232
|
+
};
|
|
233
|
+
exports.DateInput = DateInput;
|
|
234
|
+
var TableInput = function (_a) {
|
|
235
|
+
var _b;
|
|
236
|
+
var field = _a.field, _d = _a.value, value = _d === void 0 ? [] : _d, onChange = _a.onChange, props = __rest(_a, ["field", "value", "onChange"]);
|
|
237
|
+
var choices = (_b = field.options) === null || _b === void 0 ? void 0 : _b.tableChoices;
|
|
238
|
+
var handleNewRow = (0, react_1.useCallback)(function () {
|
|
239
|
+
if (!(choices === null || choices === void 0 ? void 0 : choices.length))
|
|
240
|
+
return;
|
|
241
|
+
onChange(__spreadArray(__spreadArray([], value, true), [choices.map(function (c) { return ({
|
|
242
|
+
label: c.label,
|
|
243
|
+
entry: '',
|
|
244
|
+
}); })], false), field.id, true);
|
|
245
|
+
}, [value, field.id]);
|
|
246
|
+
var handleChange = (0, react_1.useCallback)(function (r, c, u) {
|
|
247
|
+
onChange(value.map(function (v, _i) {
|
|
248
|
+
return _i !== r
|
|
249
|
+
? v
|
|
250
|
+
: v.map(function (e, _c) { return _c === c ? u : e; });
|
|
251
|
+
}), field.id, true);
|
|
252
|
+
}, [value, onChange, field.id]);
|
|
253
|
+
var handleRemove = (0, react_1.useCallback)(function (i) {
|
|
254
|
+
onChange(value.filter(function (_, _i) { return i !== _i; }), field.id, true);
|
|
255
|
+
}, [value, onChange, field.id]);
|
|
256
|
+
(0, react_1.useEffect)(function () {
|
|
257
|
+
if (field.isOptional)
|
|
258
|
+
return;
|
|
259
|
+
if (value.length)
|
|
260
|
+
return;
|
|
261
|
+
handleNewRow();
|
|
262
|
+
}, [field.isOptional, value, handleNewRow]);
|
|
263
|
+
if (!(choices === null || choices === void 0 ? void 0 : choices.length)) {
|
|
264
|
+
return (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error" }, { children: "No input choices available" }));
|
|
265
|
+
}
|
|
266
|
+
var length = choices.length || 1;
|
|
267
|
+
var iconWidth = '35px';
|
|
268
|
+
var width = "calc(".concat((100 / length).toFixed(2), "% - calc(").concat(iconWidth, " / ").concat(length, "))");
|
|
269
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column" }, { children: [value.map(function (row, i) { return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", spacing: 1 }, { children: [choices.map(function (v, columnIndex) {
|
|
270
|
+
var _a, _b, _d, _e, _f, _g, _h;
|
|
271
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { width: width } }, { children: v.type === 'Text'
|
|
272
|
+
? ((0, jsx_runtime_1.jsx)(material_1.TextField, { label: v.label, size: "small", fullWidth: true, title: v.label, InputProps: exports.defaultInputProps, value: (_a = row.find(function (c, _i) { return columnIndex === _i; })) === null || _a === void 0 ? void 0 : _a.entry, onChange: function (e) { return handleChange(i, columnIndex, { label: v.label, entry: e.target.value }); } }))
|
|
273
|
+
: v.type === 'Date' ? ((0, jsx_runtime_1.jsx)(exports.DateStringInput, { label: v.label, size: "small", fullWidth: true, title: v.label, field: field, value: (_b = row.find(function (c, _i) { return columnIndex === _i; })) === null || _b === void 0 ? void 0 : _b.entry, onChange: function (entry) {
|
|
274
|
+
if (entry === void 0) { entry = ''; }
|
|
275
|
+
return handleChange(i, columnIndex, { label: v.label, entry: entry });
|
|
276
|
+
} }))
|
|
277
|
+
: v.type === 'Select' ? ((0, jsx_runtime_1.jsxs)(material_1.FormControl, __assign({ size: "small", fullWidth: true }, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, __assign({ id: "demo-select-small" }, { children: v.label })), (0, jsx_runtime_1.jsxs)(material_1.Select, __assign({ label: v.label, size: "small", title: v.label, sx: exports.defaultInputProps.sx, value: (_d = row.find(function (c, _i) { return columnIndex === _i; })) === null || _d === void 0 ? void 0 : _d.entry, onChange: function (e) { return handleChange(i, columnIndex, { label: v.label, entry: e.target.value }); } }, { children: [(0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: "" }, { children: (0, jsx_runtime_1.jsx)("em", { children: "None" }) })), v.info.choices.map(function (c) { return ((0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: c }, { children: c }), c)); })] }))] })))
|
|
278
|
+
: (v.type === 'Database' && v.info.databaseId && v.info.databaseLabel) ? ((0, jsx_runtime_1.jsx)(exports.DatabaseSelectInput, { responses: [], size: "small", field: __assign(__assign({}, field), { options: { databaseId: v.info.databaseId, databaseLabel: v.info.databaseLabel }, title: v.label }), value: ((_e = row.find(function (_, _i) { return columnIndex === _i; })) === null || _e === void 0 ? void 0 : _e.entry) ? [{
|
|
279
|
+
text: JSON.parse(((_f = row.find(function (_, _i) { return columnIndex === _i; })) === null || _f === void 0 ? void 0 : _f.entry) || '{}').text || '',
|
|
280
|
+
databaseId: JSON.parse(((_g = row.find(function (_, _i) { return columnIndex === _i; })) === null || _g === void 0 ? void 0 : _g.entry) || '{}').databaseId || '',
|
|
281
|
+
recordId: JSON.parse(((_h = row.find(function (_, _i) { return columnIndex === _i; })) === null || _h === void 0 ? void 0 : _h.entry) || '{}').recordId || '',
|
|
282
|
+
}] : [], onChange: function (records) { var _a; return handleChange(i, columnIndex, { label: v.label, entry: JSON.stringify((_a = records === null || records === void 0 ? void 0 : records[0]) !== null && _a !== void 0 ? _a : '') }); } }))
|
|
283
|
+
: null }), v.label));
|
|
284
|
+
}), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { ml: 'auto', width: iconWidth } }, { children: (0, jsx_runtime_1.jsx)(__1.LabeledIconButton, { Icon: __1.CancelIcon, label: "Remove", onClick: function () { return handleRemove(i); }, disabled: !field.isOptional && value.length === 1 }) }))] }), i), (0, jsx_runtime_1.jsx)(material_1.Divider, { flexItem: true, sx: { my: 1 } })] })); }), (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ variant: "outlined", size: "small", onClick: handleNewRow, sx: { width: 200 } }, { children: "Add new entry" }))] })));
|
|
285
|
+
};
|
|
286
|
+
exports.TableInput = TableInput;
|
|
287
|
+
var AutoFocusTextField = function (props) { return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({ InputProps: exports.defaultInputProps }, props))); };
|
|
288
|
+
exports.AutoFocusTextField = AutoFocusTextField;
|
|
289
|
+
var CustomDateStringInput = (0, react_1.forwardRef)(function (props, ref) { return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({ InputProps: exports.defaultInputProps, fullWidth: true, inputRef: ref }, props))); });
|
|
290
|
+
var DateStringInput = function (_a) {
|
|
291
|
+
var _b;
|
|
292
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange, props = __rest(_a, ["field", "value", "onChange"]);
|
|
293
|
+
var inputRef = (0, react_1.useRef)(null);
|
|
294
|
+
// if (value && isDateString(value)) {
|
|
295
|
+
// console.log(value, new Date(
|
|
296
|
+
// new Date(MM_DD_YYYY_to_YYYY_MM_DD(value)).getTime()
|
|
297
|
+
// + (new Date().getTimezoneOffset() * 60 * 1000)
|
|
298
|
+
// ))
|
|
299
|
+
// }
|
|
300
|
+
return (((_b = field.options) === null || _b === void 0 ? void 0 : _b.useDatePicker)
|
|
301
|
+
? ((0, jsx_runtime_1.jsx)(react_datepicker_1.default // wrap in item to prevent movement on focused
|
|
302
|
+
, { selected: (value && (0, __1.isDateString)(value))
|
|
303
|
+
? new Date(new Date((0, utilities_1.MM_DD_YYYY_to_YYYY_MM_DD)(value)).getTime()
|
|
304
|
+
+ ((new Date().getTimezoneOffset() + 60) * 60 * 1000) // additional hour (60 minutes) needs to be added for date to line up properly
|
|
305
|
+
)
|
|
306
|
+
: undefined, onChange: function (d) { return onChange === null || onChange === void 0 ? void 0 : onChange((0, utilities_1.mm_dd_yyyy)(d), field.id); }, showTimeSelect: false, required: !field.isOptional, autoComplete: "off", dateFormat: "MM-dd-yyyy", customInput: (0, jsx_runtime_1.jsx)(CustomDateStringInput, __assign({ inputRef: inputRef }, props, { label: (!field.title && field.placeholder) ? field.placeholder : props.label })),
|
|
307
|
+
// className={css`width: 100%;`}
|
|
308
|
+
className: (0, css_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["", ""], ["", ""])), react_datepicker_2.datepickerCSS) }))
|
|
309
|
+
: ((0, jsx_runtime_1.jsx)(exports.AutoFocusTextField, __assign({}, props, { required: !field.isOptional, fullWidth: true, placeholder: "MM-DD-YYYY", value: value, label: (!field.title && field.placeholder) ? field.placeholder : props.label, onChange: function (e) {
|
|
310
|
+
var v = e.target.value || '';
|
|
311
|
+
onChange((v.length === 2 && /\d{2}/.test(v) && (value === null || value === void 0 ? void 0 : value.length) !== 3 // allow deletion
|
|
312
|
+
? v + '-'
|
|
313
|
+
: v.length === 5 && /\d{2}-\d{2}/.test(v) && (value === null || value === void 0 ? void 0 : value.length) !== 6 // allow deletion
|
|
314
|
+
? v + '-'
|
|
315
|
+
: v)
|
|
316
|
+
.replaceAll('/', '-'), field.id);
|
|
317
|
+
} }))));
|
|
318
|
+
};
|
|
319
|
+
exports.DateStringInput = DateStringInput;
|
|
320
|
+
var StringInput = function (_a) {
|
|
321
|
+
var field = _a.field, value = _a.value, form = _a.form, onChange = _a.onChange, props = __rest(_a, ["field", "value", "form", "onChange"]);
|
|
322
|
+
return ((0, jsx_runtime_1.jsx)(exports.AutoFocusTextField, __assign({}, props, { required: !field.isOptional, fullWidth: true, value: value, onChange: function (e) { return onChange(e.target.value, field.id); }, placeholder: (field.placeholder || (0, __1.form_display_text_for_language)(form, "Answer here...", '')), label: (!field.title && field.placeholder) ? field.placeholder : props.label })));
|
|
323
|
+
};
|
|
324
|
+
exports.StringInput = StringInput;
|
|
325
|
+
var StringLongInput = function (_a) {
|
|
326
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange, form = _a.form, props = __rest(_a, ["field", "value", "onChange", "form"]);
|
|
327
|
+
return ((0, jsx_runtime_1.jsx)(exports.AutoFocusTextField, __assign({}, props, { multiline: true, minRows: 3, maxRows: 8, required: !field.isOptional, fullWidth: true, value: value, onChange: function (e) { return onChange(e.target.value, field.id); }, placeholder: field.placeholder || (0, __1.form_display_text_for_language)(form, "Answer here...", ''), label: (!field.title && field.placeholder) ? field.placeholder : props.label })));
|
|
328
|
+
};
|
|
329
|
+
exports.StringLongInput = StringLongInput;
|
|
330
|
+
var PhoneInput = function (_a) {
|
|
331
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange, form = _a.form, props = __rest(_a, ["field", "value", "onChange", "form"]);
|
|
332
|
+
return ((0, jsx_runtime_1.jsx)(exports.AutoFocusTextField, __assign({}, props, { required: !field.isOptional, fullWidth: true, value: value, onChange: function (e) { return onChange(e.target.value, field.id); }, placeholder: field.placeholder || (0, __1.form_display_text_for_language)(form, "Enter phone...", ''), label: (!field.title && field.placeholder) ? field.placeholder : props.label })));
|
|
333
|
+
};
|
|
334
|
+
exports.PhoneInput = PhoneInput;
|
|
335
|
+
var EmailInput = function (_a) {
|
|
336
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange, form = _a.form, props = __rest(_a, ["field", "value", "onChange", "form"]);
|
|
337
|
+
return ((0, jsx_runtime_1.jsx)(exports.AutoFocusTextField, __assign({}, props, { required: !field.isOptional, fullWidth: true, type: "email", value: value, onChange: function (e) { return onChange(e.target.value, field.id); }, placeholder: field.placeholder || (0, __1.form_display_text_for_language)(form, "Enter email...", ''), label: (!field.title && field.placeholder) ? field.placeholder : props.label })));
|
|
338
|
+
};
|
|
339
|
+
exports.EmailInput = EmailInput;
|
|
340
|
+
var NumberInput = function (_a) {
|
|
341
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange, form = _a.form, props = __rest(_a, ["field", "value", "onChange", "form"]);
|
|
342
|
+
// Prevent the default scroll behavior when focused on this input
|
|
343
|
+
var inputRef = (0, react_1.useRef)(null);
|
|
344
|
+
(0, react_1.useEffect)(function () {
|
|
345
|
+
var _a;
|
|
346
|
+
var handleWheel = function (e) {
|
|
347
|
+
var _a;
|
|
348
|
+
(_a = e === null || e === void 0 ? void 0 : e.preventDefault) === null || _a === void 0 ? void 0 : _a.call(e);
|
|
349
|
+
};
|
|
350
|
+
// Get the actual input element inside the TextField
|
|
351
|
+
var inputElement = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('input');
|
|
352
|
+
if (inputElement) {
|
|
353
|
+
inputElement.addEventListener('wheel', handleWheel, { passive: false });
|
|
354
|
+
// Clean up event listener when component unmounts
|
|
355
|
+
return function () {
|
|
356
|
+
inputElement.removeEventListener('wheel', handleWheel);
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}, []);
|
|
360
|
+
return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({ ref: inputRef, autoFocus: true, InputProps: exports.defaultInputProps }, props, { required: !field.isOptional, fullWidth: true, type: "number", value: value, onChange: function (e) { return onChange(parseInt(e.target.value), field.id); }, label: (!field.title && field.placeholder) ? field.placeholder : props.label, placeholder: field.placeholder || (0, __1.form_display_text_for_language)(form, "Enter a number...", ''), onScroll: function (e) { return e.preventDefault(); }, sx: {
|
|
361
|
+
'& input[type=number]': {
|
|
362
|
+
'-moz-appearance': 'textfield'
|
|
363
|
+
},
|
|
364
|
+
'& input[type=number]::-webkit-outer-spin-button': {
|
|
365
|
+
'-webkit-appearance': 'none',
|
|
366
|
+
margin: 0
|
|
367
|
+
},
|
|
368
|
+
'& input[type=number]::-webkit-inner-spin-button': {
|
|
369
|
+
'-webkit-appearance': 'none',
|
|
370
|
+
margin: 0
|
|
371
|
+
}
|
|
372
|
+
} })));
|
|
373
|
+
};
|
|
374
|
+
exports.NumberInput = NumberInput;
|
|
375
|
+
var InsuranceInput = function (_a) {
|
|
376
|
+
var _b, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
377
|
+
var field = _a.field, onDatabaseSelect = _a.onDatabaseSelect, value = _a.value, onChange = _a.onChange, form = _a.form, responses = _a.responses, enduser = _a.enduser, props = __rest(_a, ["field", "onDatabaseSelect", "value", "onChange", "form", "responses", "enduser"]);
|
|
378
|
+
var session = (0, __1.useResolvedSession)();
|
|
379
|
+
var _t = (0, react_1.useState)([]), payers = _t[0], setPayers = _t[1];
|
|
380
|
+
var _u = (0, react_1.useState)(''), query = _u[0], setQuery = _u[1];
|
|
381
|
+
var addressQuestion = (0, react_1.useMemo)(function () { return responses === null || responses === void 0 ? void 0 : responses.find(function (r) {
|
|
382
|
+
var _a;
|
|
383
|
+
if (r.answer.type !== 'Address')
|
|
384
|
+
return false;
|
|
385
|
+
if (r.field.intakeField !== 'Address')
|
|
386
|
+
return false;
|
|
387
|
+
// make sure state is actually defined (in case of multiple address questions, where 1+ are blank)
|
|
388
|
+
if (!((_a = r.answer.value) === null || _a === void 0 ? void 0 : _a.state))
|
|
389
|
+
return false;
|
|
390
|
+
return true;
|
|
391
|
+
}); }, [responses]);
|
|
392
|
+
var state = (0, react_1.useMemo)(function () {
|
|
393
|
+
var _a, _b, _d;
|
|
394
|
+
return ((((_a = addressQuestion === null || addressQuestion === void 0 ? void 0 : addressQuestion.answer) === null || _a === void 0 ? void 0 : _a.type) === 'Address' ? (_d = (_b = addressQuestion === null || addressQuestion === void 0 ? void 0 : addressQuestion.answer) === null || _b === void 0 ? void 0 : _b.value) === null || _d === void 0 ? void 0 : _d.state : undefined) || (enduser === null || enduser === void 0 ? void 0 : enduser.state));
|
|
395
|
+
}, [enduser === null || enduser === void 0 ? void 0 : enduser.state, addressQuestion]);
|
|
396
|
+
var loadRef = (0, react_1.useRef)(false); // so session changes don't cause
|
|
397
|
+
(0, react_1.useEffect)(function () {
|
|
398
|
+
var _a;
|
|
399
|
+
if (((_a = field === null || field === void 0 ? void 0 : field.options) === null || _a === void 0 ? void 0 : _a.dataSource) === constants_1.CANVAS_TITLE)
|
|
400
|
+
return; // instead, look-up while typing against Canvas Search API
|
|
401
|
+
if (loadRef.current)
|
|
402
|
+
return;
|
|
403
|
+
loadRef.current = true;
|
|
404
|
+
// just load all at once, should be reasonably performant compared to paging
|
|
405
|
+
session.api.form_fields.load_choices_from_database({ fieldId: field.id, limit: 10000 })
|
|
406
|
+
.then(function (_a) {
|
|
407
|
+
var choices = _a.choices;
|
|
408
|
+
return setPayers(choices
|
|
409
|
+
.map(function (c) {
|
|
410
|
+
var _a, _b, _d, _e, _f, _g, _h, _j;
|
|
411
|
+
return ({
|
|
412
|
+
id: ((_b = (_a = c.values.find(function (v) { var _a, _b; return ((_b = (_a = v.label) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'id'; })) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.toString()) || '',
|
|
413
|
+
name: ((_e = (_d = c.values.find(function (v) { var _a, _b; return ((_b = (_a = v.label) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'name'; })) === null || _d === void 0 ? void 0 : _d.value) === null || _e === void 0 ? void 0 : _e.toString()) || '',
|
|
414
|
+
state: ((_g = (_f = c.values.find(function (v) { var _a, _b; return ((_b = (_a = v.label) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'state'; })) === null || _f === void 0 ? void 0 : _f.value) === null || _g === void 0 ? void 0 : _g.toString()) || '',
|
|
415
|
+
type: ((_j = (_h = c.values.find(function (v) { var _a, _b; return ((_b = (_a = v.label) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'type'; })) === null || _h === void 0 ? void 0 : _h.value) === null || _j === void 0 ? void 0 : _j.toString()) || '',
|
|
416
|
+
databaseRecord: c,
|
|
417
|
+
});
|
|
418
|
+
})
|
|
419
|
+
.filter(function (c) { return !c.state || !state || (c.state === state); }));
|
|
420
|
+
})
|
|
421
|
+
.catch(console.error);
|
|
422
|
+
}, [session, state, (_b = field === null || field === void 0 ? void 0 : field.options) === null || _b === void 0 ? void 0 : _b.dataSource]);
|
|
423
|
+
var searchRef = (0, react_1.useRef)(query);
|
|
424
|
+
(0, react_1.useEffect)(function () {
|
|
425
|
+
var _a;
|
|
426
|
+
if (((_a = field === null || field === void 0 ? void 0 : field.options) === null || _a === void 0 ? void 0 : _a.dataSource) !== constants_1.CANVAS_TITLE) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (!query)
|
|
430
|
+
return;
|
|
431
|
+
if (searchRef.current === query)
|
|
432
|
+
return;
|
|
433
|
+
searchRef.current = query;
|
|
434
|
+
session.api.integrations.proxy_read({
|
|
435
|
+
integration: constants_1.CANVAS_TITLE,
|
|
436
|
+
query: query,
|
|
437
|
+
type: 'organizations',
|
|
438
|
+
})
|
|
439
|
+
.then(function (_a) {
|
|
440
|
+
var data = _a.data;
|
|
441
|
+
try {
|
|
442
|
+
setPayers(data.map(function (d) { return ({
|
|
443
|
+
id: d.resource.id,
|
|
444
|
+
name: d.resource.name,
|
|
445
|
+
}); }));
|
|
446
|
+
}
|
|
447
|
+
catch (err) {
|
|
448
|
+
console.error;
|
|
449
|
+
}
|
|
450
|
+
})
|
|
451
|
+
.catch(console.error);
|
|
452
|
+
}, [session, (_d = field === null || field === void 0 ? void 0 : field.options) === null || _d === void 0 ? void 0 : _d.dataSource, query]);
|
|
453
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, spacing: 2, sx: { mt: '0' } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: (0, jsx_runtime_1.jsx)(material_1.Autocomplete, { freeSolo: !((_e = field.options) === null || _e === void 0 ? void 0 : _e.requirePredefinedInsurer), options: payers.map(function (p) { return p.name; }), value: (value === null || value === void 0 ? void 0 : value.payerName) || '', onChange: function (e, v) {
|
|
454
|
+
var _a, _b;
|
|
455
|
+
return onChange(__assign(__assign({}, value), { payerName: v || '', payerId: ((_a = payers.find(function (p) { return p.name === v; })) === null || _a === void 0 ? void 0 : _a.id) || '', payerType: ((_b = payers.find(function (p) { return p.name === v; })) === null || _b === void 0 ? void 0 : _b.type) || '' }), field.id);
|
|
456
|
+
}, onInputChange: ((_f = field.options) === null || _f === void 0 ? void 0 : _f.requirePredefinedInsurer)
|
|
457
|
+
? function (e, v) { if (v) {
|
|
458
|
+
setQuery(v);
|
|
459
|
+
} }
|
|
460
|
+
: function (e, v) {
|
|
461
|
+
var _a, _b, _d;
|
|
462
|
+
if (v) {
|
|
463
|
+
setQuery(v);
|
|
464
|
+
}
|
|
465
|
+
var databaseRecord = (_a = payers.find(function (p) { return p.name === v; })) === null || _a === void 0 ? void 0 : _a.databaseRecord;
|
|
466
|
+
if (databaseRecord) {
|
|
467
|
+
onDatabaseSelect === null || onDatabaseSelect === void 0 ? void 0 : onDatabaseSelect([databaseRecord]);
|
|
468
|
+
}
|
|
469
|
+
onChange(__assign(__assign({}, value), { payerName: v || '', payerId: ((_b = payers.find(function (p) { return p.name === v; })) === null || _b === void 0 ? void 0 : _b.id) || '', payerType: ((_d = payers.find(function (p) { return p.name === v; })) === null || _d === void 0 ? void 0 : _d.type) || '' }), field.id);
|
|
470
|
+
}, renderInput: function (params) {
|
|
471
|
+
var _a;
|
|
472
|
+
return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: exports.defaultInputProps.sx }), required: !field.isOptional, size: "small", label: "Insurer", placeholder: ((_a = field.options) === null || _a === void 0 ? void 0 : _a.dataSource) === constants_1.CANVAS_TITLE ? "Search insurer..." : "Insurer" })));
|
|
473
|
+
} }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { InputProps: exports.defaultInputProps, required: !field.isOptional, fullWidth: true, value: (_g = value === null || value === void 0 ? void 0 : value.memberId) !== null && _g !== void 0 ? _g : '', onChange: function (e) { return onChange(__assign(__assign({}, value), { memberId: e.target.value }), field.id); }, label: (0, __1.form_display_text_for_language)(form, "Member ID", ''), size: "small" }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { InputProps: exports.defaultInputProps, required: false, fullWidth: true, value: (_h = value === null || value === void 0 ? void 0 : value.planName) !== null && _h !== void 0 ? _h : '', onChange: function (e) { return onChange(__assign(__assign({}, value), { planName: e.target.value }), field.id); }, label: (0, __1.form_display_text_for_language)(form, "Plan Name", ''), size: "small" }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: (0, jsx_runtime_1.jsx)(exports.DateStringInput, { size: "small", label: "Plan Start Date", field: __assign(__assign({}, field), { isOptional: true }), value: (value === null || value === void 0 ? void 0 : value.startDate) || '', onChange: function (startDate) {
|
|
474
|
+
return onChange(__assign(__assign({}, value), { startDate: startDate }), field.id);
|
|
475
|
+
} }) })), ((_j = field.options) === null || _j === void 0 ? void 0 : _j.includeGroupNumber) &&
|
|
476
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { InputProps: exports.defaultInputProps, fullWidth: true, value: (_k = value === null || value === void 0 ? void 0 : value.groupNumber) !== null && _k !== void 0 ? _k : '', onChange: function (e) { return onChange(__assign(__assign({}, value), { groupNumber: e.target.value }), field.id); }, label: (0, __1.form_display_text_for_language)(form, "Group Number", ''), size: "small" }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: (0, jsx_runtime_1.jsx)(StringSelector, { size: "small", label: "Relationship to Policy Owner", options: ((((_l = field.options) === null || _l === void 0 ? void 0 : _l.billingProvider) === constants_1.CANVAS_TITLE || ((_m = field.options) === null || _m === void 0 ? void 0 : _m.dataSource) === constants_1.CANVAS_TITLE)
|
|
477
|
+
? constants_1.INSURANCE_RELATIONSHIPS_CANVAS
|
|
478
|
+
: constants_1.INSURANCE_RELATIONSHIPS)
|
|
479
|
+
.sort(function (x, y) { return x.localeCompare(y); }), value: (value === null || value === void 0 ? void 0 : value.relationship) || 'Self', onChange: function (relationship) {
|
|
480
|
+
return onChange(__assign(__assign({}, value), { relationship: relationship || 'Self' }), field.id);
|
|
481
|
+
} }) })), ((value === null || value === void 0 ? void 0 : value.relationship) || 'Self') !== 'Self' &&
|
|
482
|
+
(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ sx: { fontWeight: 'bold' } }, { children: "Policy Owner Details" })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 6 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "First Name", size: "small", InputProps: exports.defaultInputProps, fullWidth: true, value: ((_o = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _o === void 0 ? void 0 : _o.fname) || '', required: !field.isOptional, onChange: function (e) {
|
|
483
|
+
return onChange(__assign(__assign({}, value), { relationshipDetails: __assign(__assign({}, value === null || value === void 0 ? void 0 : value.relationshipDetails), { fname: e.target.value }) }), field.id);
|
|
484
|
+
} }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 6 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "Last Name", size: "small", InputProps: exports.defaultInputProps, fullWidth: true, value: ((_p = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _p === void 0 ? void 0 : _p.lname) || '', required: !field.isOptional, onChange: function (e) {
|
|
485
|
+
return onChange(__assign(__assign({}, value), { relationshipDetails: __assign(__assign({}, value === null || value === void 0 ? void 0 : value.relationshipDetails), { lname: e.target.value }) }), field.id);
|
|
486
|
+
} }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 6 }, { children: (0, jsx_runtime_1.jsx)(StringSelector, { options: constants_1.TELLESCOPE_GENDERS, size: "small", label: "Gender", value: ((_q = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _q === void 0 ? void 0 : _q.gender) || '', required: !field.isOptional, onChange: function (v) {
|
|
487
|
+
return onChange(__assign(__assign({}, value), { relationshipDetails: __assign(__assign({}, value === null || value === void 0 ? void 0 : value.relationshipDetails), { gender: v }) }), field.id);
|
|
488
|
+
} }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 6 }, { children: (0, jsx_runtime_1.jsx)(exports.DateStringInput, { size: "small", label: "Date of Birth", field: __assign(__assign({}, field), { isOptional: field.isOptional || ((_r = field.options) === null || _r === void 0 ? void 0 : _r.billingProvider) === 'Candid' }), value: ((_s = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _s === void 0 ? void 0 : _s.dateOfBirth) || '', onChange: function (dateOfBirth) {
|
|
489
|
+
return onChange(__assign(__assign({}, value), { relationshipDetails: __assign(__assign({}, value === null || value === void 0 ? void 0 : value.relationshipDetails), { dateOfBirth: dateOfBirth }) }), field.id);
|
|
490
|
+
} }) }))] })] })));
|
|
491
|
+
};
|
|
492
|
+
exports.InsuranceInput = InsuranceInput;
|
|
493
|
+
var StringSelector = function (_a) {
|
|
494
|
+
var options = _a.options, value = _a.value, onChange = _a.onChange, required = _a.required, getDisplayValue = _a.getDisplayValue, props = __rest(_a, ["options", "value", "onChange", "required", "getDisplayValue"]);
|
|
495
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.FormControl, __assign({ fullWidth: true, size: props.size, required: required }, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { children: props.label }), (0, jsx_runtime_1.jsx)(material_1.Select, __assign({}, props, { value: value, onChange: function (e) { return onChange(e.target.value); }, fullWidth: true, sx: exports.defaultInputProps.sx }, { children: options.map(function (o, i) {
|
|
496
|
+
var _a;
|
|
497
|
+
return ((0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: o }, { children: (_a = getDisplayValue === null || getDisplayValue === void 0 ? void 0 : getDisplayValue(o)) !== null && _a !== void 0 ? _a : o }), o || i));
|
|
498
|
+
}) }))] })));
|
|
499
|
+
};
|
|
500
|
+
var HourSelector = function (props) { return ((0, jsx_runtime_1.jsx)(StringSelector, __assign({}, props, { options: Array(12).fill('').map(function (_, i) { return (i + 1) <= 9 ? "0".concat(i + 1) : (i + 1).toString(); }) }))); };
|
|
501
|
+
var MinuteSelector = function (props) { return ((0, jsx_runtime_1.jsx)(StringSelector, __assign({}, props, { options: Array(60).fill('').map(function (_, i) { return i <= 9 ? "0".concat(i) : i.toString(); }) }))); };
|
|
502
|
+
var AmPmSelector = function (props) { return ((0, jsx_runtime_1.jsx)(StringSelector, __assign({}, props, { options: ['AM', 'PM'] }))); };
|
|
503
|
+
var TimeInput = function (_a) {
|
|
504
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange, props = __rest(_a, ["field", "value", "onChange"]);
|
|
505
|
+
var _b = (value || '').split(':'), hour = _b[0], _d = _b[1], rest = _d === void 0 ? '' : _d;
|
|
506
|
+
var _e = rest.split(' '), minute = _e[0], amPm = _e[1], _f = _e[2], zone = _f === void 0 ? (0, utilities_1.getLocalTimezone)() : _f;
|
|
507
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: 'center', spacing: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { width: 100 } }, { children: (0, jsx_runtime_1.jsx)(HourSelector, { value: hour, onChange: function (hour) { return onChange("".concat(hour, ":").concat(minute, " ").concat(amPm, " ").concat(zone), field.id); } }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { width: 100 } }, { children: (0, jsx_runtime_1.jsx)(MinuteSelector, { value: minute, onChange: function (minute) { return onChange("".concat(hour, ":").concat(minute, " ").concat(amPm, " ").concat(zone), field.id); } }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { width: 100 } }, { children: (0, jsx_runtime_1.jsx)(AmPmSelector, { value: amPm, onChange: function (amPm) { return onChange("".concat(hour, ":").concat(minute, " ").concat(amPm, " ").concat(zone), field.id); } }) }))] })));
|
|
508
|
+
};
|
|
509
|
+
exports.TimeInput = TimeInput;
|
|
510
|
+
var TimezoneInput = function (_a) {
|
|
511
|
+
var _b = _a.value, value = _b === void 0 ? '' : _b, field = _a.field, onChange = _a.onChange, props = __rest(_a, ["value", "field", "onChange"]);
|
|
512
|
+
return ((0, jsx_runtime_1.jsx)(StringSelector, __assign({}, props, { value: value, options: types_models_1.TIMEZONES_USA, onChange: function (v) { return onChange(v, field.id); } })));
|
|
513
|
+
};
|
|
514
|
+
exports.TimezoneInput = TimezoneInput;
|
|
515
|
+
var AddressInput = function (_a) {
|
|
516
|
+
var _b, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
517
|
+
var field = _a.field, form = _a.form, value = _a.value, onChange = _a.onChange, props = __rest(_a, ["field", "form", "value", "onChange"]);
|
|
518
|
+
return (
|
|
519
|
+
// state only
|
|
520
|
+
((_d = (_b = field.options) === null || _b === void 0 ? void 0 : _b.addressFields) === null || _d === void 0 ? void 0 : _d.includes('state'))
|
|
521
|
+
? ((0, jsx_runtime_1.jsx)(material_1.Autocomplete, __assign({ value: (value === null || value === void 0 ? void 0 : value.state) || '', options: ((_f = (_e = field.options) === null || _e === void 0 ? void 0 : _e.validStates) === null || _f === void 0 ? void 0 : _f.length) ? field.options.validStates : validation_1.VALID_STATES, disablePortal: true, onChange: function (e, v) { return v &&
|
|
522
|
+
onChange(__assign(__assign({}, value), { state: v !== null && v !== void 0 ? v : '' }), field.id); }, renderInput: function (params) { return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: exports.defaultInputProps.sx }), required: !field.isOptional,
|
|
523
|
+
// don't use 'small' so as to be consistent with other text fields, in case this is used in a group
|
|
524
|
+
// size={'small'}
|
|
525
|
+
label: (0, __1.form_display_text_for_language)(form, "State") }))); } }, props)))
|
|
526
|
+
: ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 2, sx: { mt: 0 } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(exports.AutoFocusTextField, __assign({}, props, { size: "small", required: !field.isOptional, fullWidth: true, value: (_g = value === null || value === void 0 ? void 0 : value.addressLineOne) !== null && _g !== void 0 ? _g : '', label: (0, __1.form_display_text_for_language)(form, "Address Line 1"), placeholder: (0, __1.form_display_text_for_language)(form, "Address Line 1"), onChange: function (e) {
|
|
527
|
+
var _a;
|
|
528
|
+
return onChange(__assign(__assign({}, value), { addressLineOne: (_a = e.target.value) !== null && _a !== void 0 ? _a : '' }), field.id);
|
|
529
|
+
} })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, props, { size: "small", required: false, fullWidth: true, InputProps: exports.defaultInputProps, value: (_h = value === null || value === void 0 ? void 0 : value.addressLineTwo) !== null && _h !== void 0 ? _h : '', label: (0, __1.form_display_text_for_language)(form, "Address Line 2"), placeholder: (0, __1.form_display_text_for_language)(form, "Address Line 2"), onChange: function (e) {
|
|
530
|
+
var _a;
|
|
531
|
+
return onChange(__assign(__assign({}, value), { addressLineTwo: (_a = e.target.value) !== null && _a !== void 0 ? _a : '' }), field.id);
|
|
532
|
+
} })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", justifyContent: "space-between", spacing: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12, sm: field.fullZIP ? 5 : 6 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, props, { size: "small", required: !field.isOptional, InputProps: exports.defaultInputProps, fullWidth: true, value: (_j = value === null || value === void 0 ? void 0 : value.city) !== null && _j !== void 0 ? _j : '', label: (0, __1.form_display_text_for_language)(form, "City"), placeholder: (0, __1.form_display_text_for_language)(form, "City"), onChange: function (e) {
|
|
533
|
+
var _a;
|
|
534
|
+
return onChange(__assign(__assign({}, value), { city: (_a = e.target.value) !== null && _a !== void 0 ? _a : '' }), field.id);
|
|
535
|
+
} })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: field.fullZIP ? 4 : 6, sm: field.fullZIP ? 2 : 3 }, { children: (0, jsx_runtime_1.jsx)(material_1.Autocomplete, __assign({ value: (value === null || value === void 0 ? void 0 : value.state) || '', fullWidth: true, options: ((_l = (_k = field.options) === null || _k === void 0 ? void 0 : _k.validStates) === null || _l === void 0 ? void 0 : _l.length) ? field.options.validStates : validation_1.VALID_STATES, disablePortal: true, onChange: function (e, v) { return v &&
|
|
536
|
+
onChange(__assign(__assign({}, value), { state: v !== null && v !== void 0 ? v : '' }), field.id); }, renderInput: function (params) { return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: exports.defaultInputProps.sx }), size: 'small', required: !field.isOptional, label: (0, __1.form_display_text_for_language)(form, "State") }))); } }, props)) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: field.fullZIP ? 5 : 6, sm: field.fullZIP ? 2 : 3 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, props, { size: "small", required: !field.isOptional, InputProps: exports.defaultInputProps, fullWidth: true, value: (_m = value === null || value === void 0 ? void 0 : value.zipCode) !== null && _m !== void 0 ? _m : '', label: (0, __1.form_display_text_for_language)(form, "ZIP Code"), placeholder: (0, __1.form_display_text_for_language)(form, "ZIP Code"), onChange: function (e) {
|
|
537
|
+
var _a;
|
|
538
|
+
return onChange(__assign(__assign({}, value), { zipCode: (_a = e.target.value) !== null && _a !== void 0 ? _a : '' }), field.id);
|
|
539
|
+
} })) })), field.fullZIP &&
|
|
540
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 3 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, props, { size: "small", label: "ZIP+4", required: !field.isOptional && field.fullZIP, InputProps: exports.defaultInputProps, value: (_o = value === null || value === void 0 ? void 0 : value.zipPlusFour) !== null && _o !== void 0 ? _o : '', placeholder: "ZIP + 4", onChange: function (e) {
|
|
541
|
+
var _a;
|
|
542
|
+
return onChange(__assign(__assign({}, value), { zipPlusFour: (_a = e.target.value) !== null && _a !== void 0 ? _a : '' }), field.id);
|
|
543
|
+
} })) }))] })) }))] }))));
|
|
544
|
+
};
|
|
545
|
+
exports.AddressInput = AddressInput;
|
|
546
|
+
var ESignatureTerms = function () {
|
|
547
|
+
var companyName = 'Tellescope';
|
|
548
|
+
try {
|
|
549
|
+
var indexOfName = window.location.href.indexOf('name=');
|
|
550
|
+
if (indexOfName !== -1) {
|
|
551
|
+
companyName = (decodeURIComponent(window.location.href.substring(indexOfName + 5))
|
|
552
|
+
|| companyName);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
catch (err) {
|
|
556
|
+
console.error(err);
|
|
557
|
+
}
|
|
558
|
+
return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: { paddingLeft: 10 } }, { children: [(0, jsx_runtime_1.jsxs)("h1", { children: [companyName, " Electronic Signature Terms"] }), (0, jsx_runtime_1.jsxs)("p", { children: ["By selecting the \"I consent to use electronic signatures\" checkbox, you are signing this Agreement electronically. You agree your electronic signature is the legal equivalent of your manual/handwritten signature on this Agreement. By selecting \"I consent to use electronic signatures\" using any device, means or action, you consent to the legally binding terms and conditions of this Agreement. You further agree that your signature on this document (hereafter referred to as your \"E-Signature\") is as valid as if you signed the document in writing. You also agree that no certification authority or other third party verification is necessary to validate your E-Signature, and that the lack of such certification or third party verification will not in any way affect the enforceability of your E-Signature or any resulting agreement between you and", companyName, " or between you and a customer of ", companyName, "."] })] })));
|
|
559
|
+
};
|
|
560
|
+
exports.ESignatureTerms = ESignatureTerms;
|
|
561
|
+
var SignatureInput = function (_a) {
|
|
562
|
+
var _b, _d, _e, _f, _g;
|
|
563
|
+
var value = _a.value, field = _a.field, _h = _a.autoFocus, autoFocus = _h === void 0 ? true : _h, enduser = _a.enduser, onChange = _a.onChange;
|
|
564
|
+
var prefill = (((_b = field.options) === null || _b === void 0 ? void 0 : _b.prefillSignature) && (enduser === null || enduser === void 0 ? void 0 : enduser.fname) && enduser.lname
|
|
565
|
+
? "".concat(enduser.fname, " ").concat(enduser.lname)
|
|
566
|
+
: undefined);
|
|
567
|
+
var handleConsentChange = function () {
|
|
568
|
+
var _a, _b, _d, _e;
|
|
569
|
+
var newConsent = !(value === null || value === void 0 ? void 0 : value.signed);
|
|
570
|
+
onChange({
|
|
571
|
+
pdfAttachment: (_a = field.options) === null || _a === void 0 ? void 0 : _a.pdfAttachment,
|
|
572
|
+
fullName: (_d = (_b = value === null || value === void 0 ? void 0 : value.fullName) !== null && _b !== void 0 ? _b : prefill) !== null && _d !== void 0 ? _d : '',
|
|
573
|
+
signed: newConsent,
|
|
574
|
+
url: (_e = field.options) === null || _e === void 0 ? void 0 : _e.signatureUrl,
|
|
575
|
+
}, field.id);
|
|
576
|
+
};
|
|
577
|
+
var handleNameChange = function (newName) {
|
|
578
|
+
var _a, _b, _d;
|
|
579
|
+
onChange({
|
|
580
|
+
pdfAttachment: (_a = field.options) === null || _a === void 0 ? void 0 : _a.pdfAttachment,
|
|
581
|
+
signed: (_b = value === null || value === void 0 ? void 0 : value.signed) !== null && _b !== void 0 ? _b : false,
|
|
582
|
+
fullName: newName,
|
|
583
|
+
url: (_d = field.options) === null || _d === void 0 ? void 0 : _d.signatureUrl,
|
|
584
|
+
}, field.id);
|
|
585
|
+
};
|
|
586
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center" }, { children: [((_d = field.options) === null || _d === void 0 ? void 0 : _d.pdfAttachment) &&
|
|
587
|
+
(0, jsx_runtime_1.jsx)(exports.PdfViewer, { url: (0, utilities_1.getPublicFileURL)({ businessId: field.businessId, name: field.options.pdfAttachment }) }), !((_e = field.options) === null || _e === void 0 ? void 0 : _e.pdfAttachment) && ((_f = field.options) === null || _f === void 0 ? void 0 : _f.signatureUrl) &&
|
|
588
|
+
(0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", sx: { mb: 2 } }, { children: [(0, jsx_runtime_1.jsx)("iframe", { src: field.options.signatureUrl, style: {
|
|
589
|
+
border: 'none',
|
|
590
|
+
height: 400,
|
|
591
|
+
width: '100%',
|
|
592
|
+
marginBottom: '5px'
|
|
593
|
+
} }), (0, jsx_runtime_1.jsx)("a", __assign({ href: field.options.signatureUrl, target: "_blank", rel: "noopener noreferrer" }, { children: "View document in new tab" }))] })), (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Checkbox, { style: { margin: 0, marginTop: 5, padding: 0, paddingRight: 3 }, color: "primary", checked: !!(value === null || value === void 0 ? void 0 : value.signed), onClick: function () { return handleConsentChange(); }, inputProps: { 'aria-label': 'consent to e-signature checkbox' } }), (0, jsx_runtime_1.jsxs)(material_1.Typography, __assign({ component: "span", style: { position: 'relative', top: 5, left: 2 } }, { children: ["I consent to use ", (0, jsx_runtime_1.jsx)("a", __assign({ href: "/e-signature-terms?name=".concat(((_g = field.options) === null || _g === void 0 ? void 0 : _g.esignatureTermsCompanyName) || ''), target: "_blank", rel: "noopener noreferrer" }, { children: " electronic signatures " }))] }))] })), (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ item: true, xs: 12, style: { marginTop: 12 } }, { children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { disabled: !(value === null || value === void 0 ? void 0 : value.signed), autoFocus: autoFocus, style: { width: '100%' }, size: "small", "aria-label": "Full Name", value: value === null || value === void 0 ? void 0 : value.fullName, placeholder: prefill || "Full Name", variant: "outlined", onChange: function (e) { return handleNameChange(e.target.value); }, InputProps: exports.defaultInputProps }), (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "primary", style: { fontSize: 15, marginTop: 2 } }, { children: "Enter your legal full name to complete the signature" }))] }))] })));
|
|
594
|
+
};
|
|
595
|
+
exports.SignatureInput = SignatureInput;
|
|
596
|
+
var formatBytes = function (bytes) {
|
|
597
|
+
if (bytes === 0)
|
|
598
|
+
return '0 Bytes';
|
|
599
|
+
var k = 1024;
|
|
600
|
+
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
601
|
+
var i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
602
|
+
return "".concat(parseFloat((bytes / Math.pow(k, i)).toFixed(2)), " ").concat(sizes[i]);
|
|
603
|
+
};
|
|
604
|
+
function convertHEIC(file) {
|
|
605
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
606
|
+
var blobURL, blobRes, blob, conversionResult, url;
|
|
607
|
+
return __generator(this, function (_a) {
|
|
608
|
+
switch (_a.label) {
|
|
609
|
+
case 0:
|
|
610
|
+
blobURL = (typeof file === 'string' ? file : URL.createObjectURL(file));
|
|
611
|
+
return [4 /*yield*/, fetch(blobURL)
|
|
612
|
+
// convert response to blob
|
|
613
|
+
];
|
|
614
|
+
case 1:
|
|
615
|
+
blobRes = _a.sent();
|
|
616
|
+
return [4 /*yield*/, blobRes.blob()
|
|
617
|
+
// convert to PNG - response is blob
|
|
618
|
+
];
|
|
619
|
+
case 2:
|
|
620
|
+
blob = _a.sent();
|
|
621
|
+
return [4 /*yield*/, (0, heic2any_1.default)({ blob: blob })
|
|
622
|
+
// convert to blob url
|
|
623
|
+
];
|
|
624
|
+
case 3:
|
|
625
|
+
conversionResult = _a.sent();
|
|
626
|
+
url = URL.createObjectURL(Array.isArray(conversionResult) ? conversionResult[0] : conversionResult);
|
|
627
|
+
return [2 /*return*/, url];
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
exports.convertHEIC = convertHEIC;
|
|
633
|
+
;
|
|
634
|
+
var value_is_image = function (f) { var _a; return (_a = f === null || f === void 0 ? void 0 : f.type) === null || _a === void 0 ? void 0 : _a.includes('image'); };
|
|
635
|
+
var FileInput = function (_a) {
|
|
636
|
+
var _b;
|
|
637
|
+
var value = _a.value, onChange = _a.onChange, field = _a.field, existingFileName = _a.existingFileName, uploadingFiles = _a.uploadingFiles, handleFileUpload = _a.handleFileUpload, setUploadingFiles = _a.setUploadingFiles;
|
|
638
|
+
var _d = (0, react_1.useState)(''), error = _d[0], setError = _d[1];
|
|
639
|
+
var _e = (0, react_dropzone_1.useDropzone)({
|
|
640
|
+
onDrop: (0, react_1.useCallback)(function (acceptedFiles) {
|
|
641
|
+
var _a, _b, _d, _e;
|
|
642
|
+
var file = acceptedFiles.pop();
|
|
643
|
+
if (!file)
|
|
644
|
+
return;
|
|
645
|
+
if (((_a = field.options) === null || _a === void 0 ? void 0 : _a.maxFileSize) && file.size > field.options.maxFileSize) {
|
|
646
|
+
return setError("File size must be less than ".concat(formatBytes(field.options.maxFileSize)));
|
|
647
|
+
}
|
|
648
|
+
if ((_d = (_b = field.options) === null || _b === void 0 ? void 0 : _b.validFileTypes) === null || _d === void 0 ? void 0 : _d.length) {
|
|
649
|
+
var match = field.options.validFileTypes.find(function (t) { return file.type.includes(t.toLowerCase()); });
|
|
650
|
+
if (!match) {
|
|
651
|
+
return setError("File must have type: ".concat(field.options.validFileTypes.join(', ')));
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
setError('');
|
|
655
|
+
onChange(file, field.id);
|
|
656
|
+
if (((_e = field.options) === null || _e === void 0 ? void 0 : _e.autoUploadFiles) && handleFileUpload) {
|
|
657
|
+
setUploadingFiles === null || setUploadingFiles === void 0 ? void 0 : setUploadingFiles(function (fs) { return __spreadArray(__spreadArray([], fs, true), [{ fieldId: field.id }], false); });
|
|
658
|
+
handleFileUpload(file, field.id)
|
|
659
|
+
.finally(function () { return setUploadingFiles === null || setUploadingFiles === void 0 ? void 0 : setUploadingFiles(function (fs) { return fs.filter(function (f) { return f.fieldId !== field.id; }); }); });
|
|
660
|
+
}
|
|
661
|
+
}, [onChange, (_b = field.options) === null || _b === void 0 ? void 0 : _b.validFileTypes, handleFileUpload, setUploadingFiles]),
|
|
662
|
+
}), getRootProps = _e.getRootProps, getInputProps = _e.getInputProps, isDragActive = _e.isDragActive;
|
|
663
|
+
var _f = (0, react_1.useState)(''), preview = _f[0], setPreview = _f[1];
|
|
664
|
+
(0, react_1.useEffect)(function () {
|
|
665
|
+
if (!value_is_image(value))
|
|
666
|
+
return;
|
|
667
|
+
if ((value.type.includes('heif') || value.type.includes('heic'))) {
|
|
668
|
+
convertHEIC(value).then(setPreview).catch(console.error);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
try {
|
|
672
|
+
setPreview(URL.createObjectURL(value));
|
|
673
|
+
}
|
|
674
|
+
catch (err) {
|
|
675
|
+
console.error(err);
|
|
676
|
+
}
|
|
677
|
+
}, [value]);
|
|
678
|
+
if (uploadingFiles === null || uploadingFiles === void 0 ? void 0 : uploadingFiles.find(function (f) { return f.fieldId === field.id; })) {
|
|
679
|
+
return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
|
|
680
|
+
}
|
|
681
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column" }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true }, getRootProps(), { sx: {
|
|
682
|
+
width: "100%",
|
|
683
|
+
border: "1px dashed #00000033",
|
|
684
|
+
borderRadius: 1,
|
|
685
|
+
padding: (preview && !isDragActive) ? 0 : 6,
|
|
686
|
+
'&:hover': {
|
|
687
|
+
border: "1px solid ".concat(constants_1.PRIMARY_HEX),
|
|
688
|
+
cursor: 'pointer',
|
|
689
|
+
}
|
|
690
|
+
}, alignItems: "center", justifyContent: "center" }, { children: [(0, jsx_runtime_1.jsx)("input", __assign({}, getInputProps({ multiple: false }))), (0, jsx_runtime_1.jsx)("p", { children: value
|
|
691
|
+
? (preview
|
|
692
|
+
? (0, jsx_runtime_1.jsx)("img", { src: preview, style: { paddingLeft: '10%', width: '80%', maxHeight: 200 } })
|
|
693
|
+
: "".concat((0, utilities_1.truncate_string)(value.name, { length: 30, showEllipsis: true }), " selected!"))
|
|
694
|
+
: (0, utilities_1.capture_is_supported)()
|
|
695
|
+
? ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(AddPhotoAlternate_1.default, { color: "primary" }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ sx: { fontSize: 14, textAlign: 'center' } }, { children: "Select file or take picture" })) }))] })))
|
|
696
|
+
: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", alignItems: "center", rowGap: 2 }, { children: [(0, jsx_runtime_1.jsx)(icons_material_1.UploadFile, { color: "primary", sx: { fontSize: 25 } }), (0, jsx_runtime_1.jsx)(material_1.Typography, { children: isDragActive ? "Drop to select file" : "Click or drag and drop" })] })) })] })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, alignSelf: "center", sx: { mt: 0.5 } }, { children: (!(value === null || value === void 0 ? void 0 : value.name) && existingFileName) &&
|
|
697
|
+
(0, jsx_runtime_1.jsxs)(material_1.Typography, { children: [existingFileName, " selected!"] }) })), error &&
|
|
698
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, alignSelf: "center", sx: { mt: 0.5 } }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error" }, { children: error })) }))] })));
|
|
699
|
+
};
|
|
700
|
+
exports.FileInput = FileInput;
|
|
701
|
+
var safe_create_url = function (file) {
|
|
702
|
+
try {
|
|
703
|
+
return URL.createObjectURL(file);
|
|
704
|
+
}
|
|
705
|
+
catch (err) {
|
|
706
|
+
console.error('safe_create_url error:', err);
|
|
707
|
+
return null;
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
exports.safe_create_url = safe_create_url;
|
|
711
|
+
var FilesInput = function (_a) {
|
|
712
|
+
var _b;
|
|
713
|
+
var value = _a.value, onChange = _a.onChange, field = _a.field, existingFileName = _a.existingFileName, uploadingFiles = _a.uploadingFiles, handleFileUpload = _a.handleFileUpload, setUploadingFiles = _a.setUploadingFiles;
|
|
714
|
+
var _d = (0, react_1.useState)(''), error = _d[0], setError = _d[1];
|
|
715
|
+
var _e = (0, react_dropzone_1.useDropzone)({
|
|
716
|
+
onDrop: (0, react_1.useCallback)(function (acceptedFiles) { return __awaiter(void 0, void 0, void 0, function () {
|
|
717
|
+
var _loop_1, _a, acceptedFiles_1, file, state_1;
|
|
718
|
+
var _b, _d, _e;
|
|
719
|
+
return __generator(this, function (_f) {
|
|
720
|
+
switch (_f.label) {
|
|
721
|
+
case 0:
|
|
722
|
+
setUploadingFiles === null || setUploadingFiles === void 0 ? void 0 : setUploadingFiles(function (fs) { return __spreadArray(__spreadArray([], fs, true), [{ fieldId: field.id }], false); });
|
|
723
|
+
_loop_1 = function (file) {
|
|
724
|
+
var match;
|
|
725
|
+
return __generator(this, function (_g) {
|
|
726
|
+
switch (_g.label) {
|
|
727
|
+
case 0:
|
|
728
|
+
if ((_d = (_b = field.options) === null || _b === void 0 ? void 0 : _b.validFileTypes) === null || _d === void 0 ? void 0 : _d.length) {
|
|
729
|
+
match = field.options.validFileTypes.find(function (t) { return file.type.includes(t.toLowerCase()); });
|
|
730
|
+
if (!match) {
|
|
731
|
+
return [2 /*return*/, { value: setError("File must have type: ".concat(field.options.validFileTypes.join(', '))) }];
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (!(((_e = field.options) === null || _e === void 0 ? void 0 : _e.autoUploadFiles) && handleFileUpload)) return [3 /*break*/, 2];
|
|
735
|
+
return [4 /*yield*/, handleFileUpload(file, field.id).catch(console.error)];
|
|
736
|
+
case 1:
|
|
737
|
+
_g.sent();
|
|
738
|
+
_g.label = 2;
|
|
739
|
+
case 2: return [2 /*return*/];
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
};
|
|
743
|
+
_a = 0, acceptedFiles_1 = acceptedFiles;
|
|
744
|
+
_f.label = 1;
|
|
745
|
+
case 1:
|
|
746
|
+
if (!(_a < acceptedFiles_1.length)) return [3 /*break*/, 4];
|
|
747
|
+
file = acceptedFiles_1[_a];
|
|
748
|
+
return [5 /*yield**/, _loop_1(file)];
|
|
749
|
+
case 2:
|
|
750
|
+
state_1 = _f.sent();
|
|
751
|
+
if (typeof state_1 === "object")
|
|
752
|
+
return [2 /*return*/, state_1.value];
|
|
753
|
+
_f.label = 3;
|
|
754
|
+
case 3:
|
|
755
|
+
_a++;
|
|
756
|
+
return [3 /*break*/, 1];
|
|
757
|
+
case 4:
|
|
758
|
+
setUploadingFiles === null || setUploadingFiles === void 0 ? void 0 : setUploadingFiles(function (fs) { return fs.filter(function (f) { return f.fieldId !== field.id; }); });
|
|
759
|
+
setError('');
|
|
760
|
+
onChange(__spreadArray(__spreadArray([], (value !== null && value !== void 0 ? value : []), true), acceptedFiles, true), field.id);
|
|
761
|
+
return [2 /*return*/];
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
}); }, [onChange, value, (_b = field.options) === null || _b === void 0 ? void 0 : _b.validFileTypes, handleFileUpload, setUploadingFiles]),
|
|
765
|
+
}), getRootProps = _e.getRootProps, getInputProps = _e.getInputProps, isDragActive = _e.isDragActive;
|
|
766
|
+
var previews = (0, react_1.useMemo)(function () { return ((value !== null && value !== void 0 ? value : []).map(function (v) {
|
|
767
|
+
return value_is_image(v) ? (0, exports.safe_create_url)(v) : null;
|
|
768
|
+
})); }, [value]);
|
|
769
|
+
if (uploadingFiles === null || uploadingFiles === void 0 ? void 0 : uploadingFiles.find(function (f) { return f.fieldId === field.id; })) {
|
|
770
|
+
return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
|
|
771
|
+
}
|
|
772
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column" }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true }, getRootProps(), { sx: {
|
|
773
|
+
width: "100%",
|
|
774
|
+
border: "1px dashed #00000033",
|
|
775
|
+
borderRadius: 1,
|
|
776
|
+
padding: 2,
|
|
777
|
+
'&:hover': {
|
|
778
|
+
border: "1px solid ".concat(constants_1.PRIMARY_HEX),
|
|
779
|
+
cursor: 'pointer',
|
|
780
|
+
}
|
|
781
|
+
}, alignItems: "center", justifyContent: "center" }, { children: [(0, jsx_runtime_1.jsx)("input", __assign({}, getInputProps({ multiple: false }))), (0, jsx_runtime_1.jsx)("p", { children: (0, utilities_1.capture_is_supported)()
|
|
782
|
+
? ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(AddPhotoAlternate_1.default, { color: "primary" }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ sx: { fontSize: 14, textAlign: 'center' } }, { children: "Select files or take pictures" })) }))] })))
|
|
783
|
+
: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", alignItems: "center", rowGap: 2 }, { children: [(0, jsx_runtime_1.jsx)(icons_material_1.UploadFile, { color: "primary", sx: { fontSize: 25 } }), (0, jsx_runtime_1.jsx)(material_1.Typography, { children: isDragActive ? "Drop to select files" : "Click or drag and drop" })] })) })] })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ container: true, direction: "column", sx: { overflowY: 'auto', maxHeight: '250px', mt: 1 }, wrap: "nowrap" }, { children: value === null || value === void 0 ? void 0 : value.map(function (file, i) {
|
|
784
|
+
var _a;
|
|
785
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { mt: 0.5 } }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", justifyContent: "space-between", wrap: "nowrap" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ sx: { mr: 1 } }, { children: file.name })), ((_a = file.type) === null || _a === void 0 ? void 0 : _a.includes('image')) && previews[i] &&
|
|
786
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)("img", { src: previews[i], style: { maxWidth: '45%', maxHeight: 80, height: '100%' } }) }))] })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(__1.LabeledIconButton, { label: "Remove", Icon: icons_material_1.Delete, onClick: function () { return onChange(value.filter(function (f, _i) { return i !== _i; }), field.id); } }) }))] })) }), i));
|
|
787
|
+
}) })), error &&
|
|
788
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, alignSelf: "center", sx: { mt: 0.5 } }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error" }, { children: error })) }))] })));
|
|
789
|
+
};
|
|
790
|
+
exports.FilesInput = FilesInput;
|
|
791
|
+
var MultipleChoiceInput = function (_a) {
|
|
792
|
+
var _b, _d, _e;
|
|
793
|
+
var field = _a.field, form = _a.form, _value = _a.value, onChange = _a.onChange;
|
|
794
|
+
var value = typeof _value === 'string' ? [_value] : _value; // if loading existingResponses, allows them to be a string
|
|
795
|
+
var _f = field.options, choices = _f.choices, radio = _f.radio, other = _f.other, optionDetails = _f.optionDetails;
|
|
796
|
+
var _g = (0, react_1.useState)({}), expandedDescriptions = _g[0], setExpandedDescriptions = _g[1];
|
|
797
|
+
// current other string
|
|
798
|
+
var enteringOtherStringRef = react_1.default.useRef(''); // if typing otherString as prefix of a checkbox value, don't auto-select
|
|
799
|
+
var otherString = (_b = value === null || value === void 0 ? void 0 : value.find(function (v) { var _a; return v === enteringOtherStringRef.current || !((_a = (choices !== null && choices !== void 0 ? choices : [])) === null || _a === void 0 ? void 0 : _a.find(function (c) { return c === v; })); })) !== null && _b !== void 0 ? _b : '';
|
|
800
|
+
// Get primary color from form customization or use default
|
|
801
|
+
var primaryColor = (_e = (_d = form === null || form === void 0 ? void 0 : form.customization) === null || _d === void 0 ? void 0 : _d.primaryColor) !== null && _e !== void 0 ? _e : '#798ED0';
|
|
802
|
+
var getDescriptionForChoice = (0, react_1.useCallback)(function (choice) {
|
|
803
|
+
var _a;
|
|
804
|
+
return (_a = optionDetails === null || optionDetails === void 0 ? void 0 : optionDetails.find(function (detail) { return detail.option === choice; })) === null || _a === void 0 ? void 0 : _a.description;
|
|
805
|
+
}, [optionDetails]);
|
|
806
|
+
var toggleDescription = (0, react_1.useCallback)(function (index) {
|
|
807
|
+
setExpandedDescriptions(function (prev) {
|
|
808
|
+
var _a;
|
|
809
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[index] = !prev[index], _a)));
|
|
810
|
+
});
|
|
811
|
+
}, []);
|
|
812
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", rowGap: 1.5 }, { children: [radio
|
|
813
|
+
? ((0, jsx_runtime_1.jsx)(material_1.FormControl, __assign({ fullWidth: true }, { children: (0, jsx_runtime_1.jsx)(material_1.RadioGroup, __assign({ "aria-labelledby": "radio-group-".concat(field.id, "-label"), defaultValue: "female", name: "radio-group-".concat(field.id) }, { children: (choices !== null && choices !== void 0 ? choices : []).map(function (c, i) {
|
|
814
|
+
var description = getDescriptionForChoice(c);
|
|
815
|
+
var hasDescription = !!description;
|
|
816
|
+
var isExpanded = expandedDescriptions[i];
|
|
817
|
+
var isSelected = !!(value === null || value === void 0 ? void 0 : value.includes(c)) && c !== otherString;
|
|
818
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: { width: '100%' } }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: {
|
|
819
|
+
display: 'flex',
|
|
820
|
+
alignItems: 'center',
|
|
821
|
+
width: '100%',
|
|
822
|
+
border: isSelected ? '2px solid' : '1px solid',
|
|
823
|
+
borderColor: 'primary.main',
|
|
824
|
+
borderRadius: 1,
|
|
825
|
+
padding: '16px 16px',
|
|
826
|
+
marginBottom: '12px',
|
|
827
|
+
cursor: 'pointer',
|
|
828
|
+
backgroundColor: 'transparent',
|
|
829
|
+
'&:hover': {
|
|
830
|
+
backgroundColor: function (theme) { return "".concat(theme.palette.primary.main, "14"); },
|
|
831
|
+
},
|
|
832
|
+
}, onClick: function () { return onChange((value === null || value === void 0 ? void 0 : value.includes(c)) ? [] : [c], field.id); } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ component: "span", sx: { flex: 1, color: 'primary.main', fontSize: 13, fontWeight: 600 } }, { children: c })), hasDescription && ((0, jsx_runtime_1.jsx)(material_1.IconButton, __assign({ className: "expand-button", size: "small", onClick: function (e) {
|
|
833
|
+
e.stopPropagation();
|
|
834
|
+
toggleDescription(i);
|
|
835
|
+
}, sx: {
|
|
836
|
+
transform: isExpanded ? 'rotate(180deg)' : 'rotate(0deg)',
|
|
837
|
+
transition: 'transform 0.2s',
|
|
838
|
+
ml: 1
|
|
839
|
+
} }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, { fontSize: "small" }) })))] })), hasDescription && ((0, jsx_runtime_1.jsx)(material_1.Collapse, __assign({ in: isExpanded }, { children: (0, jsx_runtime_1.jsx)(material_1.Box, __assign({ sx: { pl: 2, pr: 2, pb: 1, pt: 1 } }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "body2", color: "text.secondary" }, { children: description })) })) })))] }), i));
|
|
840
|
+
}) })) }))) : ((choices !== null && choices !== void 0 ? choices : []).map(function (c, i) {
|
|
841
|
+
var description = getDescriptionForChoice(c);
|
|
842
|
+
var hasDescription = !!description;
|
|
843
|
+
var isExpanded = expandedDescriptions[i];
|
|
844
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ xs: 12 }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: { width: '100%' } }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: {
|
|
845
|
+
display: 'flex',
|
|
846
|
+
alignItems: 'center',
|
|
847
|
+
cursor: 'pointer',
|
|
848
|
+
width: '100%'
|
|
849
|
+
}, onClick: function (e) {
|
|
850
|
+
var _a, _b, _d, _e;
|
|
851
|
+
// Don't trigger selection if clicking on the expand button
|
|
852
|
+
if (e.target.closest('.expand-button')) {
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
onChange(((value === null || value === void 0 ? void 0 : value.includes(c))
|
|
856
|
+
? ((radio || ((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.radioChoices) === null || _b === void 0 ? void 0 : _b.includes(c)))
|
|
857
|
+
? []
|
|
858
|
+
: value.filter(function (v) { return v !== c; }))
|
|
859
|
+
: ((radio || ((_e = (_d = field.options) === null || _d === void 0 ? void 0 : _d.radioChoices) === null || _e === void 0 ? void 0 : _e.includes(c)))
|
|
860
|
+
? [c]
|
|
861
|
+
: __spreadArray(__spreadArray([], (value !== null && value !== void 0 ? value : []).filter(function (x) { var _a, _b; return !((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.radioChoices) === null || _b === void 0 ? void 0 : _b.includes(x)); }), true), [c], false))), field.id);
|
|
862
|
+
} }, { children: [(0, jsx_runtime_1.jsx)(material_1.Checkbox, { color: "primary", checked: !!(value === null || value === void 0 ? void 0 : value.includes(c)) && c !== otherString, inputProps: { 'aria-label': 'primary checkbox' } }), (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ component: "span", sx: { flex: 1 } }, { children: c })), hasDescription && ((0, jsx_runtime_1.jsx)(material_1.IconButton, __assign({ className: "expand-button", size: "small", onClick: function (e) {
|
|
863
|
+
e.stopPropagation();
|
|
864
|
+
toggleDescription(i);
|
|
865
|
+
}, sx: {
|
|
866
|
+
transform: isExpanded ? 'rotate(180deg)' : 'rotate(0deg)',
|
|
867
|
+
transition: 'transform 0.2s',
|
|
868
|
+
ml: 1
|
|
869
|
+
} }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, { fontSize: "small" }) })))] })), hasDescription && ((0, jsx_runtime_1.jsx)(material_1.Collapse, __assign({ in: isExpanded }, { children: (0, jsx_runtime_1.jsx)(material_1.Box, __assign({ sx: { pl: '42px', pr: 2, pb: 1 } }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "body2", color: "text.secondary" }, { children: description })) })) })))] })) }), i));
|
|
870
|
+
})), other &&
|
|
871
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField // className={classes.textField}
|
|
872
|
+
, { InputProps: { sx: { borderRadius: 2.5 } }, sx: { width: radio ? "calc(100% - 15px)" : '100%' }, size: "small", "aria-label": (0, __1.form_display_text_for_language)(form, "Other"), value: otherString, placeholder: (0, __1.form_display_text_for_language)(form, "Other"), variant: "outlined",
|
|
873
|
+
// onClick={() => !otherChecked && handleOtherChecked()} // allow click to enable when disabled
|
|
874
|
+
onChange: function (e) {
|
|
875
|
+
enteringOtherStringRef.current = e.target.value;
|
|
876
|
+
onChange((radio
|
|
877
|
+
? (e.target.value.trim()
|
|
878
|
+
? [e.target.value]
|
|
879
|
+
: [])
|
|
880
|
+
: (e.target.value.trim()
|
|
881
|
+
// remove existing other string (if exists) and append new one
|
|
882
|
+
? __spreadArray(__spreadArray([], (value !== null && value !== void 0 ? value : []).filter(function (v) { return v !== otherString; }), true), [e.target.value], false) : value === null || value === void 0 ? void 0 : value.filter(function (v) { return v !== otherString; }))), field.id);
|
|
883
|
+
} }) }))] })));
|
|
884
|
+
};
|
|
885
|
+
exports.MultipleChoiceInput = MultipleChoiceInput;
|
|
886
|
+
var StripeInput = function (_a) {
|
|
887
|
+
var _b, _d;
|
|
888
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange, setCustomerId = _a.setCustomerId, enduserId = _a.enduserId;
|
|
889
|
+
var session = (0, __1.useResolvedSession)();
|
|
890
|
+
var _e = (0, react_1.useState)(''), clientSecret = _e[0], setClientSecret = _e[1];
|
|
891
|
+
var _f = (0, react_1.useState)(''), businessName = _f[0], setBusinessName = _f[1];
|
|
892
|
+
var _g = (0, react_1.useState)(false), isCheckout = _g[0], setIsCheckout = _g[1];
|
|
893
|
+
var _h = (0, react_1.useState)(), stripePromise = _h[0], setStripePromise = _h[1];
|
|
894
|
+
var _j = (0, react_1.useState)(''), answertext = _j[0], setAnswertext = _j[1];
|
|
895
|
+
var _k = (0, react_1.useState)(''), error = _k[0], setError = _k[1];
|
|
896
|
+
var _l = (0, react_1.useState)([]), selectedProducts = _l[0], setSelectedProducts = _l[1];
|
|
897
|
+
var _m = (0, react_1.useState)(false), showProductSelection = _m[0], setShowProductSelection = _m[1];
|
|
898
|
+
var _o = (0, react_1.useState)([]), availableProducts = _o[0], setAvailableProducts = _o[1];
|
|
899
|
+
var _p = (0, react_1.useState)(false), loadingProducts = _p[0], setLoadingProducts = _p[1];
|
|
900
|
+
var fetchRef = (0, react_1.useRef)(false);
|
|
901
|
+
(0, react_1.useEffect)(function () {
|
|
902
|
+
var _a, _b, _d;
|
|
903
|
+
if (fetchRef.current)
|
|
904
|
+
return;
|
|
905
|
+
if (value && ((_a = session.userInfo) === null || _a === void 0 ? void 0 : _a.stripeCustomerId)) {
|
|
906
|
+
return setCustomerId(function (c) { var _a; return c ? c : (_a = session.userInfo) === null || _a === void 0 ? void 0 : _a.stripeCustomerId; }); // already paid or saved card
|
|
907
|
+
}
|
|
908
|
+
// Check if product selection mode is enabled
|
|
909
|
+
if (((_b = field.options) === null || _b === void 0 ? void 0 : _b.stripeProductSelectionMode) && (((_d = field.options) === null || _d === void 0 ? void 0 : _d.productIds) || []).length > 1) {
|
|
910
|
+
setShowProductSelection(true);
|
|
911
|
+
setLoadingProducts(true);
|
|
912
|
+
// Fetch product data with real-time Stripe pricing via proxy_read
|
|
913
|
+
var productIds = (field.options.productIds || []).join(',');
|
|
914
|
+
session.api.integrations.proxy_read({
|
|
915
|
+
integration: 'Stripe',
|
|
916
|
+
type: 'product-prices',
|
|
917
|
+
id: productIds,
|
|
918
|
+
query: field.options.stripeKey
|
|
919
|
+
})
|
|
920
|
+
.then(function (_a) {
|
|
921
|
+
var data = _a.data;
|
|
922
|
+
setAvailableProducts(data.products || []);
|
|
923
|
+
setLoadingProducts(false);
|
|
924
|
+
})
|
|
925
|
+
.catch(function (e) {
|
|
926
|
+
var _a, _b;
|
|
927
|
+
console.error('Error loading product data:', e);
|
|
928
|
+
var errorMessage = ((_b = (_a = e === null || e === void 0 ? void 0 : e.message) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, 'Stripe pricing error:'))
|
|
929
|
+
? e.message.replace('Stripe pricing error: ', '')
|
|
930
|
+
: 'Failed to load product information from Stripe';
|
|
931
|
+
setError("Product configuration error: ".concat(errorMessage));
|
|
932
|
+
setLoadingProducts(false);
|
|
933
|
+
});
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
fetchRef.current = true;
|
|
937
|
+
session.api.form_responses.stripe_details({ fieldId: field.id, enduserId: enduserId })
|
|
938
|
+
.then(function (_a) {
|
|
939
|
+
var clientSecret = _a.clientSecret, publishableKey = _a.publishableKey, stripeAccount = _a.stripeAccount, businessName = _a.businessName, customerId = _a.customerId, isCheckout = _a.isCheckout, answerText = _a.answerText;
|
|
940
|
+
setAnswertext(answerText || '');
|
|
941
|
+
setIsCheckout(!!isCheckout);
|
|
942
|
+
setClientSecret(clientSecret);
|
|
943
|
+
setStripePromise((0, stripe_js_1.loadStripe)(publishableKey, { stripeAccount: stripeAccount }));
|
|
944
|
+
setBusinessName(businessName);
|
|
945
|
+
setCustomerId(customerId);
|
|
946
|
+
})
|
|
947
|
+
.catch(function (e) {
|
|
948
|
+
console.error(e);
|
|
949
|
+
if (typeof (e === null || e === void 0 ? void 0 : e.message) === 'string') {
|
|
950
|
+
setError(e.message);
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
}, [session, value, field.id, enduserId]);
|
|
954
|
+
var cost = (showProductSelection
|
|
955
|
+
? selectedProducts.reduce(function (total, productId) {
|
|
956
|
+
var _a;
|
|
957
|
+
var product = availableProducts.find(function (p) { return p._id === productId; });
|
|
958
|
+
if (product === null || product === void 0 ? void 0 : product.currentPrice) {
|
|
959
|
+
return total + (product.currentPrice.amount || 0);
|
|
960
|
+
}
|
|
961
|
+
return total + (((_a = product === null || product === void 0 ? void 0 : product.cost) === null || _a === void 0 ? void 0 : _a.amount) || 0);
|
|
962
|
+
}, 0)
|
|
963
|
+
: 0 // Will be calculated by existing Stripe flow when not in selection mode
|
|
964
|
+
);
|
|
965
|
+
// Handle product selection step
|
|
966
|
+
if (showProductSelection) {
|
|
967
|
+
if (error) {
|
|
968
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 2, alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error", variant: "h6" }, { children: "Product Configuration Error" })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error", sx: { textAlign: 'center' } }, { children: error })) }))] })));
|
|
969
|
+
}
|
|
970
|
+
if (loadingProducts) {
|
|
971
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 2, alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {}) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "Loading product information..." }) }))] })));
|
|
972
|
+
}
|
|
973
|
+
var isSingleSelection_1 = ((_b = field.options) === null || _b === void 0 ? void 0 : _b.radio) === true;
|
|
974
|
+
var handleProductSelection_1 = function (productId) {
|
|
975
|
+
if (isSingleSelection_1) {
|
|
976
|
+
setSelectedProducts([productId]);
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
setSelectedProducts(function (prev) {
|
|
980
|
+
return prev.includes(productId)
|
|
981
|
+
? prev.filter(function (id) { return id !== productId; })
|
|
982
|
+
: __spreadArray(__spreadArray([], prev, true), [productId], false);
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
var handleContinueToPayment = function () {
|
|
987
|
+
if (selectedProducts.length === 0)
|
|
988
|
+
return;
|
|
989
|
+
setShowProductSelection(false);
|
|
990
|
+
fetchRef.current = true;
|
|
991
|
+
// Now fetch Stripe details with selected products
|
|
992
|
+
session.api.form_responses.stripe_details(__assign({ fieldId: field.id, enduserId: enduserId }, (selectedProducts.length > 0 && { selectedProductIds: selectedProducts }) // Pass selected products to Stripe checkout
|
|
993
|
+
))
|
|
994
|
+
.then(function (_a) {
|
|
995
|
+
var clientSecret = _a.clientSecret, publishableKey = _a.publishableKey, stripeAccount = _a.stripeAccount, businessName = _a.businessName, customerId = _a.customerId, isCheckout = _a.isCheckout, answerText = _a.answerText;
|
|
996
|
+
setAnswertext(answerText || '');
|
|
997
|
+
setIsCheckout(!!isCheckout);
|
|
998
|
+
setClientSecret(clientSecret);
|
|
999
|
+
setStripePromise((0, stripe_js_1.loadStripe)(publishableKey, { stripeAccount: stripeAccount }));
|
|
1000
|
+
setBusinessName(businessName);
|
|
1001
|
+
setCustomerId(customerId);
|
|
1002
|
+
})
|
|
1003
|
+
.catch(function (e) {
|
|
1004
|
+
console.error(e);
|
|
1005
|
+
if (typeof (e === null || e === void 0 ? void 0 : e.message) === 'string') {
|
|
1006
|
+
setError(e.message);
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
};
|
|
1010
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 2 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Typography, __assign({ variant: "h6" }, { children: ["Select Product", isSingleSelection_1 ? '' : 's'] })) })), availableProducts.map(function (product) {
|
|
1011
|
+
var _a;
|
|
1012
|
+
// Use real-time Stripe pricing if available, fallback to Tellescope pricing
|
|
1013
|
+
var price = product.currentPrice || product.cost;
|
|
1014
|
+
var priceAmount = (price === null || price === void 0 ? void 0 : price.amount) || 0;
|
|
1015
|
+
var priceCurrency = (price === null || price === void 0 ? void 0 : price.currency) || 'USD';
|
|
1016
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { control: isSingleSelection_1 ? ((0, jsx_runtime_1.jsx)(material_1.Radio, { checked: selectedProducts.includes(product._id), onChange: function () { return handleProductSelection_1(product._id); } })) : ((0, jsx_runtime_1.jsx)(material_1.Checkbox, { checked: selectedProducts.includes(product._id), onChange: function () { return handleProductSelection_1(product._id); } })), label: (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "body1", fontWeight: "bold" }, { children: product.title })), product.description && ((0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "body2", color: "textSecondary" }, { children: product.description }))), (0, jsx_runtime_1.jsxs)(material_1.Typography, __assign({ variant: "body2", color: "primary" }, { children: ["$", (priceAmount / 100).toFixed(2), " ", priceCurrency.toUpperCase(), ((_a = product.currentPrice) === null || _a === void 0 ? void 0 : _a.isSubscription) && ((0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ component: "span", variant: "caption", sx: { ml: 0.5 } }, { children: "/month" })))] }))] }) }) }), product._id));
|
|
1017
|
+
}), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ variant: "contained", onClick: handleContinueToPayment, disabled: selectedProducts.length === 0, sx: { mt: 2 } }, { children: "Continue to Payment" })) }))] })));
|
|
1018
|
+
}
|
|
1019
|
+
if (error) {
|
|
1020
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error" }, { children: error })));
|
|
1021
|
+
}
|
|
1022
|
+
if (value) {
|
|
1023
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap" }, { children: [(0, jsx_runtime_1.jsx)(icons_material_1.CheckCircleOutline, { color: "success" }), (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ sx: { ml: 1, fontSize: 20 } }, { children: ((_d = field.options) === null || _d === void 0 ? void 0 : _d.chargeImmediately) ? 'Your purchase was successful' : "Your payment details have been saved!" }))] })));
|
|
1024
|
+
}
|
|
1025
|
+
if (!(clientSecret && stripePromise))
|
|
1026
|
+
return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
|
|
1027
|
+
if (isCheckout && stripePromise)
|
|
1028
|
+
return ((0, jsx_runtime_1.jsx)(react_stripe_js_1.EmbeddedCheckoutProvider, __assign({ stripe: stripePromise, options: {
|
|
1029
|
+
clientSecret: clientSecret,
|
|
1030
|
+
onComplete: function () { return onChange(answertext || 'Completed checkout', field.id); },
|
|
1031
|
+
} }, { children: (0, jsx_runtime_1.jsx)(react_stripe_js_1.EmbeddedCheckout, {}) })));
|
|
1032
|
+
return ((0, jsx_runtime_1.jsx)(react_stripe_js_1.Elements, __assign({ stripe: stripePromise, options: {
|
|
1033
|
+
clientSecret: clientSecret,
|
|
1034
|
+
} }, { children: (0, jsx_runtime_1.jsx)(StripeForm, { businessName: businessName, onSuccess: function () { return onChange(answertext || 'Saved card details', field.id); }, cost: cost, field: field }) })));
|
|
1035
|
+
};
|
|
1036
|
+
exports.StripeInput = StripeInput;
|
|
1037
|
+
var StripeForm = function (_a) {
|
|
1038
|
+
var _b, _d, _e;
|
|
1039
|
+
var businessName = _a.businessName, onSuccess = _a.onSuccess, field = _a.field, cost = _a.cost;
|
|
1040
|
+
var stripe = (0, react_stripe_js_1.useStripe)();
|
|
1041
|
+
var elements = (0, react_stripe_js_1.useElements)();
|
|
1042
|
+
var _f = (0, react_1.useState)(false), ready = _f[0], setReady = _f[1];
|
|
1043
|
+
var _g = (0, react_1.useState)(''), errorMessage = _g[0], setErrorMessage = _g[1];
|
|
1044
|
+
var handleSubmit = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1045
|
+
var error;
|
|
1046
|
+
var _a, _b;
|
|
1047
|
+
return __generator(this, function (_d) {
|
|
1048
|
+
switch (_d.label) {
|
|
1049
|
+
case 0:
|
|
1050
|
+
// We don't want to let default form submission happen here,
|
|
1051
|
+
// which would refresh the page.
|
|
1052
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
1053
|
+
if (!stripe || !elements) {
|
|
1054
|
+
// Stripe.js hasn't yet loaded.
|
|
1055
|
+
// Make sure to disable form submission until Stripe.js has loaded.
|
|
1056
|
+
return [2 /*return*/, null];
|
|
1057
|
+
}
|
|
1058
|
+
return [4 /*yield*/, (((_a = field.options) === null || _a === void 0 ? void 0 : _a.chargeImmediately) ? stripe.confirmPayment : stripe.confirmSetup)({
|
|
1059
|
+
//`Elements` instance that was used to create the Payment Element
|
|
1060
|
+
elements: elements,
|
|
1061
|
+
confirmParams: {
|
|
1062
|
+
return_url: window.location.href,
|
|
1063
|
+
},
|
|
1064
|
+
redirect: 'if_required', // ensures the redirect url won't be used, unless the Bank redirect payment type is enabled (it's not, just card)
|
|
1065
|
+
})];
|
|
1066
|
+
case 1:
|
|
1067
|
+
error = (_d.sent()).error;
|
|
1068
|
+
if (error) {
|
|
1069
|
+
// This point will only be reached if there is an immediate error when
|
|
1070
|
+
// confirming the payment. Show error to your customer (for example, payment
|
|
1071
|
+
// details incomplete)
|
|
1072
|
+
setErrorMessage((_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : '');
|
|
1073
|
+
}
|
|
1074
|
+
else {
|
|
1075
|
+
onSuccess();
|
|
1076
|
+
// Your customer will be redirected to your `return_url`. For some payment
|
|
1077
|
+
// methods like iDEAL, your customer will be redirected to an intermediate
|
|
1078
|
+
// site first to authorize the payment, then redirected to the `return_url`.
|
|
1079
|
+
}
|
|
1080
|
+
return [2 /*return*/];
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
}); };
|
|
1084
|
+
return ((0, jsx_runtime_1.jsxs)("form", __assign({ onSubmit: handleSubmit }, { children: [(0, jsx_runtime_1.jsx)(react_stripe_js_1.PaymentElement, { onReady: function () { return setReady(true); }, options: {
|
|
1085
|
+
business: { name: businessName },
|
|
1086
|
+
} }), (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ variant: "contained", color: "primary", type: "submit", sx: { mt: 1 }, disabled: !(stripe && ready) }, { children: ((_b = field.options) === null || _b === void 0 ? void 0 : _b.chargeImmediately) ? 'Make Payment' : 'Save Payment Details' })), cost > 0 &&
|
|
1087
|
+
(0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ sx: { mt: 0.5 } }, { children: ((_d = field.options) === null || _d === void 0 ? void 0 : _d.customPriceMessage)
|
|
1088
|
+
? field.options.customPriceMessage.replaceAll('{{PRICE}}', "$".concat((cost / 100).toFixed(2)))
|
|
1089
|
+
: "You will be charged $".concat((cost / 100).toFixed(2), " ").concat(((_e = field.options) === null || _e === void 0 ? void 0 : _e.chargeImmediately) ? '' : 'on form submission') })), errorMessage &&
|
|
1090
|
+
(0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error", sx: { mt: 0.5 } }, { children: errorMessage }))] })));
|
|
1091
|
+
};
|
|
1092
|
+
var Progress = function (_a) {
|
|
1093
|
+
var numerator = _a.numerator, denominator = _a.denominator, style = _a.style, color = _a.color;
|
|
1094
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, __assign({ sx: __assign({ display: 'flex', alignItems: 'center' }, style) }, { children: (0, jsx_runtime_1.jsx)(material_1.Box, __assign({ sx: { width: '100%' } }, { children: (0, jsx_runtime_1.jsx)(LinearProgress_1.default, { variant: "determinate", value: (numerator / (denominator || 1)) * 100, sx: color ? {
|
|
1095
|
+
height: '16px',
|
|
1096
|
+
borderRadius: '8px',
|
|
1097
|
+
backgroundColor: "".concat(color, "20"),
|
|
1098
|
+
'& .MuiLinearProgress-bar': {
|
|
1099
|
+
backgroundColor: color,
|
|
1100
|
+
borderRadius: '8px',
|
|
1101
|
+
}
|
|
1102
|
+
} : {
|
|
1103
|
+
height: '16px',
|
|
1104
|
+
borderRadius: '8px',
|
|
1105
|
+
'& .MuiLinearProgress-bar': {
|
|
1106
|
+
borderRadius: '8px',
|
|
1107
|
+
}
|
|
1108
|
+
} }) })) })));
|
|
1109
|
+
};
|
|
1110
|
+
exports.Progress = Progress;
|
|
1111
|
+
var DropdownInput = function (_a) {
|
|
1112
|
+
var _b, _d, _e, _f, _g, _h, _j;
|
|
1113
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange;
|
|
1114
|
+
var _k = (0, react_1.useState)(''), typing = _k[0], setTyping = _k[1];
|
|
1115
|
+
// this should run only once, even if the field updates but the id is unchanged, otherwise will overwrite input
|
|
1116
|
+
var typingRef = (0, react_1.useRef)('');
|
|
1117
|
+
(0, react_1.useEffect)(function () {
|
|
1118
|
+
if (typingRef.current === field.id)
|
|
1119
|
+
return;
|
|
1120
|
+
typingRef.current = field.id;
|
|
1121
|
+
setTyping('');
|
|
1122
|
+
}, [field]);
|
|
1123
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Autocomplete, { id: field.id, style: { marginTop: 5 }, multiple: !((_b = field.options) === null || _b === void 0 ? void 0 : _b.radio), freeSolo: !!((_d = field.options) === null || _d === void 0 ? void 0 : _d.other), value: ((_e = field.options) === null || _e === void 0 ? void 0 : _e.radio)
|
|
1124
|
+
? ((_f = value === null || value === void 0 ? void 0 : value[0]) !== null && _f !== void 0 ? _f : '')
|
|
1125
|
+
: (value !== null && value !== void 0 ? value : []), onChange: function (_, v) { return (onChange((typeof v === 'string' || v === null) ? [v !== null && v !== void 0 ? v : ''] : v, field.id)); }, options: (_h = (_g = field.options) === null || _g === void 0 ? void 0 : _g.choices) !== null && _h !== void 0 ? _h : [], inputValue: ((_j = field.options) === null || _j === void 0 ? void 0 : _j.radio) && Array.isArray(value) && value[0]
|
|
1126
|
+
? value[0]
|
|
1127
|
+
: typing, onInputChange: function (e, value) { return setTyping(value); }, renderInput: function (params) {
|
|
1128
|
+
var _a, _b;
|
|
1129
|
+
return (0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: exports.defaultInputProps.sx }), onChange: function (e) {
|
|
1130
|
+
var _a;
|
|
1131
|
+
return ((((_a = field.options) === null || _a === void 0 ? void 0 : _a.radio) && field.options.other)
|
|
1132
|
+
? onChange(e.target.value ? [e.target.value] : [], field.id)
|
|
1133
|
+
: undefined);
|
|
1134
|
+
}, placeholder: field.placeholder
|
|
1135
|
+
? field.placeholder + ((!field.title && !field.isOptional) ? '*' : '')
|
|
1136
|
+
: undefined, label: (!((_a = field.options) === null || _a === void 0 ? void 0 : _a.radio) && ((_b = field.options) === null || _b === void 0 ? void 0 : _b.other))
|
|
1137
|
+
? "Press enter to save a custom value"
|
|
1138
|
+
: '' }));
|
|
1139
|
+
} }));
|
|
1140
|
+
};
|
|
1141
|
+
exports.DropdownInput = DropdownInput;
|
|
1142
|
+
var choicesForDatabase = {};
|
|
1143
|
+
var preventRefetch = {};
|
|
1144
|
+
var LOAD_CHOICES_LIMIT = 500;
|
|
1145
|
+
var useDatabaseChoices = function (_a) {
|
|
1146
|
+
var _b, _d, _e, _f;
|
|
1147
|
+
var _g = _a.databaseId, databaseId = _g === void 0 ? '' : _g, field = _a.field, otherAnswers = _a.otherAnswers;
|
|
1148
|
+
var session = (0, __1.useResolvedSession)();
|
|
1149
|
+
var _h = (0, react_1.useState)(0), renderCount = _h[0], setRenderCount = _h[1];
|
|
1150
|
+
// todo: make searchable, don't load all
|
|
1151
|
+
(0, react_1.useEffect)(function () {
|
|
1152
|
+
var _a, _b, _d, _e;
|
|
1153
|
+
if ((_a = choicesForDatabase[databaseId]) === null || _a === void 0 ? void 0 : _a.done)
|
|
1154
|
+
return;
|
|
1155
|
+
if (renderCount > 100)
|
|
1156
|
+
return; // limit to 50000 entries / prevent infinite looping
|
|
1157
|
+
var choices = (_d = (_b = choicesForDatabase[databaseId]) === null || _b === void 0 ? void 0 : _b.records) !== null && _d !== void 0 ? _d : [];
|
|
1158
|
+
var lastId = (_e = choicesForDatabase[databaseId]) === null || _e === void 0 ? void 0 : _e.lastId;
|
|
1159
|
+
if (preventRefetch[databaseId + field.id + lastId])
|
|
1160
|
+
return;
|
|
1161
|
+
preventRefetch[databaseId + field.id + lastId] = true;
|
|
1162
|
+
session.api.form_fields.load_choices_from_database({
|
|
1163
|
+
fieldId: field.id,
|
|
1164
|
+
lastId: lastId,
|
|
1165
|
+
limit: LOAD_CHOICES_LIMIT,
|
|
1166
|
+
databaseId: databaseId,
|
|
1167
|
+
})
|
|
1168
|
+
.then(function (_a) {
|
|
1169
|
+
var _b;
|
|
1170
|
+
var newChoices = _a.choices;
|
|
1171
|
+
choicesForDatabase[databaseId] = {
|
|
1172
|
+
lastId: (_b = newChoices === null || newChoices === void 0 ? void 0 : newChoices[newChoices.length - 1]) === null || _b === void 0 ? void 0 : _b.id,
|
|
1173
|
+
records: __spreadArray(__spreadArray([], choices, true), newChoices, true).sort(function (c1, c2) { return (label_for_database_record(field, c1)
|
|
1174
|
+
.localeCompare(label_for_database_record(field, c2))); }),
|
|
1175
|
+
done: newChoices.length < LOAD_CHOICES_LIMIT,
|
|
1176
|
+
};
|
|
1177
|
+
setRenderCount(function (r) { return r + 1; });
|
|
1178
|
+
})
|
|
1179
|
+
.catch(function (err) {
|
|
1180
|
+
console.error(err);
|
|
1181
|
+
preventRefetch[databaseId + field.id + lastId] = false;
|
|
1182
|
+
});
|
|
1183
|
+
}, [session, field, databaseId, renderCount]);
|
|
1184
|
+
var addChoice = (0, react_1.useCallback)(function (record) {
|
|
1185
|
+
if (!choicesForDatabase[databaseId]) {
|
|
1186
|
+
choicesForDatabase[databaseId] = {
|
|
1187
|
+
done: false,
|
|
1188
|
+
records: [],
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
choicesForDatabase[databaseId].records.push(record);
|
|
1192
|
+
}, [choicesForDatabase, databaseId]);
|
|
1193
|
+
return {
|
|
1194
|
+
addChoice: addChoice,
|
|
1195
|
+
doneLoading: (_d = (_b = choicesForDatabase[databaseId]) === null || _b === void 0 ? void 0 : _b.done) !== null && _d !== void 0 ? _d : false,
|
|
1196
|
+
choices: __spreadArray(__spreadArray([], (_f = (_e = choicesForDatabase[databaseId]) === null || _e === void 0 ? void 0 : _e.records) !== null && _f !== void 0 ? _f : [], true), (otherAnswers || []).map(function (v) {
|
|
1197
|
+
var _a;
|
|
1198
|
+
return ({
|
|
1199
|
+
id: v.text,
|
|
1200
|
+
databaseId: databaseId,
|
|
1201
|
+
values: [{ label: ((_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseLabel) || '', type: 'Text', value: v.text }],
|
|
1202
|
+
});
|
|
1203
|
+
}), true),
|
|
1204
|
+
renderCount: renderCount,
|
|
1205
|
+
};
|
|
1206
|
+
};
|
|
1207
|
+
var label_for_database_record = function (field, record) {
|
|
1208
|
+
var _a, _b, _d, _e;
|
|
1209
|
+
if (!record)
|
|
1210
|
+
return '';
|
|
1211
|
+
var addedLabels = ((((_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseLabels) || [])
|
|
1212
|
+
.map(function (l) { var _a, _b; return (_b = (_a = record.values.find(function (v) { return v.label === l; })) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.toString(); })
|
|
1213
|
+
.filter(function (v) { return v === null || v === void 0 ? void 0 : v.trim(); }));
|
|
1214
|
+
return (((_e = (_d = (_b = record.values.find(function (v) { var _a; return v.label === ((_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseLabel); })) === null || _b === void 0 ? void 0 : _b.value) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _e !== void 0 ? _e : '')
|
|
1215
|
+
+ (addedLabels.length
|
|
1216
|
+
? " (".concat(addedLabels.join(', '), ")")
|
|
1217
|
+
: ''));
|
|
1218
|
+
};
|
|
1219
|
+
var get_other_answers = function (_value, typing) {
|
|
1220
|
+
try {
|
|
1221
|
+
var existing = ((_value || [])
|
|
1222
|
+
.filter(function (v) { return typeof v === 'string' || v.recordId === v.text; })
|
|
1223
|
+
.map(function (v) { return typeof v === 'string' ? { databaseId: '', recordId: v, text: v } : v; }));
|
|
1224
|
+
if (typing) {
|
|
1225
|
+
existing.push({ text: typing, databaseId: '', recordId: typing });
|
|
1226
|
+
}
|
|
1227
|
+
return existing;
|
|
1228
|
+
}
|
|
1229
|
+
catch (err) {
|
|
1230
|
+
console.error(err);
|
|
1231
|
+
}
|
|
1232
|
+
return [];
|
|
1233
|
+
};
|
|
1234
|
+
var DatabaseSelectInput = function (_a) {
|
|
1235
|
+
var _b, _d, _e, _f, _g, _h, _j, _k;
|
|
1236
|
+
var AddToDatabase = _a.AddToDatabase, field = _a.field, _value = _a.value, onChange = _a.onChange, onDatabaseSelect = _a.onDatabaseSelect, responses = _a.responses, size = _a.size, disabled = _a.disabled, enduser = _a.enduser;
|
|
1237
|
+
var _l = (0, react_1.useState)(''), typing = _l[0], setTyping = _l[1];
|
|
1238
|
+
var _m = useDatabaseChoices({
|
|
1239
|
+
databaseId: (_b = field.options) === null || _b === void 0 ? void 0 : _b.databaseId,
|
|
1240
|
+
field: field,
|
|
1241
|
+
otherAnswers: get_other_answers(_value, ((_d = field === null || field === void 0 ? void 0 : field.options) === null || _d === void 0 ? void 0 : _d.other) ? typing : undefined),
|
|
1242
|
+
}), addChoice = _m.addChoice, choices = _m.choices, doneLoading = _m.doneLoading;
|
|
1243
|
+
var value = react_1.default.useMemo(function () {
|
|
1244
|
+
var _a, _b;
|
|
1245
|
+
try {
|
|
1246
|
+
// if the value is a string (some single answer that was save), make sure we coerce to array
|
|
1247
|
+
var __value = typeof _value === 'string' ? [_value] : _value;
|
|
1248
|
+
return ((_b = (_a = __value === null || __value === void 0 ? void 0 : __value.map(function (v) {
|
|
1249
|
+
return choices.find(function (c) {
|
|
1250
|
+
return c.id === v.recordId || (typeof v === 'string' && label_for_database_record(field, c) === v);
|
|
1251
|
+
});
|
|
1252
|
+
})) === null || _a === void 0 ? void 0 : _a.filter(function (v) { return v; })) !== null && _b !== void 0 ? _b : []);
|
|
1253
|
+
}
|
|
1254
|
+
catch (err) {
|
|
1255
|
+
console.error('Error resolving database answers for _value', err);
|
|
1256
|
+
return [];
|
|
1257
|
+
}
|
|
1258
|
+
}, [_value, choices, field]);
|
|
1259
|
+
var filterResponse = (0, react_1.useMemo)(function () {
|
|
1260
|
+
var _a, _b, _d, _e;
|
|
1261
|
+
return (((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseFilter) === null || _b === void 0 ? void 0 : _b.fieldId)
|
|
1262
|
+
? (_e = (_d = responses.find(function (r) { var _a, _b; return r.fieldId === ((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseFilter) === null || _b === void 0 ? void 0 : _b.fieldId); })) === null || _d === void 0 ? void 0 : _d.answer) === null || _e === void 0 ? void 0 : _e.value
|
|
1263
|
+
: undefined);
|
|
1264
|
+
}, [responses, (_e = field.options) === null || _e === void 0 ? void 0 : _e.databaseFilter]);
|
|
1265
|
+
// State filtering logic similar to Insurance component
|
|
1266
|
+
var addressQuestion = (0, react_1.useMemo)(function () { return responses === null || responses === void 0 ? void 0 : responses.find(function (r) {
|
|
1267
|
+
var _a;
|
|
1268
|
+
if (r.answer.type !== 'Address')
|
|
1269
|
+
return false;
|
|
1270
|
+
if (r.field.intakeField !== 'Address')
|
|
1271
|
+
return false;
|
|
1272
|
+
// make sure state is actually defined (in case of multiple address questions, where 1+ are blank)
|
|
1273
|
+
if (!((_a = r.answer.value) === null || _a === void 0 ? void 0 : _a.state))
|
|
1274
|
+
return false;
|
|
1275
|
+
return true;
|
|
1276
|
+
}); }, [responses]);
|
|
1277
|
+
var state = (0, react_1.useMemo)(function () {
|
|
1278
|
+
var _a, _b, _d, _e;
|
|
1279
|
+
return (((_a = field.options) === null || _a === void 0 ? void 0 : _a.filterByEnduserState)
|
|
1280
|
+
? ((((_b = addressQuestion === null || addressQuestion === void 0 ? void 0 : addressQuestion.answer) === null || _b === void 0 ? void 0 : _b.type) === 'Address' ? (_e = (_d = addressQuestion === null || addressQuestion === void 0 ? void 0 : addressQuestion.answer) === null || _d === void 0 ? void 0 : _d.value) === null || _e === void 0 ? void 0 : _e.state : undefined) || (enduser === null || enduser === void 0 ? void 0 : enduser.state))
|
|
1281
|
+
: undefined);
|
|
1282
|
+
}, [enduser === null || enduser === void 0 ? void 0 : enduser.state, addressQuestion, (_f = field.options) === null || _f === void 0 ? void 0 : _f.filterByEnduserState]);
|
|
1283
|
+
var filteredChoicesWithPotentialDuplicates = (0, react_1.useMemo)(function () {
|
|
1284
|
+
var _a, _b;
|
|
1285
|
+
if (!choices)
|
|
1286
|
+
return [];
|
|
1287
|
+
if (!filterResponse)
|
|
1288
|
+
return choices;
|
|
1289
|
+
if (!((_b = (_a = field === null || field === void 0 ? void 0 : field.options) === null || _a === void 0 ? void 0 : _a.databaseFilter) === null || _b === void 0 ? void 0 : _b.databaseLabel))
|
|
1290
|
+
if (!value || value.length === 0)
|
|
1291
|
+
return choices;
|
|
1292
|
+
return (choices
|
|
1293
|
+
.filter(function (c) {
|
|
1294
|
+
var _a;
|
|
1295
|
+
var v = (_a = c.values.find(function (_v) { var _a, _b; return _v.label === ((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseFilter) === null || _b === void 0 ? void 0 : _b.databaseLabel); })) === null || _a === void 0 ? void 0 : _a.value;
|
|
1296
|
+
if (!v)
|
|
1297
|
+
return true;
|
|
1298
|
+
// use .text on r values to handle Database Select types as filter source (in addition to basic text and list of text)
|
|
1299
|
+
if (typeof v === 'object') {
|
|
1300
|
+
return !!(Object.values(v).find(function (oVal) { return (typeof oVal === 'string' || typeof oVal === 'number'
|
|
1301
|
+
? (Array.isArray(filterResponse)
|
|
1302
|
+
? filterResponse.find(function (r) { return r === oVal.toString() || (typeof r === 'object' && r.text === oVal); })
|
|
1303
|
+
: (typeof filterResponse === 'string' || typeof filterResponse === 'number')
|
|
1304
|
+
? filterResponse.toString() === oVal.toString()
|
|
1305
|
+
: false)
|
|
1306
|
+
: false); }));
|
|
1307
|
+
}
|
|
1308
|
+
if (typeof v === 'string' || typeof v === 'number') {
|
|
1309
|
+
return !!(Array.isArray(filterResponse)
|
|
1310
|
+
? filterResponse.find(function (r) { return r === v.toString() || (typeof r === 'object' && r.text === v); })
|
|
1311
|
+
: (typeof filterResponse === 'string' || typeof filterResponse === 'number')
|
|
1312
|
+
? filterResponse.toString() === v.toString()
|
|
1313
|
+
: (typeof filterResponse === 'object' && filterResponse.city === v.toString()) ? true
|
|
1314
|
+
: (typeof filterResponse === 'object' && filterResponse.state === v.toString()) ? true
|
|
1315
|
+
: (typeof filterResponse === 'object' && filterResponse.zipCode === v.toString()) ? true
|
|
1316
|
+
: false);
|
|
1317
|
+
}
|
|
1318
|
+
return false;
|
|
1319
|
+
}));
|
|
1320
|
+
}, [choices, filterResponse, (_g = field.options) === null || _g === void 0 ? void 0 : _g.databaseFilter, value]);
|
|
1321
|
+
// Apply state filtering as a secondary filter (doesn't modify existing logic)
|
|
1322
|
+
var stateFilteredChoices = (0, react_1.useMemo)(function () {
|
|
1323
|
+
var _a;
|
|
1324
|
+
if (!((_a = field.options) === null || _a === void 0 ? void 0 : _a.filterByEnduserState) || !state) {
|
|
1325
|
+
return filteredChoicesWithPotentialDuplicates;
|
|
1326
|
+
}
|
|
1327
|
+
return filteredChoicesWithPotentialDuplicates.filter(function (c) {
|
|
1328
|
+
var _a, _b;
|
|
1329
|
+
var recordState = ((_b = (_a = c.values.find(function (v) { var _a, _b; return ((_b = (_a = v.label) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'state'; })) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.toString()) || '';
|
|
1330
|
+
return !recordState || recordState === state;
|
|
1331
|
+
});
|
|
1332
|
+
}, [filteredChoicesWithPotentialDuplicates, (_h = field.options) === null || _h === void 0 ? void 0 : _h.filterByEnduserState, state]);
|
|
1333
|
+
var filteredChoices = (0, react_1.useMemo)(function () {
|
|
1334
|
+
var filtered = [];
|
|
1335
|
+
var uniques = new Set([]);
|
|
1336
|
+
for (var _a = 0, stateFilteredChoices_1 = stateFilteredChoices; _a < stateFilteredChoices_1.length; _a++) {
|
|
1337
|
+
var c = stateFilteredChoices_1[_a];
|
|
1338
|
+
var text = label_for_database_record(field, c);
|
|
1339
|
+
if (uniques.has(text))
|
|
1340
|
+
continue; // duplicate found
|
|
1341
|
+
uniques.add(text);
|
|
1342
|
+
filtered.push(c);
|
|
1343
|
+
}
|
|
1344
|
+
return filtered;
|
|
1345
|
+
}, [field, stateFilteredChoices]);
|
|
1346
|
+
if (!doneLoading)
|
|
1347
|
+
return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
|
|
1348
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Autocomplete, { id: field.id, freeSolo: false, size: size, componentsProps: { popper: { sx: { wordBreak: "break-word" } } }, options: filteredChoices, multiple: true, getOptionLabel: function (o) { return (Array.isArray(o) // edge case
|
|
1349
|
+
? ''
|
|
1350
|
+
: label_for_database_record(field, o)); }, value: value, disabled: disabled, onChange: function (_, v) {
|
|
1351
|
+
var _a, _b, _d, _e, _f;
|
|
1352
|
+
if (v.length && onDatabaseSelect) {
|
|
1353
|
+
onDatabaseSelect(((_a = field.options) === null || _a === void 0 ? void 0 : _a.radio)
|
|
1354
|
+
? [v[v.length - 1]] // if radio, only last selected
|
|
1355
|
+
: v);
|
|
1356
|
+
}
|
|
1357
|
+
return onChange((!((_b = field.options) === null || _b === void 0 ? void 0 : _b.radio)
|
|
1358
|
+
? v.map(function (_v) {
|
|
1359
|
+
var _a;
|
|
1360
|
+
return ({
|
|
1361
|
+
databaseId: (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseId,
|
|
1362
|
+
recordId: _v.id,
|
|
1363
|
+
text: label_for_database_record(field, _v),
|
|
1364
|
+
});
|
|
1365
|
+
})
|
|
1366
|
+
: [{
|
|
1367
|
+
databaseId: (_d = field.options) === null || _d === void 0 ? void 0 : _d.databaseId,
|
|
1368
|
+
recordId: (_f = (_e = v[v.length - 1]) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : '',
|
|
1369
|
+
text: label_for_database_record(field, v[v.length - 1]),
|
|
1370
|
+
}]), field.id);
|
|
1371
|
+
}, inputValue: typing, onInputChange: function (e, v) { return e && setTyping(v); }, renderInput: function (params) { return (0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: exports.defaultInputProps.sx }) })); },
|
|
1372
|
+
// use custom Chip to ensure very long entries break properly (whitespace: normal)
|
|
1373
|
+
renderTags: function (value, getTagProps) {
|
|
1374
|
+
return value.map(function (value, index) { return ((0, jsx_runtime_1.jsx)(material_1.Chip, __assign({ label: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ style: { whiteSpace: 'normal' } }, { children: Array.isArray(value) ? '' : label_for_database_record(field, value) })) }, getTagProps({ index: index }), { sx: { height: "100%", py: 0.5 } }))); });
|
|
1375
|
+
} }), AddToDatabase && ((_j = field === null || field === void 0 ? void 0 : field.options) === null || _j === void 0 ? void 0 : _j.allowAddToDatabase) && ((0, jsx_runtime_1.jsx)(AddToDatabase, { databaseId: (_k = field.options) === null || _k === void 0 ? void 0 : _k.databaseId, onAdd: addChoice }))] }));
|
|
1376
|
+
};
|
|
1377
|
+
exports.DatabaseSelectInput = DatabaseSelectInput;
|
|
1378
|
+
var displayTermsCache = undefined;
|
|
1379
|
+
var DRUGS_FOR_DISPLAY_TERM = {};
|
|
1380
|
+
var RX_NORM_CODE_FOR_DRUG = {};
|
|
1381
|
+
var NDC_CODES_FOR_RX_NORM_CODE = {};
|
|
1382
|
+
var useMedications = function (_a) {
|
|
1383
|
+
var dontFetch = _a.dontFetch;
|
|
1384
|
+
var _b = (0, react_1.useState)(displayTermsCache), displayTerms = _b[0], setDisplayTerms = _b[1];
|
|
1385
|
+
var fetchRef = (0, react_1.useRef)(displayTerms !== undefined);
|
|
1386
|
+
(0, react_1.useEffect)(function () {
|
|
1387
|
+
if (dontFetch)
|
|
1388
|
+
return;
|
|
1389
|
+
if (fetchRef.current)
|
|
1390
|
+
return;
|
|
1391
|
+
fetchRef.current = true;
|
|
1392
|
+
// thankfully, this endpoint has cache control, so repeated requests should fetch from disk anyway
|
|
1393
|
+
axios_1.default.get('https://rxnav.nlm.nih.gov/REST/displaynames.json')
|
|
1394
|
+
.then(function (result) {
|
|
1395
|
+
var _a, _b, _d;
|
|
1396
|
+
return setDisplayTerms({
|
|
1397
|
+
displayTermsList: {
|
|
1398
|
+
term: ((_d = (_b = (_a = result.data) === null || _a === void 0 ? void 0 : _a.displayTermsList) === null || _b === void 0 ? void 0 : _b.term) === null || _d === void 0 ? void 0 : _d.filter(function (t) {
|
|
1399
|
+
try {
|
|
1400
|
+
// parse out some of the not immediately useful / non-human-readable options
|
|
1401
|
+
if (t.startsWith('('))
|
|
1402
|
+
return false;
|
|
1403
|
+
if (t.startsWith('.'))
|
|
1404
|
+
return false;
|
|
1405
|
+
if (!isNaN(parseInt(t.charAt(0))))
|
|
1406
|
+
return false; // starts with a number
|
|
1407
|
+
return true;
|
|
1408
|
+
}
|
|
1409
|
+
catch (err) {
|
|
1410
|
+
return false;
|
|
1411
|
+
}
|
|
1412
|
+
}))
|
|
1413
|
+
}
|
|
1414
|
+
});
|
|
1415
|
+
})
|
|
1416
|
+
.catch(console.error);
|
|
1417
|
+
}, [dontFetch]);
|
|
1418
|
+
var getDrugsForDisplayTerm = (0, react_1.useCallback)(function (s) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1419
|
+
var drugs, _a;
|
|
1420
|
+
var _b, _d, _e, _f;
|
|
1421
|
+
return __generator(this, function (_g) {
|
|
1422
|
+
switch (_g.label) {
|
|
1423
|
+
case 0:
|
|
1424
|
+
_a = DRUGS_FOR_DISPLAY_TERM[s];
|
|
1425
|
+
if (_a) return [3 /*break*/, 2];
|
|
1426
|
+
return [4 /*yield*/, axios_1.default.get("https://rxnav.nlm.nih.gov/REST/drugs.json?name=".concat(s))];
|
|
1427
|
+
case 1:
|
|
1428
|
+
_a = ((_f = (_e = (_d = (_b = (_g.sent())
|
|
1429
|
+
.data) === null || _b === void 0 ? void 0 : _b.drugGroup) === null || _d === void 0 ? void 0 : _d.conceptGroup) === null || _e === void 0 ? void 0 : _e.find(function (v) { return v.conceptProperties; })) === null || _f === void 0 ? void 0 : _f.conceptProperties);
|
|
1430
|
+
_g.label = 2;
|
|
1431
|
+
case 2:
|
|
1432
|
+
drugs = _a;
|
|
1433
|
+
if (!DRUGS_FOR_DISPLAY_TERM[s]) {
|
|
1434
|
+
DRUGS_FOR_DISPLAY_TERM[s] = drugs; // cache for future lookups
|
|
1435
|
+
}
|
|
1436
|
+
return [2 /*return*/, drugs];
|
|
1437
|
+
}
|
|
1438
|
+
});
|
|
1439
|
+
}); }, []);
|
|
1440
|
+
var getCodesForDrug = (0, react_1.useCallback)(function (s) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1441
|
+
var rxNormCode, _a, NDCs, _b;
|
|
1442
|
+
var _d, _e, _f, _g, _h, _j, _k;
|
|
1443
|
+
return __generator(this, function (_l) {
|
|
1444
|
+
switch (_l.label) {
|
|
1445
|
+
case 0:
|
|
1446
|
+
_a = RX_NORM_CODE_FOR_DRUG[s];
|
|
1447
|
+
if (_a) return [3 /*break*/, 2];
|
|
1448
|
+
return [4 /*yield*/, axios_1.default.get("https://rxnav.nlm.nih.gov/REST/rxcui.json?name=".concat(s, "&allsrc=1"))];
|
|
1449
|
+
case 1:
|
|
1450
|
+
_a = ((_f = (_e = (_d = (_l.sent())
|
|
1451
|
+
.data) === null || _d === void 0 ? void 0 : _d.idGroup) === null || _e === void 0 ? void 0 : _e.rxnormId) === null || _f === void 0 ? void 0 : _f[0]);
|
|
1452
|
+
_l.label = 2;
|
|
1453
|
+
case 2:
|
|
1454
|
+
rxNormCode = _a;
|
|
1455
|
+
RX_NORM_CODE_FOR_DRUG[s] = rxNormCode; // cache for future lookups
|
|
1456
|
+
_b = NDC_CODES_FOR_RX_NORM_CODE[rxNormCode];
|
|
1457
|
+
if (_b) return [3 /*break*/, 4];
|
|
1458
|
+
return [4 /*yield*/, axios_1.default.get("https://rxnav.nlm.nih.gov/REST/rxcui/".concat(rxNormCode, "/ndcs.json"))];
|
|
1459
|
+
case 3:
|
|
1460
|
+
_b = ((_k = (_j = (_h = (_g = (_l.sent())
|
|
1461
|
+
.data) === null || _g === void 0 ? void 0 : _g.ndcGroup) === null || _h === void 0 ? void 0 : _h.ndcList) === null || _j === void 0 ? void 0 : _j.ndc) !== null && _k !== void 0 ? _k : []);
|
|
1462
|
+
_l.label = 4;
|
|
1463
|
+
case 4:
|
|
1464
|
+
NDCs = _b;
|
|
1465
|
+
NDC_CODES_FOR_RX_NORM_CODE[rxNormCode] = NDCs; // cache for future lookups
|
|
1466
|
+
return [2 /*return*/, {
|
|
1467
|
+
rxNormCode: rxNormCode,
|
|
1468
|
+
NDCs: NDCs,
|
|
1469
|
+
}];
|
|
1470
|
+
}
|
|
1471
|
+
});
|
|
1472
|
+
}); }, []);
|
|
1473
|
+
if (displayTerms === undefined) {
|
|
1474
|
+
return {
|
|
1475
|
+
displayTerms: undefined,
|
|
1476
|
+
doneLoading: false,
|
|
1477
|
+
getDrugsForDisplayTerm: getDrugsForDisplayTerm,
|
|
1478
|
+
getCodesForDrug: getCodesForDrug,
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
return {
|
|
1482
|
+
displayTerms: displayTerms,
|
|
1483
|
+
doneLoading: true,
|
|
1484
|
+
getDrugsForDisplayTerm: getDrugsForDisplayTerm,
|
|
1485
|
+
getCodesForDrug: getCodesForDrug,
|
|
1486
|
+
};
|
|
1487
|
+
};
|
|
1488
|
+
var filterOptions = function (options, _a) {
|
|
1489
|
+
var inputValue = _a.inputValue;
|
|
1490
|
+
return ((inputValue
|
|
1491
|
+
? (options
|
|
1492
|
+
.filter(function (o) { return o.toLowerCase().includes(inputValue.toLowerCase()); })
|
|
1493
|
+
// show shorter matches first (tends to promote exact match and simpler medications)
|
|
1494
|
+
.sort(function (v1, v2) { return v1.length - v2.length; })
|
|
1495
|
+
// .reverse()
|
|
1496
|
+
) : (options))
|
|
1497
|
+
.slice(0, 100) // dramatic performance improvement (when not virtualized) to show a subset like this
|
|
1498
|
+
);
|
|
1499
|
+
};
|
|
1500
|
+
var FDB_URL = "http://www.fdbhealth.com/";
|
|
1501
|
+
var CanvasMedicationsInput = function (_a) {
|
|
1502
|
+
var _b;
|
|
1503
|
+
var field = _a.field, _d = _a.value, value = _d === void 0 ? [] : _d, onChange = _a.onChange;
|
|
1504
|
+
var session = (0, __1.useResolvedSession)();
|
|
1505
|
+
var _e = (0, react_1.useState)(''), query = _e[0], setQuery = _e[1];
|
|
1506
|
+
var _f = (0, react_1.useState)([]), results = _f[0], setResults = _f[1];
|
|
1507
|
+
// if two Medications questions shown in a row, reset state
|
|
1508
|
+
(0, react_1.useEffect)(function () {
|
|
1509
|
+
setQuery('');
|
|
1510
|
+
setResults([]);
|
|
1511
|
+
}, [field.id]);
|
|
1512
|
+
var fetchRef = (0, react_1.useRef)(query);
|
|
1513
|
+
(0, react_1.useEffect)(function () {
|
|
1514
|
+
if (fetchRef.current === query)
|
|
1515
|
+
return;
|
|
1516
|
+
fetchRef.current = query;
|
|
1517
|
+
if (!query)
|
|
1518
|
+
return;
|
|
1519
|
+
var t = setTimeout(function () {
|
|
1520
|
+
session.api.integrations
|
|
1521
|
+
.proxy_read({
|
|
1522
|
+
integration: constants_1.CANVAS_TITLE,
|
|
1523
|
+
type: 'medications',
|
|
1524
|
+
query: query,
|
|
1525
|
+
})
|
|
1526
|
+
.then(function (r) {
|
|
1527
|
+
var _a;
|
|
1528
|
+
setResults((((_a = r.data) === null || _a === void 0 ? void 0 : _a.entry) || [])
|
|
1529
|
+
.map(function (v) {
|
|
1530
|
+
var fdbCode = v.resource.code.coding.find(function (c) { return c.system === FDB_URL; });
|
|
1531
|
+
return {
|
|
1532
|
+
displayTerm: (fdbCode === null || fdbCode === void 0 ? void 0 : fdbCode.display) || '',
|
|
1533
|
+
drugName: (fdbCode === null || fdbCode === void 0 ? void 0 : fdbCode.display) || '',
|
|
1534
|
+
fdbCode: (fdbCode === null || fdbCode === void 0 ? void 0 : fdbCode.code) || '',
|
|
1535
|
+
};
|
|
1536
|
+
}));
|
|
1537
|
+
});
|
|
1538
|
+
}, 200);
|
|
1539
|
+
return function () { clearTimeout(t); };
|
|
1540
|
+
}, [session, query, (_b = field === null || field === void 0 ? void 0 : field.options) === null || _b === void 0 ? void 0 : _b.dataSource]);
|
|
1541
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Autocomplete, { multiple: true, value: value, options: results, style: { marginTop: 5 }, noOptionsText: query.length ? 'No results found' : 'Type to start search', onChange: function (e, v) {
|
|
1542
|
+
if (!v) {
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
onChange(v, field.id);
|
|
1546
|
+
setResults([]);
|
|
1547
|
+
}, getOptionLabel: function (v) { return (0, utilities_1.first_letter_capitalized)(v.displayTerm); }, filterOptions: function (o) { return o; }, inputValue: query, onInputChange: function (e, v) { return e && setQuery(v); }, renderInput: function (params) { return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: exports.defaultInputProps.sx }), required: !field.isOptional, size: "small", label: "", placeholder: "Search medications..." }))); }, renderTags: function (value, getTagProps) {
|
|
1548
|
+
return value.map(function (value, index) { return ((0, jsx_runtime_1.jsx)(material_1.Chip, __assign({ label: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ style: { whiteSpace: 'normal' } }, { children: value.displayTerm })) }, getTagProps({ index: index }), { sx: { height: "100%", py: 0.5 } }))); });
|
|
1549
|
+
} }) })), (value || []).map(function (medication, i) {
|
|
1550
|
+
var _a;
|
|
1551
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 0.75 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ noWrap: true, sx: { fontSize: 14 } }, { children: medication.drugName })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { InputProps: { sx: exports.defaultInputProps.sx }, fullWidth: true, size: "small", label: "Medication instructions: how much you take, how often, and when", value: ((_a = medication.dosage) === null || _a === void 0 ? void 0 : _a.description) || '', onChange: function (e) { return (onChange((value || []).map(function (v, _i) {
|
|
1552
|
+
return i === _i
|
|
1553
|
+
? __assign(__assign({}, v), { dosage: __assign(__assign({}, v.dosage), { description: e.target.value }) }) : v;
|
|
1554
|
+
}), field.id)); } }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Divider, { flexItem: true, sx: { my: 0.5 } }) }))] })) }), i));
|
|
1555
|
+
})] })));
|
|
1556
|
+
};
|
|
1557
|
+
exports.CanvasMedicationsInput = CanvasMedicationsInput;
|
|
1558
|
+
var MedicationsInput = function (_a) {
|
|
1559
|
+
var _b, _d;
|
|
1560
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange, props = __rest(_a, ["field", "value", "onChange"]);
|
|
1561
|
+
var _e = useMedications({
|
|
1562
|
+
dontFetch: ((_b = field.options) === null || _b === void 0 ? void 0 : _b.dataSource) === constants_1.CANVAS_TITLE
|
|
1563
|
+
}), displayTerms = _e.displayTerms, doneLoading = _e.doneLoading, getCodesForDrug = _e.getCodesForDrug, getDrugsForDisplayTerm = _e.getDrugsForDisplayTerm;
|
|
1564
|
+
var _f = (0, react_1.useState)({}), drugs = _f[0], setDrugs = _f[1];
|
|
1565
|
+
// uncomment to load data after initial typing
|
|
1566
|
+
// const [query, setQuery] = useState('')
|
|
1567
|
+
// useEffect(() => {
|
|
1568
|
+
// if (!value?.length) return
|
|
1569
|
+
// Promise.all((value ?? []).map(v => (
|
|
1570
|
+
// v.displayTerm ? getDrugsForDisplayTerm(v.displayTerm) : null
|
|
1571
|
+
// )))
|
|
1572
|
+
// .then(values => {
|
|
1573
|
+
// const toSet: typeof drugs = {}
|
|
1574
|
+
// values.forEach((v, i) => {
|
|
1575
|
+
// toSet[value[i].displayTerm] = v ?? []
|
|
1576
|
+
// if (!v?.length) {
|
|
1577
|
+
// // drug is unknown, and previously looked-up NDCs and rxNormCode should be reset
|
|
1578
|
+
// value[i].drugName = "Unknown"
|
|
1579
|
+
// value[i].NDCs = []
|
|
1580
|
+
// value[i].rxNormCode = ''
|
|
1581
|
+
// }
|
|
1582
|
+
// })
|
|
1583
|
+
// setDrugs(toSet)
|
|
1584
|
+
// })
|
|
1585
|
+
// .catch(console.error)
|
|
1586
|
+
// }, [value, getDrugsForDisplayTerm])
|
|
1587
|
+
if (((_d = field.options) === null || _d === void 0 ? void 0 : _d.dataSource) === constants_1.CANVAS_TITLE) {
|
|
1588
|
+
return (0, jsx_runtime_1.jsx)(exports.CanvasMedicationsInput, __assign({ field: field, value: value, onChange: onChange }, props));
|
|
1589
|
+
}
|
|
1590
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", sx: { mt: 2 } }, { children: [(value !== null && value !== void 0 ? value : []).map(function (v, i) {
|
|
1591
|
+
var _a, _b, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1592
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap" }, { children: (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { width: '100%' } }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Autocomplete, { freeSolo: false, multiple: false, loading: !doneLoading, options:
|
|
1593
|
+
// uncomment to load data after initial typing
|
|
1594
|
+
// query.length === 0 ? [] :
|
|
1595
|
+
((_b = (_a = displayTerms === null || displayTerms === void 0 ? void 0 : displayTerms.displayTermsList) === null || _a === void 0 ? void 0 : _a.term) !== null && _b !== void 0 ? _b : []),
|
|
1596
|
+
// uncomment to load data after initial typing
|
|
1597
|
+
// noOptionsText={query.length === 0 ? "Start typing..." : undefined}
|
|
1598
|
+
// uncomment to load data after initial typing
|
|
1599
|
+
// inputValue={query} onInputChange={(e, v) => setQuery(v)}
|
|
1600
|
+
getOptionLabel: utilities_1.first_letter_capitalized, filterOptions: filterOptions, value: v.displayTerm, onChange: function (_, displayTerm) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1601
|
+
var drugs, _a;
|
|
1602
|
+
return __generator(this, function (_b) {
|
|
1603
|
+
switch (_b.label) {
|
|
1604
|
+
case 0:
|
|
1605
|
+
if (!displayTerm) return [3 /*break*/, 2];
|
|
1606
|
+
return [4 /*yield*/, getDrugsForDisplayTerm(displayTerm)];
|
|
1607
|
+
case 1:
|
|
1608
|
+
_a = _b.sent();
|
|
1609
|
+
return [3 /*break*/, 3];
|
|
1610
|
+
case 2:
|
|
1611
|
+
_a = null;
|
|
1612
|
+
_b.label = 3;
|
|
1613
|
+
case 3:
|
|
1614
|
+
drugs = _a;
|
|
1615
|
+
if (displayTerm) {
|
|
1616
|
+
setDrugs(function (ds) {
|
|
1617
|
+
var _a;
|
|
1618
|
+
return (__assign(__assign({}, ds), (_a = {}, _a[displayTerm] = drugs !== null && drugs !== void 0 ? drugs : [], _a)));
|
|
1619
|
+
});
|
|
1620
|
+
}
|
|
1621
|
+
onChange((value !== null && value !== void 0 ? value : []).map(function (_v, _i) { return (i === _i
|
|
1622
|
+
? __assign(__assign({}, _v), { displayTerm: displayTerm || '', drugName: (drugs === null || drugs === void 0 ? void 0 : drugs.length) ? '' : "Unknown", drugSynonym: '', reasonForTaking: '', dosage: {
|
|
1623
|
+
unit: '',
|
|
1624
|
+
value: '',
|
|
1625
|
+
quantity: '',
|
|
1626
|
+
frequency: '',
|
|
1627
|
+
},
|
|
1628
|
+
// reset these on new search term to avoid stale data
|
|
1629
|
+
NDCs: [], rxNormCode: '' }) : _v); }), field.id);
|
|
1630
|
+
return [2 /*return*/];
|
|
1631
|
+
}
|
|
1632
|
+
});
|
|
1633
|
+
}); }, renderInput: function (params) {
|
|
1634
|
+
return (0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: exports.defaultInputProps.sx }), required: !field.isOptional, label: "Search", size: "small", fullWidth: true }));
|
|
1635
|
+
} }) })), v.displayTerm && v.drugName !== "Unknown" && !v.otherDrug &&
|
|
1636
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { mt: 1.5 } }, { children: (0, jsx_runtime_1.jsx)(material_1.Autocomplete, { freeSolo: false, options: drugs[v.displayTerm]
|
|
1637
|
+
? drugs[v.displayTerm].length
|
|
1638
|
+
? drugs[v.displayTerm]
|
|
1639
|
+
: [{ name: 'Unknown', rxcui: '' }]
|
|
1640
|
+
: [] // still loading
|
|
1641
|
+
, multiple: false, getOptionLabel: function (d) { return (d === null || d === void 0 ? void 0 : d.synonym) ? d.synonym : ((d === null || d === void 0 ? void 0 : d.name) || ''); }, value: (_e = __spreadArray(__spreadArray([], (_d = drugs[v.displayTerm]) !== null && _d !== void 0 ? _d : [], true), [{ name: "Unknown", rxcui: '' }], false).find(function (d) { return d.name === v.drugName; })) !== null && _e !== void 0 ? _e : null, onChange: function (_, drug) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1642
|
+
var info, _a;
|
|
1643
|
+
return __generator(this, function (_b) {
|
|
1644
|
+
switch (_b.label) {
|
|
1645
|
+
case 0:
|
|
1646
|
+
if (!drug)
|
|
1647
|
+
return [2 /*return*/];
|
|
1648
|
+
if (!(drug.name === 'Unknown')) return [3 /*break*/, 2];
|
|
1649
|
+
return [4 /*yield*/, getCodesForDrug(v.displayTerm)]; // might get us a value, better than searching Unknown or keeping a prior value
|
|
1650
|
+
case 1:
|
|
1651
|
+
_a = _b.sent(); // might get us a value, better than searching Unknown or keeping a prior value
|
|
1652
|
+
return [3 /*break*/, 4];
|
|
1653
|
+
case 2: return [4 /*yield*/, getCodesForDrug(drug.name)];
|
|
1654
|
+
case 3:
|
|
1655
|
+
_a = _b.sent();
|
|
1656
|
+
_b.label = 4;
|
|
1657
|
+
case 4:
|
|
1658
|
+
info = (_a);
|
|
1659
|
+
onChange((value !== null && value !== void 0 ? value : []).map(function (_v, _i) { return (i === _i
|
|
1660
|
+
? __assign(__assign(__assign({}, _v), { drugName: drug.name, drugSynonym: drug.synonym || '' }), info) : _v); }), field.id);
|
|
1661
|
+
return [2 /*return*/];
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
}); }, renderInput: function (params) {
|
|
1665
|
+
return (0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: exports.defaultInputProps.sx }), required: !field.isOptional, label: "Drug Select", size: "small", fullWidth: true }));
|
|
1666
|
+
} }) })), v.displayTerm && (v.drugName === "Unknown" || !v.drugName) &&
|
|
1667
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { mt: 1 } }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { label: 'Other Drug', fullWidth: true, size: "small", required: true, InputProps: exports.defaultInputProps, value: (_g = (_f = value === null || value === void 0 ? void 0 : value.find(function (v, _i) { return _i === i; })) === null || _f === void 0 ? void 0 : _f.otherDrug) !== null && _g !== void 0 ? _g : '', onChange: function (e) { return (onChange((value !== null && value !== void 0 ? value : []).map(function (_v, _i) { return (i === _i
|
|
1668
|
+
? __assign(__assign({}, _v), { otherDrug: e.target.value }) : _v); }), field.id)); } }) })), v.displayTerm &&
|
|
1669
|
+
(0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, spacing: 1, sx: { mt: 0 } }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ item: true, xs: 12, md: 6 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ sx: { fontSize: 13.5 } }, { children: "Units (e.g. capsule, table, puff) per dose?" })), (0, jsx_runtime_1.jsx)(material_1.TextField, { type: "number", size: "small", fullWidth: true, InputProps: exports.defaultInputProps, value: (_h = v.dosage) === null || _h === void 0 ? void 0 : _h.quantity, onChange: function (e) {
|
|
1670
|
+
return onChange((value !== null && value !== void 0 ? value : []).map(function (_v, _i) { return (i === _i
|
|
1671
|
+
? __assign(__assign({}, _v), { dosage: __assign(__assign({}, _v.dosage), { quantity: e.target.value }) }) : _v); }), field.id);
|
|
1672
|
+
},
|
|
1673
|
+
// hide arrows for number input, which continue to increase after initial press
|
|
1674
|
+
sx: {
|
|
1675
|
+
'& input[type=number]': {
|
|
1676
|
+
'-moz-appearance': 'textfield'
|
|
1677
|
+
},
|
|
1678
|
+
'& input[type=number]::-webkit-outer-spin-button': {
|
|
1679
|
+
'-webkit-appearance': 'none',
|
|
1680
|
+
margin: 0
|
|
1681
|
+
},
|
|
1682
|
+
'& input[type=number]::-webkit-inner-spin-button': {
|
|
1683
|
+
'-webkit-appearance': 'none',
|
|
1684
|
+
margin: 0
|
|
1685
|
+
}
|
|
1686
|
+
} })] })), (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ item: true, xs: 12, md: 6 }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, __assign({ sx: { fontSize: 13.5 } }, { children: ["How many times per ", (0, jsx_runtime_1.jsx)("strong", { children: "day" }), "?"] })), (0, jsx_runtime_1.jsx)(StringSelector, { size: "small", options: ["1", "2", "3", "4", "5", "6", "As Needed"], value: (_k = (_j = v.dosage) === null || _j === void 0 ? void 0 : _j.frequency) !== null && _k !== void 0 ? _k : '', onChange: function (frequency) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1687
|
+
return __generator(this, function (_a) {
|
|
1688
|
+
onChange((value !== null && value !== void 0 ? value : []).map(function (_v, _i) { return (i === _i
|
|
1689
|
+
? __assign(__assign({}, _v), { dosage: __assign(__assign({}, _v.dosage), { frequency: frequency || '' }) }) : _v); }), field.id);
|
|
1690
|
+
return [2 /*return*/];
|
|
1691
|
+
});
|
|
1692
|
+
}); } })] }))] })), v.displayTerm &&
|
|
1693
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { mt: 1.25 } }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "Reason for taking medication", size: "small", fullWidth: true, InputProps: exports.defaultInputProps, value: (_l = v.reasonForTaking) !== null && _l !== void 0 ? _l : '', onChange: function (e) {
|
|
1694
|
+
return onChange((value !== null && value !== void 0 ? value : []).map(function (_v, _i) { return (i === _i
|
|
1695
|
+
? __assign(__assign({}, _v), { reasonForTaking: e.target.value }) : _v); }), field.id);
|
|
1696
|
+
} }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "primary", sx: { textDecoration: 'underline', cursor: 'pointer' }, onClick: function () { return onChange((value !== null && value !== void 0 ? value : []).filter(function (_, _i) { return i !== _i; }), field.id); } }, { children: "Remove medication" })) })), window.location.origin.includes(':300') && i === 0 &&
|
|
1697
|
+
(0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ item: true, sx: { mt: 3 } }, { children: [(0, jsx_runtime_1.jsx)("strong", { children: "DEBUG:" }), " ", (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)("pre", __assign({ style: { wordWrap: 'break-word' } }, { children: JSON.stringify(value !== null && value !== void 0 ? value : {}, null, 2) }))] })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Grid, { container: true }) }))] })) })) })) }), i), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Divider, { flexItem: true, sx: { my: 1 } }) }))] }));
|
|
1698
|
+
}), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ color: "primary", variant: "outlined", onClick: function () { return onChange(__spreadArray(__spreadArray([], (value !== null && value !== void 0 ? value : []), true), [{ displayTerm: '', drugName: '' }], false), field.id); } }, { children: "Add Medication" })) }))] })));
|
|
1699
|
+
};
|
|
1700
|
+
exports.MedicationsInput = MedicationsInput;
|
|
1701
|
+
var contact_is_valid = function (e) {
|
|
1702
|
+
if (e.email) {
|
|
1703
|
+
try {
|
|
1704
|
+
validation_1.emailValidator.validate()(e.email);
|
|
1705
|
+
}
|
|
1706
|
+
catch (err) {
|
|
1707
|
+
return "Email is invalid";
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
if (e.phone) {
|
|
1711
|
+
try {
|
|
1712
|
+
validation_1.phoneValidator.validate()(e.phone);
|
|
1713
|
+
}
|
|
1714
|
+
catch (err) {
|
|
1715
|
+
return "Phone is invalid";
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
if (e.dateOfBirth && !(0, __1.isDateString)(e.dateOfBirth)) {
|
|
1719
|
+
return "Date of birth should be MM-DD-YYYY";
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
exports.contact_is_valid = contact_is_valid;
|
|
1723
|
+
var RelatedContactsInput = function (_a) {
|
|
1724
|
+
var _b, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _w, _x;
|
|
1725
|
+
var field = _a.field, _value = _a.value, onChange = _a.onChange, props = __rest(_a, ["field", "value", "onChange"]);
|
|
1726
|
+
// safeguard against any rogue values like empty string
|
|
1727
|
+
var value = Array.isArray(_value) ? _value : [];
|
|
1728
|
+
var _y = (0, react_1.useState)(value.length === 1 ? 0 : -1), editing = _y[0], setEditing = _y[1];
|
|
1729
|
+
var handleAddContact = (0, react_1.useCallback)(function () {
|
|
1730
|
+
var _a, _b;
|
|
1731
|
+
onChange(__spreadArray(__spreadArray([], value, true), [
|
|
1732
|
+
{ relationships: ((_b = (_a = field === null || field === void 0 ? void 0 : field.options) === null || _a === void 0 ? void 0 : _a.relatedContactTypes) === null || _b === void 0 ? void 0 : _b.length) === 1 ? [{ type: field.options.relatedContactTypes[0], id: '' }] : [] }
|
|
1733
|
+
], false), field.id, true);
|
|
1734
|
+
setEditing(value.length);
|
|
1735
|
+
}, [onChange, value, field === null || field === void 0 ? void 0 : field.id, (_b = field === null || field === void 0 ? void 0 : field.options) === null || _b === void 0 ? void 0 : _b.relatedContactTypes]);
|
|
1736
|
+
if (value[editing]) {
|
|
1737
|
+
var _z = value[editing], fname = _z.fname, lname = _z.lname, email = _z.email, phone = _z.phone, _0 = _z.fields, fields_1 = _0 === void 0 ? {} : _0, _1 = _z.dateOfBirth, dateOfBirth = _1 === void 0 ? '' : _1, relationships = _z.relationships;
|
|
1738
|
+
var errorMessage = (0, exports.contact_is_valid)(value[editing]);
|
|
1739
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap", spacing: 1 }, { children: [!((_e = (_d = field.options) === null || _d === void 0 ? void 0 : _d.hiddenDefaultFields) === null || _e === void 0 ? void 0 : _e.includes('First Name')) &&
|
|
1740
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 4 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "First Name", size: "small", fullWidth: true, InputProps: exports.defaultInputProps, value: fname, onChange: function (e) { return onChange(value.map(function (v, i) { return i === editing ? __assign(__assign({}, v), { fname: e.target.value }) : v; }), field.id); } }) })), !((_g = (_f = field.options) === null || _f === void 0 ? void 0 : _f.hiddenDefaultFields) === null || _g === void 0 ? void 0 : _g.includes('Last Name')) &&
|
|
1741
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 4 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "Last Name", size: "small", fullWidth: true, InputProps: exports.defaultInputProps, value: lname, onChange: function (e) { return onChange(value.map(function (v, i) { return i === editing ? __assign(__assign({}, v), { lname: e.target.value }) : v; }), field.id); } }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 4 }, { children: (0, jsx_runtime_1.jsx)(StringSelector, { options: ((_j = (_h = field.options) === null || _h === void 0 ? void 0 : _h.relatedContactTypes) === null || _j === void 0 ? void 0 : _j.length) ? field.options.relatedContactTypes : constants_1.RELATIONSHIP_TYPES, label: "Relationship", size: "small", disabled: ((_l = (_k = field === null || field === void 0 ? void 0 : field.options) === null || _k === void 0 ? void 0 : _k.relatedContactTypes) === null || _l === void 0 ? void 0 : _l.length) === 1, value: (_o = (_m = relationships === null || relationships === void 0 ? void 0 : relationships[0]) === null || _m === void 0 ? void 0 : _m.type) !== null && _o !== void 0 ? _o : '', onChange: function (type) { return onChange(value.map(function (v, i) { return i === editing ? __assign(__assign({}, v), { relationships: [{ type: type, id: '' /* to be filled on server-side */ }] }) : v; }), field.id); } }) }))] })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap", spacing: 1 }, { children: [!((_q = (_p = field.options) === null || _p === void 0 ? void 0 : _p.hiddenDefaultFields) === null || _q === void 0 ? void 0 : _q.includes('Date of Birth')) &&
|
|
1742
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 4 }, { children: (0, jsx_runtime_1.jsx)(exports.DateStringInput, { value: dateOfBirth, field: __assign(__assign({}, field), { isOptional: true }), size: "small", label: "Date of Birth (MM-DD-YYYY)", onChange: function (dateOfBirth) { return onChange(value.map(function (v, i) { return i === editing ? __assign(__assign({}, v), { dateOfBirth: dateOfBirth }) : v; }), field.id); } }) })), !((_s = (_r = field.options) === null || _r === void 0 ? void 0 : _r.hiddenDefaultFields) === null || _s === void 0 ? void 0 : _s.includes('Email')) &&
|
|
1743
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 4 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "Email", size: "small", fullWidth: true, type: "email", InputProps: exports.defaultInputProps, value: email, onChange: function (e) { return onChange(value.map(function (v, i) { return i === editing ? __assign(__assign({}, v), { email: e.target.value }) : v; }), field.id); } }) })), !((_u = (_t = field.options) === null || _t === void 0 ? void 0 : _t.hiddenDefaultFields) === null || _u === void 0 ? void 0 : _u.includes('Phone Number')) &&
|
|
1744
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 4 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "Phone Number", size: "small", fullWidth: true, InputProps: exports.defaultInputProps, value: phone, onChange: function (e) { return onChange(value.map(function (v, i) { return i === editing ? __assign(__assign({}, v), { phone: e.target.value }) : v; }), field.id); } }) }))] })) })), (((_w = field.options) === null || _w === void 0 ? void 0 : _w.tableChoices) || []).length > 0 &&
|
|
1745
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ container: true, spacing: 1 }, { children: (((_x = field.options) === null || _x === void 0 ? void 0 : _x.tableChoices) || []).map(function (_a, i) {
|
|
1746
|
+
var info = _a.info, label = _a.label, type = _a.type;
|
|
1747
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 6 }, { children: type === 'Text'
|
|
1748
|
+
? ((0, jsx_runtime_1.jsx)(material_1.TextField, { label: label, size: "small", fullWidth: true, InputProps: exports.defaultInputProps, value: fields_1[label] || '', onChange: function (e) { return onChange(value.map(function (v, i) {
|
|
1749
|
+
var _a;
|
|
1750
|
+
return i === editing ? __assign(__assign({}, v), { fields: __assign(__assign({}, fields_1), (_a = {}, _a[label] = e.target.value, _a)) }) : v;
|
|
1751
|
+
}), field.id); } }))
|
|
1752
|
+
: type === 'Date' ? ((0, jsx_runtime_1.jsx)(exports.DateStringInput, { label: label, size: "small", fullWidth: true, field: __assign(__assign({}, field), { isOptional: true }), value: fields_1[label] || '', onChange: function (e) {
|
|
1753
|
+
if (e === void 0) { e = ''; }
|
|
1754
|
+
return onChange(value.map(function (v, i) {
|
|
1755
|
+
var _a;
|
|
1756
|
+
return i === editing ? __assign(__assign({}, v), { fields: __assign(__assign({}, fields_1), (_a = {}, _a[label] = e, _a)) }) : v;
|
|
1757
|
+
}), field.id);
|
|
1758
|
+
} }))
|
|
1759
|
+
: type === 'Select' ? ((0, jsx_runtime_1.jsxs)(material_1.FormControl, __assign({ size: "small", fullWidth: true }, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, __assign({ id: "demo-select-small" }, { children: label })), (0, jsx_runtime_1.jsxs)(material_1.Select, __assign({ label: label, size: "small", sx: exports.defaultInputProps.sx, value: fields_1[label] || '', onChange: function (e) { return onChange(value.map(function (v, i) {
|
|
1760
|
+
var _a;
|
|
1761
|
+
return i === editing ? __assign(__assign({}, v), { fields: __assign(__assign({}, fields_1), (_a = {}, _a[label] = e.target.value, _a)) }) : v;
|
|
1762
|
+
}), field.id); } }, { children: [(0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: "" }, { children: (0, jsx_runtime_1.jsx)("em", { children: "None" }) })), info.choices.map(function (c) { return ((0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: c }, { children: c }), c)); })] }))] })))
|
|
1763
|
+
: null }), i));
|
|
1764
|
+
}) })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { my: 0.75 } }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ variant: "outlined", onClick: function () { return setEditing(-1); }, size: "small" }, { children: "Save Contact" })) })), errorMessage &&
|
|
1765
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error" }, { children: errorMessage })) }))] })));
|
|
1766
|
+
}
|
|
1767
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: value.map(function (contact, i) { return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", justifyContent: "space-between", wrap: "nowrap", spacing: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(__1.IconButton, __assign({ onClick: function () { return setEditing(i); }, color: "primary", size: "small" }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.Edit, {}) })), (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ noWrap: true }, { children: (0, utilities_1.user_display_name)(contact) || "Unnamed Contact ".concat(i + 1) }))] })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(__1.LabeledIconButton, { Icon: icons_material_1.Delete, label: "Remove", onClick: function () { return onChange(value.filter(function (v, _i) { return i !== _i; }), field.id); } }) }))] })) }), i)); }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ variant: "contained", onClick: handleAddContact }, { children: "Add Contact" })) }))] })));
|
|
1768
|
+
};
|
|
1769
|
+
exports.RelatedContactsInput = RelatedContactsInput;
|
|
1770
|
+
var AppointmentBookingInput = function (_a) {
|
|
1771
|
+
var _b, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1772
|
+
var formResponseId = _a.formResponseId, field = _a.field, value = _a.value, onChange = _a.onChange, form = _a.form, responses = _a.responses, goToPreviousField = _a.goToPreviousField, isPreviousDisabled = _a.isPreviousDisabled, enduserId = _a.enduserId, props = __rest(_a, ["formResponseId", "field", "value", "onChange", "form", "responses", "goToPreviousField", "isPreviousDisabled", "enduserId"]);
|
|
1773
|
+
var session = (0, __1.useResolvedSession)();
|
|
1774
|
+
var _m = (0, react_1.useState)(), loaded = _m[0], setLoaded = _m[1];
|
|
1775
|
+
var _o = (0, react_1.useState)(''), error = _o[0], setError = _o[1];
|
|
1776
|
+
var _p = (0, react_1.useState)(false), acknowledgedWarning = _p[0], setAcknowledgedWarning = _p[1];
|
|
1777
|
+
var _q = (0, react_1.useState)(450), height = _q[0], setHeight = _q[1];
|
|
1778
|
+
var _r = (0, react_1.useState)(false), confirming = _r[0], setConfirming = _r[1];
|
|
1779
|
+
var bookingPageId = (_b = field === null || field === void 0 ? void 0 : field.options) === null || _b === void 0 ? void 0 : _b.bookingPageId;
|
|
1780
|
+
var downloadICS = (0, react_1.useCallback)(function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1781
|
+
var _a, err_1;
|
|
1782
|
+
return __generator(this, function (_b) {
|
|
1783
|
+
switch (_b.label) {
|
|
1784
|
+
case 0:
|
|
1785
|
+
_b.trys.push([0, 2, , 3]);
|
|
1786
|
+
_a = utilities_1.downloadFile;
|
|
1787
|
+
return [4 /*yield*/, session.api.calendar_events.download_ics_file({ calendarEventId: event.id, excludeAttendee: true })];
|
|
1788
|
+
case 1:
|
|
1789
|
+
_a.apply(void 0, [_b.sent(),
|
|
1790
|
+
{ name: "event.ics", dataIsURL: true, type: 'text/calendar' }]);
|
|
1791
|
+
return [3 /*break*/, 3];
|
|
1792
|
+
case 2:
|
|
1793
|
+
err_1 = _b.sent();
|
|
1794
|
+
console.error(err_1);
|
|
1795
|
+
return [3 /*break*/, 3];
|
|
1796
|
+
case 3: return [2 /*return*/];
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1799
|
+
}); }, [session]);
|
|
1800
|
+
var addressQuestion = (0, react_1.useMemo)(function () { return responses === null || responses === void 0 ? void 0 : responses.find(function (r) {
|
|
1801
|
+
var _a;
|
|
1802
|
+
if (r.answer.type !== 'Address')
|
|
1803
|
+
return false;
|
|
1804
|
+
if (r.field.intakeField !== 'Address')
|
|
1805
|
+
return false;
|
|
1806
|
+
// make sure state is actually defined (in case of multiple address questions, where 1+ are blank)
|
|
1807
|
+
if (!((_a = r.answer.value) === null || _a === void 0 ? void 0 : _a.state))
|
|
1808
|
+
return false;
|
|
1809
|
+
return true;
|
|
1810
|
+
}); }, [responses]);
|
|
1811
|
+
var state = (0, react_1.useMemo)(function () {
|
|
1812
|
+
var _a, _b, _d;
|
|
1813
|
+
return (((_a = addressQuestion === null || addressQuestion === void 0 ? void 0 : addressQuestion.answer) === null || _a === void 0 ? void 0 : _a.type) === 'Address' ? (_d = (_b = addressQuestion === null || addressQuestion === void 0 ? void 0 : addressQuestion.answer) === null || _b === void 0 ? void 0 : _b.value) === null || _d === void 0 ? void 0 : _d.state : undefined);
|
|
1814
|
+
}, [addressQuestion]);
|
|
1815
|
+
var loadBookingInfo = (0, react_1.useCallback)(function () {
|
|
1816
|
+
if (!bookingPageId)
|
|
1817
|
+
return;
|
|
1818
|
+
setError('');
|
|
1819
|
+
session.api.form_fields.booking_info({
|
|
1820
|
+
enduserId: enduserId,
|
|
1821
|
+
bookingPageId: bookingPageId,
|
|
1822
|
+
enduserFields: { state: state }
|
|
1823
|
+
})
|
|
1824
|
+
.then(setLoaded)
|
|
1825
|
+
.catch(function (e) { return setError((e === null || e === void 0 ? void 0 : e.message) || (e === null || e === void 0 ? void 0 : e.toString()) || 'Error loading appointment details'); });
|
|
1826
|
+
}, [enduserId, bookingPageId, session, state]);
|
|
1827
|
+
var fetchRef = (0, react_1.useRef)(false);
|
|
1828
|
+
(0, react_1.useEffect)(function () {
|
|
1829
|
+
if (value)
|
|
1830
|
+
return;
|
|
1831
|
+
if (!bookingPageId)
|
|
1832
|
+
return;
|
|
1833
|
+
if (fetchRef.current)
|
|
1834
|
+
return;
|
|
1835
|
+
fetchRef.current = true;
|
|
1836
|
+
loadBookingInfo();
|
|
1837
|
+
}, [bookingPageId, loadBookingInfo, value]);
|
|
1838
|
+
(0, react_1.useEffect)(function () {
|
|
1839
|
+
var handleMessage = function (m) {
|
|
1840
|
+
var _a, _b, _d, _e, _f, _g, _h, _j, _k;
|
|
1841
|
+
// entropy to separate from other booking pages rendered on the same screen
|
|
1842
|
+
if (((_a = m === null || m === void 0 ? void 0 : m.data) === null || _a === void 0 ? void 0 : _a.type) === 'Booking Success'
|
|
1843
|
+
&& typeof ((_b = m === null || m === void 0 ? void 0 : m.data) === null || _b === void 0 ? void 0 : _b.bookedEventId) === 'string'
|
|
1844
|
+
&& (!((_d = m === null || m === void 0 ? void 0 : m.data) === null || _d === void 0 ? void 0 : _d.entropy) || ((_e = m === null || m === void 0 ? void 0 : m.data) === null || _e === void 0 ? void 0 : _e.entropy) === (loaded === null || loaded === void 0 ? void 0 : loaded.entropy))) {
|
|
1845
|
+
onChange(m.data.bookedEventId, field.id);
|
|
1846
|
+
(0, utilities_1.emit_gtm_event)({ event: 'form_progress', fieldId: field.id, formId: field.formId, title: field.title, status: "Appointment Booked" });
|
|
1847
|
+
}
|
|
1848
|
+
if (((_f = m === null || m === void 0 ? void 0 : m.data) === null || _f === void 0 ? void 0 : _f.type) === 'CalendarPicker') {
|
|
1849
|
+
setHeight(750);
|
|
1850
|
+
}
|
|
1851
|
+
if (((_g = m === null || m === void 0 ? void 0 : m.data) === null || _g === void 0 ? void 0 : _g.type) === 'UsersPicker') {
|
|
1852
|
+
setHeight(450);
|
|
1853
|
+
}
|
|
1854
|
+
if (((_h = m === null || m === void 0 ? void 0 : m.data) === null || _h === void 0 ? void 0 : _h.type) === 'Confirmation') {
|
|
1855
|
+
setConfirming(true);
|
|
1856
|
+
}
|
|
1857
|
+
if (((_j = m === null || m === void 0 ? void 0 : m.data) === null || _j === void 0 ? void 0 : _j.type) === 'Join Link' && ((_k = m === null || m === void 0 ? void 0 : m.data) === null || _k === void 0 ? void 0 : _k.link)) {
|
|
1858
|
+
(0, utilities_1.update_local_storage)('tellescope_last_booking_page_join_link', m.data.link);
|
|
1859
|
+
}
|
|
1860
|
+
else {
|
|
1861
|
+
setConfirming(false);
|
|
1862
|
+
}
|
|
1863
|
+
};
|
|
1864
|
+
window.addEventListener('message', handleMessage);
|
|
1865
|
+
return function () { window.removeEventListener('message', handleMessage); };
|
|
1866
|
+
}, [field === null || field === void 0 ? void 0 : field.id, field === null || field === void 0 ? void 0 : field.formId, field === null || field === void 0 ? void 0 : field.title, onChange, acknowledgedWarning, value, loaded === null || loaded === void 0 ? void 0 : loaded.entropy]);
|
|
1867
|
+
if (value) {
|
|
1868
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap" }, { children: [(0, jsx_runtime_1.jsx)(icons_material_1.CheckCircleOutline, { color: "success" }), (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ sx: { ml: 1, fontSize: 20 } }, { children: "Your appointment has been booked" }))] })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { maxWidth: 250 } }, { children: (0, jsx_runtime_1.jsx)(__1.LoadingButton, { variant: "contained", style: { maxWidth: 250 }, submitText: "Add to Calendar", submittingText: "Downloading...", onClick: function () { return downloadICS({ id: value }); } }) }))] })));
|
|
1869
|
+
}
|
|
1870
|
+
if (!bookingPageId) {
|
|
1871
|
+
return (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "No booking page specified" });
|
|
1872
|
+
}
|
|
1873
|
+
if (error) {
|
|
1874
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Typography, __assign({ color: "error" }, { children: ["Error: ", error] })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(__1.LoadingButton, { disabled: !bookingPageId, style: { maxWidth: 300 }, variant: "contained", onClick: loadBookingInfo, submitText: "Try Again", submittingText: "Loading..." }) }))] })));
|
|
1875
|
+
}
|
|
1876
|
+
if (!(loaded === null || loaded === void 0 ? void 0 : loaded.bookingURL)) {
|
|
1877
|
+
return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
|
|
1878
|
+
}
|
|
1879
|
+
var bookingURL = loaded.bookingURL;
|
|
1880
|
+
if ((_e = (_d = field.options) === null || _d === void 0 ? void 0 : _d.userTags) === null || _e === void 0 ? void 0 : _e.length) {
|
|
1881
|
+
bookingURL += "&userTags=".concat(field.options.userTags
|
|
1882
|
+
.flatMap(function (t) {
|
|
1883
|
+
var _a, _b;
|
|
1884
|
+
// set dynamic tags if found
|
|
1885
|
+
if (t === '{{logic}}') {
|
|
1886
|
+
return new URL(window.location.href).searchParams.get('logic') || '{{logic}}';
|
|
1887
|
+
}
|
|
1888
|
+
if (t.startsWith("{{field.") && t.endsWith(".value}}")) {
|
|
1889
|
+
var fieldId_1 = t.replace('{{field.', '').replace(".value}}", '');
|
|
1890
|
+
var answer = (_a = responses === null || responses === void 0 ? void 0 : responses.find(function (r) { return r.fieldId === fieldId_1; })) === null || _a === void 0 ? void 0 : _a.answer;
|
|
1891
|
+
if (!(answer === null || answer === void 0 ? void 0 : answer.value))
|
|
1892
|
+
return t;
|
|
1893
|
+
if (answer.type === 'Insurance') {
|
|
1894
|
+
return answer.value.payerName || '';
|
|
1895
|
+
}
|
|
1896
|
+
if (Array.isArray(answer.value) && typeof ((_b = answer.value) === null || _b === void 0 ? void 0 : _b[0]) === 'string') {
|
|
1897
|
+
return answer.value;
|
|
1898
|
+
}
|
|
1899
|
+
return (0, utilities_1.form_response_value_to_string)(answer.value);
|
|
1900
|
+
}
|
|
1901
|
+
return t;
|
|
1902
|
+
})
|
|
1903
|
+
.join(','));
|
|
1904
|
+
}
|
|
1905
|
+
if ((_g = (_f = field.options) === null || _f === void 0 ? void 0 : _f.userFilterTags) === null || _g === void 0 ? void 0 : _g.length) {
|
|
1906
|
+
bookingURL += "&userFilterTags=".concat(field.options.userFilterTags
|
|
1907
|
+
.flatMap(function (t) {
|
|
1908
|
+
var _a, _b;
|
|
1909
|
+
// set dynamic tags if found
|
|
1910
|
+
if (t === '{{logic}}') {
|
|
1911
|
+
return new URL(window.location.href).searchParams.get('logic') || '{{logic}}';
|
|
1912
|
+
}
|
|
1913
|
+
if (t.startsWith("{{field.") && t.endsWith(".value}}")) {
|
|
1914
|
+
var fieldId_2 = t.replace('{{field.', '').replace(".value}}", '');
|
|
1915
|
+
var answer = (_a = responses === null || responses === void 0 ? void 0 : responses.find(function (r) { return r.fieldId === fieldId_2; })) === null || _a === void 0 ? void 0 : _a.answer;
|
|
1916
|
+
if (!(answer === null || answer === void 0 ? void 0 : answer.value))
|
|
1917
|
+
return t;
|
|
1918
|
+
if (answer.type === 'Insurance') {
|
|
1919
|
+
return answer.value.payerName || '';
|
|
1920
|
+
}
|
|
1921
|
+
if (Array.isArray(answer.value) && typeof ((_b = answer.value) === null || _b === void 0 ? void 0 : _b[0]) === 'string') {
|
|
1922
|
+
return answer.value;
|
|
1923
|
+
}
|
|
1924
|
+
return (0, utilities_1.form_response_value_to_string)(answer.value);
|
|
1925
|
+
}
|
|
1926
|
+
return t;
|
|
1927
|
+
})
|
|
1928
|
+
.join(','));
|
|
1929
|
+
}
|
|
1930
|
+
// need to use form?.id for internally-submitted forms because formResponseId isn't generated until initial submission or saved draft
|
|
1931
|
+
if (((_h = field.options) === null || _h === void 0 ? void 0 : _h.holdAppointmentMinutes) && (formResponseId || (field === null || field === void 0 ? void 0 : field.id))) {
|
|
1932
|
+
bookingURL += "&formResponseId=".concat(formResponseId || (field === null || field === void 0 ? void 0 : field.id));
|
|
1933
|
+
bookingURL += "&holdAppointmentMinutes=".concat(field.options.holdAppointmentMinutes);
|
|
1934
|
+
}
|
|
1935
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 1, sx: { mt: 1 } }, { children: [!!((_k = (_j = field.options) === null || _j === void 0 ? void 0 : _j.userFilterTags) === null || _k === void 0 ? void 0 : _k.length) && !((_l = field.options.userTags) === null || _l === void 0 ? void 0 : _l.length) && !(isPreviousDisabled === null || isPreviousDisabled === void 0 ? void 0 : isPreviousDisabled()) && !confirming &&
|
|
1936
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, alignSelf: "flex-start" }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ variant: "outlined", onClick: goToPreviousField, sx: { height: 25, p: 0.5, px: 1 } }, { children: "Back" })) })), loaded.warningMessage &&
|
|
1937
|
+
(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error", sx: { fontSize: 20, fontWeight: 'bold' } }, { children: loaded.warningMessage })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (!loaded.warningMessage || acknowledgedWarning)
|
|
1938
|
+
? ((0, jsx_runtime_1.jsx)("iframe", { title: "Appointment Booking Embed", src: bookingURL, style: { border: 'none', width: '100%', height: height } }))
|
|
1939
|
+
: ((0, jsx_runtime_1.jsx)(material_1.Button, __assign({ variant: "outlined", onClick: function () { return setAcknowledgedWarning(true); } }, { children: "Show Booking Page Preview" }))) }))] })));
|
|
1940
|
+
};
|
|
1941
|
+
exports.AppointmentBookingInput = AppointmentBookingInput;
|
|
1942
|
+
var HeightInput = function (_a) {
|
|
1943
|
+
var _b;
|
|
1944
|
+
var field = _a.field, _d = _a.value, value = _d === void 0 ? {} : _d, onChange = _a.onChange, props = __rest(_a, ["field", "value", "onChange"]);
|
|
1945
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: 'center', wrap: "nowrap", spacing: 1, style: { marginTop: 5 } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { width: '100%' } }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, size: "small", label: "Feet", type: "number", value: (value === null || value === void 0 ? void 0 : value.feet) || '', onChange: function (e) { return onChange(__assign(__assign({}, value), { feet: parseInt(e.target.value) }), field.id); } }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { width: '100%' } }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, size: "small", label: "Inches", type: "number", value: (_b = value === null || value === void 0 ? void 0 : value.inches) !== null && _b !== void 0 ? _b : '', onChange: function (e) { return onChange(__assign(__assign({}, value), { inches: parseInt(e.target.value) }), field.id); } }) }))] })));
|
|
1946
|
+
};
|
|
1947
|
+
exports.HeightInput = HeightInput;
|
|
1948
|
+
var include_current_url_parameters_if_templated = function (url) {
|
|
1949
|
+
try {
|
|
1950
|
+
// get parameters from the current URL, and replace all values where {{URL_PARAM.paramName}} is used
|
|
1951
|
+
var params_1 = new URL(window.location.href).searchParams;
|
|
1952
|
+
return url.replace(/{{URL_PARAM\.(.*?)}}/g, function (_, paramName) {
|
|
1953
|
+
var value = params_1.get(paramName);
|
|
1954
|
+
console.log(paramName, value);
|
|
1955
|
+
if (value === null)
|
|
1956
|
+
return '';
|
|
1957
|
+
return value;
|
|
1958
|
+
});
|
|
1959
|
+
}
|
|
1960
|
+
catch (err) {
|
|
1961
|
+
console.error(err);
|
|
1962
|
+
}
|
|
1963
|
+
return url;
|
|
1964
|
+
};
|
|
1965
|
+
exports.include_current_url_parameters_if_templated = include_current_url_parameters_if_templated;
|
|
1966
|
+
var RedirectInput = function (_a) {
|
|
1967
|
+
var _b, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
1968
|
+
var enduserId = _a.enduserId, groupId = _a.groupId, groupInsance = _a.groupInsance, rootResponseId = _a.rootResponseId, formResponseId = _a.formResponseId, field = _a.field, submit = _a.submit, _u = _a.value, value = _u === void 0 ? {} : _u, onChange = _a.onChange, responses = _a.responses, enduser = _a.enduser, props = __rest(_a, ["enduserId", "groupId", "groupInsance", "rootResponseId", "formResponseId", "field", "submit", "value", "onChange", "responses", "enduser"]);
|
|
1969
|
+
var session = (0, __1.useResolvedSession)();
|
|
1970
|
+
var eId = '';
|
|
1971
|
+
try {
|
|
1972
|
+
eId = new URL(window.location.href).searchParams.get('eId') || enduserId || (enduser === null || enduser === void 0 ? void 0 : enduser.id) || '';
|
|
1973
|
+
}
|
|
1974
|
+
catch (err) { }
|
|
1975
|
+
var email = (((_d = (_b = responses === null || responses === void 0 ? void 0 : responses.find(function (r) { return r.intakeField === 'email'; })) === null || _b === void 0 ? void 0 : _b.answer) === null || _d === void 0 ? void 0 : _d.value)
|
|
1976
|
+
|| (enduser === null || enduser === void 0 ? void 0 : enduser.email)
|
|
1977
|
+
|| session.userInfo.email);
|
|
1978
|
+
var phone = (((_f = (_e = responses === null || responses === void 0 ? void 0 : responses.find(function (r) { return r.intakeField === 'phone'; })) === null || _e === void 0 ? void 0 : _e.answer) === null || _f === void 0 ? void 0 : _f.value)
|
|
1979
|
+
|| (enduser === null || enduser === void 0 ? void 0 : enduser.phone)
|
|
1980
|
+
|| session.userInfo.phone);
|
|
1981
|
+
var fname = (((_h = (_g = responses === null || responses === void 0 ? void 0 : responses.find(function (r) { return r.intakeField === 'fname'; })) === null || _g === void 0 ? void 0 : _g.answer) === null || _h === void 0 ? void 0 : _h.value)
|
|
1982
|
+
|| (enduser === null || enduser === void 0 ? void 0 : enduser.fname)
|
|
1983
|
+
|| ((_j = session.userInfo) === null || _j === void 0 ? void 0 : _j.fname));
|
|
1984
|
+
var lname = (((_l = (_k = responses === null || responses === void 0 ? void 0 : responses.find(function (r) { return r.intakeField === 'lname'; })) === null || _k === void 0 ? void 0 : _k.answer) === null || _l === void 0 ? void 0 : _l.value)
|
|
1985
|
+
|| (enduser === null || enduser === void 0 ? void 0 : enduser.lname)
|
|
1986
|
+
|| ((_m = session.userInfo) === null || _m === void 0 ? void 0 : _m.lname));
|
|
1987
|
+
var state = (((_p = (_o = responses === null || responses === void 0 ? void 0 : responses.find(function (r) { return r.intakeField === 'state'; })) === null || _o === void 0 ? void 0 : _o.answer) === null || _p === void 0 ? void 0 : _p.value)
|
|
1988
|
+
|| ((_s = (_r = (_q = responses === null || responses === void 0 ? void 0 : responses.find(function (r) { return r.intakeField === 'Address'; })) === null || _q === void 0 ? void 0 : _q.answer) === null || _r === void 0 ? void 0 : _r.value) === null || _s === void 0 ? void 0 : _s.state)
|
|
1989
|
+
|| (enduser === null || enduser === void 0 ? void 0 : enduser.state)
|
|
1990
|
+
|| ((_t = session.userInfo) === null || _t === void 0 ? void 0 : _t.state));
|
|
1991
|
+
(0, react_1.useEffect)(function () {
|
|
1992
|
+
var _a, _b;
|
|
1993
|
+
if (session.type === 'user') {
|
|
1994
|
+
return;
|
|
1995
|
+
}
|
|
1996
|
+
if ((_a = field.options) === null || _a === void 0 ? void 0 : _a.redirectExternalUrl) {
|
|
1997
|
+
submit === null || submit === void 0 ? void 0 : submit().finally(function () {
|
|
1998
|
+
var _a;
|
|
1999
|
+
if (!((_a = field.options) === null || _a === void 0 ? void 0 : _a.redirectExternalUrl)) {
|
|
2000
|
+
return;
|
|
2001
|
+
}
|
|
2002
|
+
window.location.href = ((0, exports.include_current_url_parameters_if_templated)((0, utilities_1.replace_enduser_template_values)(field.options.redirectExternalUrl, __assign(__assign({}, session.userInfo), { id: eId, email: email, fname: fname, lname: lname, state: state, phone: phone }))));
|
|
2003
|
+
}).catch(console.error);
|
|
2004
|
+
return;
|
|
2005
|
+
}
|
|
2006
|
+
if (!((_b = field.options) === null || _b === void 0 ? void 0 : _b.redirectFormId)) {
|
|
2007
|
+
return;
|
|
2008
|
+
}
|
|
2009
|
+
session.api.form_responses.prepare_form_response({
|
|
2010
|
+
enduserId: session.userInfo.id || eId,
|
|
2011
|
+
formId: field.options.redirectFormId,
|
|
2012
|
+
rootResponseId: rootResponseId || formResponseId,
|
|
2013
|
+
parentResponseId: formResponseId,
|
|
2014
|
+
})
|
|
2015
|
+
.then(function (_a) {
|
|
2016
|
+
var fullURL = _a.fullURL;
|
|
2017
|
+
return (
|
|
2018
|
+
// we should still redirect even if submission fails
|
|
2019
|
+
submit === null || submit === void 0 ? void 0 : submit().catch(console.error).finally(function () {
|
|
2020
|
+
// if accessing form group in portal
|
|
2021
|
+
if (window.location.href.includes('/documents') && groupId && groupInsance) {
|
|
2022
|
+
var toRedirect = "".concat(window.location.origin, "/documents?groupId=").concat(groupId, "&groupInstance=").concat(groupInsance);
|
|
2023
|
+
if (fullURL.endsWith('&')) {
|
|
2024
|
+
window.location.replace(fullURL + "back=".concat(toRedirect, "&"));
|
|
2025
|
+
}
|
|
2026
|
+
else {
|
|
2027
|
+
window.location.replace(fullURL + "&back=".concat(toRedirect));
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
else {
|
|
2031
|
+
window.location.replace(fullURL);
|
|
2032
|
+
}
|
|
2033
|
+
}));
|
|
2034
|
+
})
|
|
2035
|
+
.catch(console.error);
|
|
2036
|
+
}, [session, email, fname, lname, state, phone]);
|
|
2037
|
+
if (session.type === 'user') {
|
|
2038
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Typography, { children: "Redirect is for patient-facing forms only" }));
|
|
2039
|
+
}
|
|
2040
|
+
return null;
|
|
2041
|
+
};
|
|
2042
|
+
exports.RedirectInput = RedirectInput;
|
|
2043
|
+
var HiddenValueInput = function (_a) {
|
|
2044
|
+
var goToNextField = _a.goToNextField, goToPreviousField = _a.goToPreviousField, field = _a.field, value = _a.value, onChange = _a.onChange, isSinglePage = _a.isSinglePage, groupFields = _a.groupFields;
|
|
2045
|
+
var lastRef = (0, react_1.useRef)(0);
|
|
2046
|
+
var lastIdRef = (0, react_1.useRef)('');
|
|
2047
|
+
// in a Question Group, only the first Hidden Value should navigate
|
|
2048
|
+
// AND, it should only navigate if the group only contains hidden values
|
|
2049
|
+
var firstHiddenValue = groupFields === null || groupFields === void 0 ? void 0 : groupFields.find(function (v) { return v.type === 'Hidden Value'; });
|
|
2050
|
+
var dontNavigate = ((firstHiddenValue && (firstHiddenValue === null || firstHiddenValue === void 0 ? void 0 : firstHiddenValue.id) !== field.id) // is in a group, but not the first hidden value
|
|
2051
|
+
|| !!(groupFields === null || groupFields === void 0 ? void 0 : groupFields.find(function (v) { return v.type !== 'Hidden Value'; })) // group contains at least 1 non-hidden value
|
|
2052
|
+
);
|
|
2053
|
+
var publicIdentifier = (0, react_1.useMemo)(function () {
|
|
2054
|
+
try {
|
|
2055
|
+
return new URL(window.location.href).searchParams.get('publicIdentifier') || '';
|
|
2056
|
+
}
|
|
2057
|
+
catch (err) {
|
|
2058
|
+
return '';
|
|
2059
|
+
}
|
|
2060
|
+
}, []);
|
|
2061
|
+
var valueToSet = (0, react_1.useMemo)(function () { return ((field.title === "{{PUBLIC_IDENTIFIER}}" && publicIdentifier) ? publicIdentifier
|
|
2062
|
+
: field.title); }, [field.title, publicIdentifier]);
|
|
2063
|
+
(0, react_1.useEffect)(function () {
|
|
2064
|
+
if (lastRef.current > Date.now() - 1000 && lastIdRef.current === field.id)
|
|
2065
|
+
return;
|
|
2066
|
+
lastRef.current = Date.now();
|
|
2067
|
+
lastIdRef.current = field.id;
|
|
2068
|
+
if (value) {
|
|
2069
|
+
if (isSinglePage)
|
|
2070
|
+
return;
|
|
2071
|
+
onChange('', field.id);
|
|
2072
|
+
if (dontNavigate)
|
|
2073
|
+
return;
|
|
2074
|
+
goToPreviousField === null || goToPreviousField === void 0 ? void 0 : goToPreviousField();
|
|
2075
|
+
}
|
|
2076
|
+
else {
|
|
2077
|
+
onChange(valueToSet, field.id);
|
|
2078
|
+
if (dontNavigate)
|
|
2079
|
+
return;
|
|
2080
|
+
// pass value that is set after above onChange
|
|
2081
|
+
goToNextField === null || goToNextField === void 0 ? void 0 : goToNextField({ type: 'Hidden Value', value: valueToSet });
|
|
2082
|
+
}
|
|
2083
|
+
}, [value, onChange, field.id, valueToSet, goToNextField, goToPreviousField, isSinglePage, dontNavigate]);
|
|
2084
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
|
|
2085
|
+
};
|
|
2086
|
+
exports.HiddenValueInput = HiddenValueInput;
|
|
2087
|
+
var EmotiiInput = function (_a) {
|
|
2088
|
+
var goToNextField = _a.goToNextField, goToPreviousField = _a.goToPreviousField, field = _a.field, value = _a.value, onChange = _a.onChange, form = _a.form, formResponseId = _a.formResponseId, props = __rest(_a, ["goToNextField", "goToPreviousField", "field", "value", "onChange", "form", "formResponseId"]);
|
|
2089
|
+
var session = (0, __1.useResolvedSession)();
|
|
2090
|
+
var requestIdRef = (0, react_1.useRef)(value || "".concat(field.id).concat(formResponseId || Date.now()));
|
|
2091
|
+
var _b = (0, react_1.useState)(), data = _b[0], setData = _b[1];
|
|
2092
|
+
var _d = (0, react_1.useState)(0), loadCount = _d[0], setLoadCount = _d[1];
|
|
2093
|
+
var fetchRef = (0, react_1.useRef)(false);
|
|
2094
|
+
(0, react_1.useEffect)(function () {
|
|
2095
|
+
if (value)
|
|
2096
|
+
return;
|
|
2097
|
+
if (fetchRef.current)
|
|
2098
|
+
return;
|
|
2099
|
+
fetchRef.current = true;
|
|
2100
|
+
session.api.integrations
|
|
2101
|
+
.proxy_read({
|
|
2102
|
+
integration: constants_1.EMOTII_TITLE,
|
|
2103
|
+
type: 'get_survey',
|
|
2104
|
+
id: props === null || props === void 0 ? void 0 : props.enduserId,
|
|
2105
|
+
query: requestIdRef.current,
|
|
2106
|
+
})
|
|
2107
|
+
.then(function (r) { return setData(r.data); });
|
|
2108
|
+
}, [session, value, props === null || props === void 0 ? void 0 : props.enduserId]);
|
|
2109
|
+
var loadAnswerRef = (0, react_1.useRef)(false);
|
|
2110
|
+
(0, react_1.useEffect)(function () {
|
|
2111
|
+
if (loadCount !== 2)
|
|
2112
|
+
return;
|
|
2113
|
+
if (loadAnswerRef.current)
|
|
2114
|
+
return;
|
|
2115
|
+
loadAnswerRef.current = true;
|
|
2116
|
+
onChange(requestIdRef.current, field.id);
|
|
2117
|
+
}, [loadCount]);
|
|
2118
|
+
if (value || loadCount === 2)
|
|
2119
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap" }, { children: [(0, jsx_runtime_1.jsx)(icons_material_1.CheckCircleOutline, { color: "success" }), (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ sx: { ml: 1, fontSize: 20 } }, { children: "Please click Next or Submit to continue." }))] })));
|
|
2120
|
+
if (!data) {
|
|
2121
|
+
return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
|
|
2122
|
+
}
|
|
2123
|
+
return ((0, jsx_runtime_1.jsx)("iframe", { src: data.surveyUrl, style: { border: 'none', height: 650, width: '100%' }, onLoad: function () { return setLoadCount(function (l) { return l + 1; }); } }));
|
|
2124
|
+
};
|
|
2125
|
+
exports.EmotiiInput = EmotiiInput;
|
|
2126
|
+
var AllergiesInput = function (_a) {
|
|
2127
|
+
var _b;
|
|
2128
|
+
var goToNextField = _a.goToNextField, goToPreviousField = _a.goToPreviousField, field = _a.field, value = _a.value, onChange = _a.onChange, form = _a.form, formResponseId = _a.formResponseId, props = __rest(_a, ["goToNextField", "goToPreviousField", "field", "value", "onChange", "form", "formResponseId"]);
|
|
2129
|
+
var session = (0, __1.useResolvedSession)();
|
|
2130
|
+
var _d = (0, react_1.useState)(''), query = _d[0], setQuery = _d[1];
|
|
2131
|
+
var _e = (0, react_1.useState)([]), results = _e[0], setResults = _e[1];
|
|
2132
|
+
// if two allergy questions shown in a row, reset state
|
|
2133
|
+
(0, react_1.useEffect)(function () {
|
|
2134
|
+
setQuery('');
|
|
2135
|
+
setResults([]);
|
|
2136
|
+
}, [field.id]);
|
|
2137
|
+
var fetchRef = (0, react_1.useRef)(query);
|
|
2138
|
+
(0, react_1.useEffect)(function () {
|
|
2139
|
+
if (fetchRef.current === query)
|
|
2140
|
+
return;
|
|
2141
|
+
fetchRef.current = query;
|
|
2142
|
+
if (!query)
|
|
2143
|
+
return;
|
|
2144
|
+
var t = setTimeout(function () {
|
|
2145
|
+
var _a;
|
|
2146
|
+
if (((_a = field.options) === null || _a === void 0 ? void 0 : _a.dataSource) === constants_1.CANVAS_TITLE) {
|
|
2147
|
+
session.api.integrations
|
|
2148
|
+
.proxy_read({
|
|
2149
|
+
integration: constants_1.CANVAS_TITLE,
|
|
2150
|
+
type: 'allergies',
|
|
2151
|
+
query: query,
|
|
2152
|
+
})
|
|
2153
|
+
.then(function (r) {
|
|
2154
|
+
var deduped = [];
|
|
2155
|
+
var totalResults = ((r.data.entry || [])
|
|
2156
|
+
.flatMap(function (v) { var _a, _b; return ((_b = (_a = v === null || v === void 0 ? void 0 : v.resource) === null || _a === void 0 ? void 0 : _a.code) === null || _b === void 0 ? void 0 : _b.coding) || []; })
|
|
2157
|
+
.filter(function (v) { return v.system.includes('fdbhealth'); })
|
|
2158
|
+
.map(function (v) { return ({ code: v.code, display: v.display, system: v.system }); }));
|
|
2159
|
+
var _loop_2 = function (v) {
|
|
2160
|
+
if (deduped.find(function (d) { return d.display === v.display; })) {
|
|
2161
|
+
return "continue";
|
|
2162
|
+
}
|
|
2163
|
+
deduped.push(v);
|
|
2164
|
+
};
|
|
2165
|
+
for (var _a = 0, totalResults_1 = totalResults; _a < totalResults_1.length; _a++) {
|
|
2166
|
+
var v = totalResults_1[_a];
|
|
2167
|
+
_loop_2(v);
|
|
2168
|
+
}
|
|
2169
|
+
setResults(deduped);
|
|
2170
|
+
});
|
|
2171
|
+
}
|
|
2172
|
+
else {
|
|
2173
|
+
session.api.allergy_codes.getSome({ search: { query: query } })
|
|
2174
|
+
.then(function (results) {
|
|
2175
|
+
var deduped = [];
|
|
2176
|
+
var _loop_3 = function (v) {
|
|
2177
|
+
if (deduped.find(function (d) { return d.display === v.display; })) {
|
|
2178
|
+
return "continue";
|
|
2179
|
+
}
|
|
2180
|
+
deduped.push(v);
|
|
2181
|
+
};
|
|
2182
|
+
for (var _a = 0, results_1 = results; _a < results_1.length; _a++) {
|
|
2183
|
+
var v = results_1[_a];
|
|
2184
|
+
_loop_3(v);
|
|
2185
|
+
}
|
|
2186
|
+
setResults(deduped);
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2189
|
+
}, 200);
|
|
2190
|
+
return function () { clearTimeout(t); };
|
|
2191
|
+
}, [session, query, (_b = field === null || field === void 0 ? void 0 : field.options) === null || _b === void 0 ? void 0 : _b.dataSource]);
|
|
2192
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, direction: "column", spacing: 1 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Autocomplete, { multiple: true, value: value || [], options: results, style: { marginTop: 5 }, noOptionsText: query.length ? 'No results found' : 'Type to start search', onChange: function (e, v) {
|
|
2193
|
+
if (!v) {
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
onChange(v, field.id);
|
|
2197
|
+
setResults([]);
|
|
2198
|
+
}, getOptionLabel: function (v) { return (0, utilities_1.first_letter_capitalized)(v.display); }, filterOptions: function (o) { return o; }, inputValue: query, onInputChange: function (e, v) { return e && setQuery(v); }, renderInput: function (params) { return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: exports.defaultInputProps.sx }), required: !field.isOptional, size: "small", label: "", placeholder: "Search allergies..." }))); }, renderTags: function (value, getTagProps) {
|
|
2199
|
+
return value.map(function (value, index) { return ((0, jsx_runtime_1.jsx)(material_1.Chip, __assign({ label: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ style: { whiteSpace: 'normal' } }, { children: value.display })) }, getTagProps({ index: index }), { sx: { height: "100%", py: 0.5 } }))); });
|
|
2200
|
+
} }) })), (value || []).map(function (allergy, i) { return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap", columnGap: 0.5, justifyContent: "space-between" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ noWrap: true, sx: { width: 85, fontSize: 14 } }, { children: allergy.display })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { width: 140 } }, { children: (0, jsx_runtime_1.jsx)(StringSelector, { options: ['mild', 'moderate', 'severe'], size: "small", label: "Severity", value: allergy.severity || '', onChange: function (severity) { return onChange((value || []).map(function (v, _i) { return i === _i ? __assign(__assign({}, v), { severity: severity }) : v; }), field.id); }, getDisplayValue: utilities_1.first_letter_capitalized }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, sx: { width: "50%" } }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { InputProps: { sx: exports.defaultInputProps.sx }, fullWidth: true, size: "small", label: "Note", value: allergy.note || '', onChange: function (e) { return onChange((value || []).map(function (v, _i) { return i === _i ? __assign(__assign({}, v), { note: e.target.value }) : v; }), field.id); } }) }))] })) }), i)); })] })));
|
|
2201
|
+
};
|
|
2202
|
+
exports.AllergiesInput = AllergiesInput;
|
|
2203
|
+
var display_with_code = function (v) { return "".concat(v.code, ": ").concat((0, utilities_1.first_letter_capitalized)(v.display)); };
|
|
2204
|
+
var ConditionsInput = function (_a) {
|
|
2205
|
+
var goToNextField = _a.goToNextField, goToPreviousField = _a.goToPreviousField, field = _a.field, value = _a.value, onChange = _a.onChange, form = _a.form, formResponseId = _a.formResponseId, props = __rest(_a, ["goToNextField", "goToPreviousField", "field", "value", "onChange", "form", "formResponseId"]);
|
|
2206
|
+
var session = (0, __1.useResolvedSession)();
|
|
2207
|
+
var _b = (0, react_1.useState)(''), query = _b[0], setQuery = _b[1];
|
|
2208
|
+
var _d = (0, react_1.useState)([]), results = _d[0], setResults = _d[1];
|
|
2209
|
+
var fetchRef = (0, react_1.useRef)(query);
|
|
2210
|
+
(0, react_1.useEffect)(function () {
|
|
2211
|
+
if (fetchRef.current === query)
|
|
2212
|
+
return;
|
|
2213
|
+
fetchRef.current = query;
|
|
2214
|
+
if (!query)
|
|
2215
|
+
return;
|
|
2216
|
+
var t = setTimeout(function () {
|
|
2217
|
+
session.api.diagnosis_codes.getSome({ search: { query: query } })
|
|
2218
|
+
.then(function (codes) {
|
|
2219
|
+
var deduped = [];
|
|
2220
|
+
var _loop_4 = function (v) {
|
|
2221
|
+
if (deduped.find(function (d) { return d.display === v.display; })) {
|
|
2222
|
+
return "continue";
|
|
2223
|
+
}
|
|
2224
|
+
deduped.push(v);
|
|
2225
|
+
};
|
|
2226
|
+
for (var _a = 0, codes_1 = codes; _a < codes_1.length; _a++) {
|
|
2227
|
+
var v = codes_1[_a];
|
|
2228
|
+
_loop_4(v);
|
|
2229
|
+
}
|
|
2230
|
+
setResults(deduped);
|
|
2231
|
+
});
|
|
2232
|
+
}, 200);
|
|
2233
|
+
return function () { clearTimeout(t); };
|
|
2234
|
+
}, [session, query]);
|
|
2235
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Autocomplete, { multiple: true, value: value || [], options: results, style: { marginTop: 5 }, noOptionsText: query.length ? 'No results found' : 'Type to start search', onChange: function (e, v) {
|
|
2236
|
+
if (!v) {
|
|
2237
|
+
return;
|
|
2238
|
+
}
|
|
2239
|
+
onChange(v, field.id);
|
|
2240
|
+
setResults([]);
|
|
2241
|
+
}, getOptionLabel: display_with_code, filterOptions: function (o) { return o; }, inputValue: query, onInputChange: function (e, v) { return e && setQuery(v); }, renderInput: function (params) { return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: exports.defaultInputProps.sx }), required: !field.isOptional, size: "small", label: "", placeholder: "Search conditions..." }))); }, renderTags: function (value, getTagProps) {
|
|
2242
|
+
return value.map(function (value, index) { return ((0, jsx_runtime_1.jsx)(material_1.Chip, __assign({ label: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ style: { whiteSpace: 'normal' } }, { children: display_with_code(value) })) }, getTagProps({ index: index }), { sx: { height: "100%", py: 0.5 } }))); });
|
|
2243
|
+
} }));
|
|
2244
|
+
};
|
|
2245
|
+
exports.ConditionsInput = ConditionsInput;
|
|
2246
|
+
var RichTextInput = function (_a) {
|
|
2247
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange;
|
|
2248
|
+
return ((0, jsx_runtime_1.jsx)(wysiwyg_1.WYSIWYG, { stopEnterPropagation: true, initialHTML: value, onChange: function (v) { return onChange(v, field.id); }, style: { width: '100%' }, editorStyle: { width: '100%' } }));
|
|
2249
|
+
};
|
|
2250
|
+
exports.RichTextInput = RichTextInput;
|
|
2251
|
+
var ChargeebeeInput = function (_a) {
|
|
2252
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange, setCustomerId = _a.setCustomerId;
|
|
2253
|
+
var session = (0, __1.useResolvedSession)();
|
|
2254
|
+
var _b = (0, react_1.useState)(''), url = _b[0], setUrl = _b[1];
|
|
2255
|
+
var _d = (0, react_1.useState)(''), error = _d[0], setError = _d[1];
|
|
2256
|
+
var _e = (0, react_1.useState)(0), loadCount = _e[0], setLoadCount = _e[1];
|
|
2257
|
+
var fetchRef = (0, react_1.useRef)(false);
|
|
2258
|
+
(0, react_1.useEffect)(function () {
|
|
2259
|
+
if (fetchRef.current)
|
|
2260
|
+
return;
|
|
2261
|
+
fetchRef.current = true;
|
|
2262
|
+
session.api.form_responses.chargebee_details({ fieldId: field.id })
|
|
2263
|
+
.then(function (_a) {
|
|
2264
|
+
var url = _a.url;
|
|
2265
|
+
return setUrl(url);
|
|
2266
|
+
})
|
|
2267
|
+
.catch(setError);
|
|
2268
|
+
}, [session]);
|
|
2269
|
+
var loadAnswerRef = (0, react_1.useRef)(false);
|
|
2270
|
+
(0, react_1.useEffect)(function () {
|
|
2271
|
+
if (loadCount !== 2)
|
|
2272
|
+
return;
|
|
2273
|
+
if (loadAnswerRef.current)
|
|
2274
|
+
return;
|
|
2275
|
+
loadAnswerRef.current = true;
|
|
2276
|
+
onChange({ url: url }, field.id);
|
|
2277
|
+
}, [loadCount, url]);
|
|
2278
|
+
if (value || loadCount === 2) {
|
|
2279
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap" }, { children: [(0, jsx_runtime_1.jsx)(icons_material_1.CheckCircleOutline, { color: "success" }), (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ sx: { ml: 1, fontSize: 20 } }, { children: "Your purchase was successful" }))] })));
|
|
2280
|
+
}
|
|
2281
|
+
if (error && typeof error === 'string')
|
|
2282
|
+
return (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error" }, { children: error }));
|
|
2283
|
+
if (!url)
|
|
2284
|
+
return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
|
|
2285
|
+
return ((0, jsx_runtime_1.jsx)("iframe", { src: url, title: "Checkout", style: { border: 'none', width: '100%', height: 700 }, onLoad: function () { return setLoadCount(function (l) { return l + 1; }); } }));
|
|
2286
|
+
};
|
|
2287
|
+
exports.ChargeebeeInput = ChargeebeeInput;
|
|
2288
|
+
var templateObject_1, templateObject_2;
|
|
2289
|
+
//# sourceMappingURL=inputs.v2.js.map
|