@tellescope/react-components 1.231.0 → 1.232.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/lib/cjs/Forms/forms.js +1 -1
  2. package/lib/cjs/Forms/forms.js.map +1 -1
  3. package/lib/cjs/Forms/forms.v2.d.ts +1 -1
  4. package/lib/cjs/Forms/forms.v2.js +1 -1
  5. package/lib/cjs/Forms/forms.v2.js.map +1 -1
  6. package/lib/cjs/Forms/hooks.d.ts.map +1 -1
  7. package/lib/cjs/Forms/hooks.js +24 -0
  8. package/lib/cjs/Forms/hooks.js.map +1 -1
  9. package/lib/cjs/Forms/inputs.d.ts +6 -3
  10. package/lib/cjs/Forms/inputs.d.ts.map +1 -1
  11. package/lib/cjs/Forms/inputs.js +171 -44
  12. package/lib/cjs/Forms/inputs.js.map +1 -1
  13. package/lib/cjs/Forms/inputs.v2.d.ts +7 -11
  14. package/lib/cjs/Forms/inputs.v2.d.ts.map +1 -1
  15. package/lib/cjs/Forms/inputs.v2.js +16 -445
  16. package/lib/cjs/Forms/inputs.v2.js.map +1 -1
  17. package/lib/esm/CMS/components.d.ts +0 -1
  18. package/lib/esm/CMS/components.d.ts.map +1 -1
  19. package/lib/esm/Forms/form_responses.d.ts +0 -1
  20. package/lib/esm/Forms/form_responses.d.ts.map +1 -1
  21. package/lib/esm/Forms/forms.d.ts +3 -3
  22. package/lib/esm/Forms/forms.js +1 -1
  23. package/lib/esm/Forms/forms.js.map +1 -1
  24. package/lib/esm/Forms/forms.v2.d.ts +4 -4
  25. package/lib/esm/Forms/forms.v2.js +1 -1
  26. package/lib/esm/Forms/forms.v2.js.map +1 -1
  27. package/lib/esm/Forms/hooks.d.ts +0 -1
  28. package/lib/esm/Forms/hooks.d.ts.map +1 -1
  29. package/lib/esm/Forms/hooks.js +24 -0
  30. package/lib/esm/Forms/hooks.js.map +1 -1
  31. package/lib/esm/Forms/inputs.d.ts +7 -4
  32. package/lib/esm/Forms/inputs.d.ts.map +1 -1
  33. package/lib/esm/Forms/inputs.js +173 -46
  34. package/lib/esm/Forms/inputs.js.map +1 -1
  35. package/lib/esm/Forms/inputs.v2.d.ts +8 -12
  36. package/lib/esm/Forms/inputs.v2.d.ts.map +1 -1
  37. package/lib/esm/Forms/inputs.v2.js +17 -446
  38. package/lib/esm/Forms/inputs.v2.js.map +1 -1
  39. package/lib/esm/controls.d.ts +2 -2
  40. package/lib/esm/inputs.d.ts +1 -1
  41. package/lib/esm/inputs.native.d.ts +0 -1
  42. package/lib/esm/inputs.native.d.ts.map +1 -1
  43. package/lib/esm/state.d.ts +315 -315
  44. package/lib/tsconfig.tsbuildinfo +1 -1
  45. package/package.json +9 -9
  46. package/src/Forms/forms.tsx +1 -1
  47. package/src/Forms/forms.v2.tsx +1 -1
  48. package/src/Forms/hooks.tsx +33 -5
  49. package/src/Forms/inputs.tsx +224 -35
  50. package/src/Forms/inputs.v2.tsx +20 -639
@@ -3,7 +3,7 @@ import { SxProps, TextFieldProps } from "@mui/material";
3
3
  import { FormInputProps } from "./types";
4
4
  import { Enduser, FormResponseValue } from "@tellescope/types-models";
5
5
  import { FileBlob, Styled } from "..";
6
- import { DatabaseRecord, FormField } from "@tellescope/types-client";
6
+ import { FormField } from "@tellescope/types-client";
7
7
  export declare const LanguageSelect: ({ value, ...props }: {
8
8
  value: string;
9
9
  onChange: (s: string) => void;
@@ -45,28 +45,24 @@ export declare const FilesInput: ({ value, onChange, field, existingFileName, up
45
45
  existingFileName?: string | undefined;
46
46
  }) => JSX.Element;
47
47
  export declare const MultipleChoiceInput: ({ field, form, value: _value, onChange }: FormInputProps<'multiple_choice'>) => JSX.Element;
48
- export declare const StripeInput: ({ field, value, onChange, setCustomerId, enduserId }: FormInputProps<"Stripe"> & {
49
- setCustomerId: React.Dispatch<React.SetStateAction<string | undefined>>;
50
- }) => JSX.Element;
48
+ export { StripeInput } from './inputs';
51
49
  export declare const Progress: ({ numerator, denominator, style, color }: {
52
50
  numerator: number;
53
51
  denominator: number;
54
52
  color?: string | undefined;
55
53
  } & Styled) => JSX.Element;
56
54
  export declare const DropdownInput: ({ field, value, onChange }: FormInputProps<'Dropdown'>) => JSX.Element;
57
- export interface AddToDatabaseProps {
58
- databaseId: string;
59
- onAdd: (record: DatabaseRecord) => void;
60
- }
61
- export declare const DatabaseSelectInput: ({ AddToDatabase, field, value: _value, onChange, onDatabaseSelect, responses, size, disabled, enduser }: FormInputProps<"Database Select"> & {
55
+ import { AddToDatabaseProps as AddToDatabasePropsImported } from './inputs';
56
+ export type AddToDatabaseProps = AddToDatabasePropsImported;
57
+ export declare const DatabaseSelectInput: (props: FormInputProps<'Database Select'> & {
62
58
  responses: FormResponseValue[];
63
- AddToDatabase?: React.JSXElementConstructor<AddToDatabaseProps> | undefined;
59
+ AddToDatabase?: React.JSXElementConstructor<AddToDatabaseProps>;
64
60
  }) => JSX.Element;
65
61
  export declare const CanvasMedicationsInput: ({ field, value, onChange }: FormInputProps<'Medications'>) => JSX.Element;
66
62
  export declare const MedicationsInput: ({ field, value, onChange, ...props }: FormInputProps<'Medications'>) => JSX.Element;
67
63
  export declare const BelugaPatientPreferenceInput: ({ field, value: _value, onChange }: FormInputProps<'Beluga Patient Preference'>) => JSX.Element;
68
64
  export declare const contact_is_valid: (e: Partial<Enduser>) => "Email is invalid" | "Phone is invalid" | "Date of birth should be MM-DD-YYYY" | undefined;
69
- export declare const RelatedContactsInput: ({ field, value: _value, onChange, ...props }: FormInputProps<'Related Contacts'>) => JSX.Element;
65
+ export declare const RelatedContactsInput: ({ field, value: _value, onChange, error: parentError, ...props }: FormInputProps<'Related Contacts'>) => JSX.Element;
70
66
  export declare const AppointmentBookingInput: ({ formResponseId, field, value, onChange, form, responses, goToPreviousField, isPreviousDisabled, enduserId, ...props }: FormInputProps<'Appointment Booking'>) => JSX.Element;
71
67
  export declare const HeightInput: ({ field, value, onChange, ...props }: FormInputProps<'Height'>) => JSX.Element;
72
68
  export declare const include_current_url_parameters_if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,eAAO,MAAM,4BAA4B,uCAAwC,eAAe,2BAA2B,CAAC,gBAoK3H,CAAA;AAED,eAAO,MAAM,gBAAgB,MAAO,QAAQ,OAAO,CAAC,+FAkBnD,CAAA;AAED,eAAO,MAAM,oBAAoB,qEAAsE,eAAe,kBAAkB,CAAC,gBAiLxI,CAAA;AAED,eAAO,MAAM,uBAAuB,4HAA6H,eAAe,qBAAqB,CAAC,gBAyOrM,CAAA;AAED,eAAO,MAAM,WAAW,yCAAoD,eAAe,QAAQ,CAAC,gBAenG,CAAA;AAED,eAAO,MAAM,2CAA2C,QAAS,MAAM,WAetE,CAAA;AAED,eAAO,MAAM,aAAa,uIAAkJ,eAAe,UAAU,CAAC,uBAkGrM,CAAA;AAED,eAAO,MAAM,gBAAgB,4FAA6F,eAAe,OAAO,CAAC,gBA+ChJ,CAAA;AAED,eAAO,MAAM,WAAW,iGAAkG,eAAe,OAAO,CAAC,gBA8ChJ,CAAA;AAMD,eAAO,MAAM,cAAc,iGAAkG,eAAe,WAAW,CAAC,gBAqHvJ,CAAA;AAGD,eAAO,MAAM,eAAe,iGAAkG,eAAe,YAAY,CAAC,gBAsDzJ,CAAA;AAED,eAAO,MAAM,aAAa,+BAAgC,eAAe,WAAW,CAAC,gBAEpF,CAAA;AAED,eAAO,MAAM,eAAe;mBACX,MAAM,QAAQ,CAAC,MAAM,cAAc,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;iBA6CxE,CAAA"}
@@ -118,8 +118,6 @@ var DragIndicator_1 = __importDefault(require("@mui/icons-material/DragIndicator
118
118
  var heic2any_1 = __importDefault(require("heic2any"));
119
119
  var AddPhotoAlternate_1 = __importDefault(require("@mui/icons-material/AddPhotoAlternate"));
120
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
121
  var icons_material_1 = require("@mui/icons-material");
124
122
  var wysiwyg_1 = require("./wysiwyg");
125
123
  var LanguageSelect = function (_a) {
@@ -858,212 +856,12 @@ var MultipleChoiceInput = function (_a) {
858
856
  } }) }))] })));
859
857
  };
860
858
  exports.MultipleChoiceInput = MultipleChoiceInput;
861
- var StripeInput = function (_a) {
862
- var _b, _d;
863
- var field = _a.field, value = _a.value, onChange = _a.onChange, setCustomerId = _a.setCustomerId, enduserId = _a.enduserId;
864
- var session = (0, __1.useResolvedSession)();
865
- var _e = (0, react_1.useState)(''), clientSecret = _e[0], setClientSecret = _e[1];
866
- var _f = (0, react_1.useState)(''), businessName = _f[0], setBusinessName = _f[1];
867
- var _g = (0, react_1.useState)(false), isCheckout = _g[0], setIsCheckout = _g[1];
868
- var _h = (0, react_1.useState)(), stripePromise = _h[0], setStripePromise = _h[1];
869
- var _j = (0, react_1.useState)(''), answertext = _j[0], setAnswertext = _j[1];
870
- var _k = (0, react_1.useState)(''), error = _k[0], setError = _k[1];
871
- var _l = (0, react_1.useState)([]), selectedProducts = _l[0], setSelectedProducts = _l[1];
872
- var _m = (0, react_1.useState)(false), showProductSelection = _m[0], setShowProductSelection = _m[1];
873
- var _o = (0, react_1.useState)([]), availableProducts = _o[0], setAvailableProducts = _o[1];
874
- var _p = (0, react_1.useState)(false), loadingProducts = _p[0], setLoadingProducts = _p[1];
875
- var fetchRef = (0, react_1.useRef)(false);
876
- (0, react_1.useEffect)(function () {
877
- var _a, _b, _d;
878
- if (fetchRef.current)
879
- return;
880
- if (value && ((_a = session.userInfo) === null || _a === void 0 ? void 0 : _a.stripeCustomerId)) {
881
- 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
882
- }
883
- // Check if product selection mode is enabled
884
- 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) {
885
- setShowProductSelection(true);
886
- setLoadingProducts(true);
887
- // Fetch product data with real-time Stripe pricing via proxy_read
888
- var productIds = (field.options.productIds || []).join(',');
889
- session.api.integrations.proxy_read({
890
- integration: 'Stripe',
891
- type: 'product-prices',
892
- id: productIds,
893
- query: field.options.stripeKey
894
- })
895
- .then(function (_a) {
896
- var data = _a.data;
897
- setAvailableProducts(data.products || []);
898
- setLoadingProducts(false);
899
- })
900
- .catch(function (e) {
901
- var _a, _b;
902
- console.error('Error loading product data:', e);
903
- 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:'))
904
- ? e.message.replace('Stripe pricing error: ', '')
905
- : 'Failed to load product information from Stripe';
906
- setError("Product configuration error: ".concat(errorMessage));
907
- setLoadingProducts(false);
908
- });
909
- return;
910
- }
911
- fetchRef.current = true;
912
- session.api.form_responses.stripe_details({ fieldId: field.id, enduserId: enduserId })
913
- .then(function (_a) {
914
- var clientSecret = _a.clientSecret, publishableKey = _a.publishableKey, stripeAccount = _a.stripeAccount, businessName = _a.businessName, customerId = _a.customerId, isCheckout = _a.isCheckout, answerText = _a.answerText;
915
- setAnswertext(answerText || '');
916
- setIsCheckout(!!isCheckout);
917
- setClientSecret(clientSecret);
918
- setStripePromise((0, stripe_js_1.loadStripe)(publishableKey, { stripeAccount: stripeAccount }));
919
- setBusinessName(businessName);
920
- setCustomerId(customerId);
921
- })
922
- .catch(function (e) {
923
- console.error(e);
924
- if (typeof (e === null || e === void 0 ? void 0 : e.message) === 'string') {
925
- setError(e.message);
926
- }
927
- });
928
- }, [session, value, field.id, enduserId]);
929
- var cost = (showProductSelection
930
- ? selectedProducts.reduce(function (total, productId) {
931
- var _a;
932
- var product = availableProducts.find(function (p) { return p._id === productId; });
933
- if (product === null || product === void 0 ? void 0 : product.currentPrice) {
934
- return total + (product.currentPrice.amount || 0);
935
- }
936
- return total + (((_a = product === null || product === void 0 ? void 0 : product.cost) === null || _a === void 0 ? void 0 : _a.amount) || 0);
937
- }, 0)
938
- : 0 // Will be calculated by existing Stripe flow when not in selection mode
939
- );
940
- // Handle product selection step
941
- if (showProductSelection) {
942
- if (error) {
943
- 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 })) }))] })));
944
- }
945
- if (loadingProducts) {
946
- 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..." }) }))] })));
947
- }
948
- var isSingleSelection_1 = ((_b = field.options) === null || _b === void 0 ? void 0 : _b.radio) === true;
949
- var handleProductSelection_1 = function (productId) {
950
- if (isSingleSelection_1) {
951
- setSelectedProducts([productId]);
952
- }
953
- else {
954
- setSelectedProducts(function (prev) {
955
- return prev.includes(productId)
956
- ? prev.filter(function (id) { return id !== productId; })
957
- : __spreadArray(__spreadArray([], prev, true), [productId], false);
958
- });
959
- }
960
- };
961
- var handleContinueToPayment = function () {
962
- if (selectedProducts.length === 0)
963
- return;
964
- setShowProductSelection(false);
965
- fetchRef.current = true;
966
- // Now fetch Stripe details with selected products
967
- session.api.form_responses.stripe_details(__assign({ fieldId: field.id, enduserId: enduserId }, (selectedProducts.length > 0 && { selectedProductIds: selectedProducts }) // Pass selected products to Stripe checkout
968
- ))
969
- .then(function (_a) {
970
- var clientSecret = _a.clientSecret, publishableKey = _a.publishableKey, stripeAccount = _a.stripeAccount, businessName = _a.businessName, customerId = _a.customerId, isCheckout = _a.isCheckout, answerText = _a.answerText;
971
- setAnswertext(answerText || '');
972
- setIsCheckout(!!isCheckout);
973
- setClientSecret(clientSecret);
974
- setStripePromise((0, stripe_js_1.loadStripe)(publishableKey, { stripeAccount: stripeAccount }));
975
- setBusinessName(businessName);
976
- setCustomerId(customerId);
977
- })
978
- .catch(function (e) {
979
- console.error(e);
980
- if (typeof (e === null || e === void 0 ? void 0 : e.message) === 'string') {
981
- setError(e.message);
982
- }
983
- });
984
- };
985
- 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) {
986
- var _a, _b, _d;
987
- // Use real-time Stripe pricing if available, fallback to Tellescope pricing
988
- var price = product.currentPrice || product.cost;
989
- var priceAmount = (price === null || price === void 0 ? void 0 : price.amount) || 0;
990
- var priceCurrency = (price === null || price === void 0 ? void 0 : price.currency) || 'USD';
991
- 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: (0, utilities_1.format_stripe_subscription_interval)((_b = product.currentPrice) === null || _b === void 0 ? void 0 : _b.interval, (_d = product.currentPrice) === null || _d === void 0 ? void 0 : _d.interval_count) })))] }))] }) }) }), product._id));
992
- }), (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" })) }))] })));
993
- }
994
- if (error) {
995
- return ((0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error" }, { children: error })));
996
- }
997
- if (value) {
998
- 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!" }))] })));
999
- }
1000
- if (!(clientSecret && stripePromise))
1001
- return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
1002
- if (isCheckout && stripePromise)
1003
- return ((0, jsx_runtime_1.jsx)(react_stripe_js_1.EmbeddedCheckoutProvider, __assign({ stripe: stripePromise, options: {
1004
- clientSecret: clientSecret,
1005
- onComplete: function () { return onChange(answertext || 'Completed checkout', field.id); },
1006
- } }, { children: (0, jsx_runtime_1.jsx)(react_stripe_js_1.EmbeddedCheckout, {}) })));
1007
- return ((0, jsx_runtime_1.jsx)(react_stripe_js_1.Elements, __assign({ stripe: stripePromise, options: {
1008
- clientSecret: clientSecret,
1009
- } }, { children: (0, jsx_runtime_1.jsx)(StripeForm, { businessName: businessName, onSuccess: function () { return onChange(answertext || 'Saved card details', field.id); }, cost: cost, field: field }) })));
1010
- };
1011
- exports.StripeInput = StripeInput;
1012
- var StripeForm = function (_a) {
1013
- var _b, _d, _e;
1014
- var businessName = _a.businessName, onSuccess = _a.onSuccess, field = _a.field, cost = _a.cost;
1015
- var stripe = (0, react_stripe_js_1.useStripe)();
1016
- var elements = (0, react_stripe_js_1.useElements)();
1017
- var _f = (0, react_1.useState)(false), ready = _f[0], setReady = _f[1];
1018
- var _g = (0, react_1.useState)(''), errorMessage = _g[0], setErrorMessage = _g[1];
1019
- var handleSubmit = function (event) { return __awaiter(void 0, void 0, void 0, function () {
1020
- var error;
1021
- var _a, _b;
1022
- return __generator(this, function (_d) {
1023
- switch (_d.label) {
1024
- case 0:
1025
- // We don't want to let default form submission happen here,
1026
- // which would refresh the page.
1027
- event === null || event === void 0 ? void 0 : event.preventDefault();
1028
- if (!stripe || !elements) {
1029
- // Stripe.js hasn't yet loaded.
1030
- // Make sure to disable form submission until Stripe.js has loaded.
1031
- return [2 /*return*/, null];
1032
- }
1033
- return [4 /*yield*/, (((_a = field.options) === null || _a === void 0 ? void 0 : _a.chargeImmediately) ? stripe.confirmPayment : stripe.confirmSetup)({
1034
- //`Elements` instance that was used to create the Payment Element
1035
- elements: elements,
1036
- confirmParams: {
1037
- return_url: window.location.href,
1038
- },
1039
- redirect: 'if_required', // ensures the redirect url won't be used, unless the Bank redirect payment type is enabled (it's not, just card)
1040
- })];
1041
- case 1:
1042
- error = (_d.sent()).error;
1043
- if (error) {
1044
- // This point will only be reached if there is an immediate error when
1045
- // confirming the payment. Show error to your customer (for example, payment
1046
- // details incomplete)
1047
- setErrorMessage((_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : '');
1048
- }
1049
- else {
1050
- onSuccess();
1051
- // Your customer will be redirected to your `return_url`. For some payment
1052
- // methods like iDEAL, your customer will be redirected to an intermediate
1053
- // site first to authorize the payment, then redirected to the `return_url`.
1054
- }
1055
- return [2 /*return*/];
1056
- }
1057
- });
1058
- }); };
1059
- 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: {
1060
- business: { name: businessName },
1061
- } }), (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 &&
1062
- (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)
1063
- ? field.options.customPriceMessage.replaceAll('{{PRICE}}', "$".concat((cost / 100).toFixed(2)))
1064
- : "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 &&
1065
- (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error", sx: { mt: 0.5 } }, { children: errorMessage }))] })));
1066
- };
859
+ // StripeInput is shared between v1 and v2 forms
860
+ // Both versions use the same implementation from inputs.tsx to ensure consistent behavior
861
+ // and avoid code duplication. Re-exporting here maintains the pattern where forms.v2.tsx
862
+ // only imports from inputs.v2.tsx
863
+ var inputs_1 = require("./inputs");
864
+ Object.defineProperty(exports, "StripeInput", { enumerable: true, get: function () { return inputs_1.StripeInput; } });
1067
865
  var Progress = function (_a) {
1068
866
  var numerator = _a.numerator, denominator = _a.denominator, style = _a.style, color = _a.color;
1069
867
  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 ? {
@@ -1114,240 +912,13 @@ var DropdownInput = function (_a) {
1114
912
  } }));
1115
913
  };
1116
914
  exports.DropdownInput = DropdownInput;
1117
- var choicesForDatabase = {};
1118
- var preventRefetch = {};
1119
- var LOAD_CHOICES_LIMIT = 500;
1120
- var useDatabaseChoices = function (_a) {
1121
- var _b, _d, _e, _f;
1122
- var _g = _a.databaseId, databaseId = _g === void 0 ? '' : _g, field = _a.field, otherAnswers = _a.otherAnswers;
1123
- var session = (0, __1.useResolvedSession)();
1124
- var _h = (0, react_1.useState)(0), renderCount = _h[0], setRenderCount = _h[1];
1125
- // todo: make searchable, don't load all
1126
- (0, react_1.useEffect)(function () {
1127
- var _a, _b, _d, _e;
1128
- if ((_a = choicesForDatabase[databaseId]) === null || _a === void 0 ? void 0 : _a.done)
1129
- return;
1130
- if (renderCount > 100)
1131
- return; // limit to 50000 entries / prevent infinite looping
1132
- var choices = (_d = (_b = choicesForDatabase[databaseId]) === null || _b === void 0 ? void 0 : _b.records) !== null && _d !== void 0 ? _d : [];
1133
- var lastId = (_e = choicesForDatabase[databaseId]) === null || _e === void 0 ? void 0 : _e.lastId;
1134
- if (preventRefetch[databaseId + field.id + lastId])
1135
- return;
1136
- preventRefetch[databaseId + field.id + lastId] = true;
1137
- session.api.form_fields.load_choices_from_database({
1138
- fieldId: field.id,
1139
- lastId: lastId,
1140
- limit: LOAD_CHOICES_LIMIT,
1141
- databaseId: databaseId,
1142
- })
1143
- .then(function (_a) {
1144
- var _b;
1145
- var newChoices = _a.choices;
1146
- choicesForDatabase[databaseId] = {
1147
- lastId: (_b = newChoices === null || newChoices === void 0 ? void 0 : newChoices[newChoices.length - 1]) === null || _b === void 0 ? void 0 : _b.id,
1148
- records: __spreadArray(__spreadArray([], choices, true), newChoices, true).sort(function (c1, c2) { return (label_for_database_record(field, c1)
1149
- .localeCompare(label_for_database_record(field, c2))); }),
1150
- done: newChoices.length < LOAD_CHOICES_LIMIT,
1151
- };
1152
- setRenderCount(function (r) { return r + 1; });
1153
- })
1154
- .catch(function (err) {
1155
- console.error(err);
1156
- preventRefetch[databaseId + field.id + lastId] = false;
1157
- });
1158
- }, [session, field, databaseId, renderCount]);
1159
- var addChoice = (0, react_1.useCallback)(function (record) {
1160
- if (!choicesForDatabase[databaseId]) {
1161
- choicesForDatabase[databaseId] = {
1162
- done: false,
1163
- records: [],
1164
- };
1165
- }
1166
- choicesForDatabase[databaseId].records.push(record);
1167
- }, [choicesForDatabase, databaseId]);
1168
- return {
1169
- addChoice: addChoice,
1170
- doneLoading: (_d = (_b = choicesForDatabase[databaseId]) === null || _b === void 0 ? void 0 : _b.done) !== null && _d !== void 0 ? _d : false,
1171
- 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) {
1172
- var _a;
1173
- return ({
1174
- id: v.text,
1175
- databaseId: databaseId,
1176
- values: [{ label: ((_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseLabel) || '', type: 'Text', value: v.text }],
1177
- });
1178
- }), true),
1179
- renderCount: renderCount,
1180
- };
1181
- };
1182
- var label_for_database_record = function (field, record) {
1183
- var _a, _b, _d, _e;
1184
- if (!record)
1185
- return '';
1186
- var addedLabels = ((((_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseLabels) || [])
1187
- .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(); })
1188
- .filter(function (v) { return v === null || v === void 0 ? void 0 : v.trim(); }));
1189
- 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 : '')
1190
- + (addedLabels.length
1191
- ? " (".concat(addedLabels.join(', '), ")")
1192
- : ''));
1193
- };
1194
- var get_other_answers = function (_value, typing) {
1195
- try {
1196
- var existing = ((_value || [])
1197
- .filter(function (v) { return typeof v === 'string' || v.recordId === v.text; })
1198
- .map(function (v) { return typeof v === 'string' ? { databaseId: '', recordId: v, text: v } : v; }));
1199
- if (typing) {
1200
- existing.push({ text: typing, databaseId: '', recordId: typing });
1201
- }
1202
- return existing;
1203
- }
1204
- catch (err) {
1205
- console.error(err);
1206
- }
1207
- return [];
1208
- };
1209
- var DatabaseSelectInput = function (_a) {
1210
- var _b, _d, _e, _f, _g, _h, _j, _k;
1211
- 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;
1212
- var _l = (0, react_1.useState)(''), typing = _l[0], setTyping = _l[1];
1213
- var _m = useDatabaseChoices({
1214
- databaseId: (_b = field.options) === null || _b === void 0 ? void 0 : _b.databaseId,
1215
- field: field,
1216
- 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),
1217
- }), addChoice = _m.addChoice, choices = _m.choices, doneLoading = _m.doneLoading;
1218
- var value = react_1.default.useMemo(function () {
1219
- var _a, _b;
1220
- try {
1221
- // if the value is a string (some single answer that was save), make sure we coerce to array
1222
- var __value = typeof _value === 'string' ? [_value] : _value;
1223
- return ((_b = (_a = __value === null || __value === void 0 ? void 0 : __value.map(function (v) {
1224
- return choices.find(function (c) {
1225
- return c.id === v.recordId || (typeof v === 'string' && label_for_database_record(field, c) === v);
1226
- });
1227
- })) === null || _a === void 0 ? void 0 : _a.filter(function (v) { return v; })) !== null && _b !== void 0 ? _b : []);
1228
- }
1229
- catch (err) {
1230
- console.error('Error resolving database answers for _value', err);
1231
- return [];
1232
- }
1233
- }, [_value, choices, field]);
1234
- var filterResponse = (0, react_1.useMemo)(function () {
1235
- var _a, _b, _d, _e;
1236
- return (((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseFilter) === null || _b === void 0 ? void 0 : _b.fieldId)
1237
- ? (_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
1238
- : undefined);
1239
- }, [responses, (_e = field.options) === null || _e === void 0 ? void 0 : _e.databaseFilter]);
1240
- // State filtering logic similar to Insurance component
1241
- var addressQuestion = (0, react_1.useMemo)(function () { return responses === null || responses === void 0 ? void 0 : responses.find(function (r) {
1242
- var _a;
1243
- if (r.answer.type !== 'Address')
1244
- return false;
1245
- if (r.field.intakeField !== 'Address')
1246
- return false;
1247
- // make sure state is actually defined (in case of multiple address questions, where 1+ are blank)
1248
- if (!((_a = r.answer.value) === null || _a === void 0 ? void 0 : _a.state))
1249
- return false;
1250
- return true;
1251
- }); }, [responses]);
1252
- var state = (0, react_1.useMemo)(function () {
1253
- var _a, _b, _d, _e;
1254
- return (((_a = field.options) === null || _a === void 0 ? void 0 : _a.filterByEnduserState)
1255
- ? ((((_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))
1256
- : undefined);
1257
- }, [enduser === null || enduser === void 0 ? void 0 : enduser.state, addressQuestion, (_f = field.options) === null || _f === void 0 ? void 0 : _f.filterByEnduserState]);
1258
- var filteredChoicesWithPotentialDuplicates = (0, react_1.useMemo)(function () {
1259
- var _a, _b;
1260
- if (!choices)
1261
- return [];
1262
- if (!filterResponse)
1263
- return choices;
1264
- 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))
1265
- if (!value || value.length === 0)
1266
- return choices;
1267
- return (choices
1268
- .filter(function (c) {
1269
- var _a;
1270
- 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;
1271
- if (!v)
1272
- return true;
1273
- // use .text on r values to handle Database Select types as filter source (in addition to basic text and list of text)
1274
- if (typeof v === 'object') {
1275
- return !!(Object.values(v).find(function (oVal) { return (typeof oVal === 'string' || typeof oVal === 'number'
1276
- ? (Array.isArray(filterResponse)
1277
- ? filterResponse.find(function (r) { return r === oVal.toString() || (typeof r === 'object' && r.text === oVal); })
1278
- : (typeof filterResponse === 'string' || typeof filterResponse === 'number')
1279
- ? filterResponse.toString() === oVal.toString()
1280
- : false)
1281
- : false); }));
1282
- }
1283
- if (typeof v === 'string' || typeof v === 'number') {
1284
- return !!(Array.isArray(filterResponse)
1285
- ? filterResponse.find(function (r) { return r === v.toString() || (typeof r === 'object' && r.text === v); })
1286
- : (typeof filterResponse === 'string' || typeof filterResponse === 'number')
1287
- ? filterResponse.toString() === v.toString()
1288
- : (typeof filterResponse === 'object' && filterResponse.city === v.toString()) ? true
1289
- : (typeof filterResponse === 'object' && filterResponse.state === v.toString()) ? true
1290
- : (typeof filterResponse === 'object' && filterResponse.zipCode === v.toString()) ? true
1291
- : false);
1292
- }
1293
- return false;
1294
- }));
1295
- }, [choices, filterResponse, (_g = field.options) === null || _g === void 0 ? void 0 : _g.databaseFilter, value]);
1296
- // Apply state filtering as a secondary filter (doesn't modify existing logic)
1297
- var stateFilteredChoices = (0, react_1.useMemo)(function () {
1298
- var _a;
1299
- if (!((_a = field.options) === null || _a === void 0 ? void 0 : _a.filterByEnduserState) || !state) {
1300
- return filteredChoicesWithPotentialDuplicates;
1301
- }
1302
- return filteredChoicesWithPotentialDuplicates.filter(function (c) {
1303
- var _a, _b;
1304
- 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()) || '';
1305
- return !recordState || recordState === state;
1306
- });
1307
- }, [filteredChoicesWithPotentialDuplicates, (_h = field.options) === null || _h === void 0 ? void 0 : _h.filterByEnduserState, state]);
1308
- var filteredChoices = (0, react_1.useMemo)(function () {
1309
- var filtered = [];
1310
- var uniques = new Set([]);
1311
- for (var _a = 0, stateFilteredChoices_1 = stateFilteredChoices; _a < stateFilteredChoices_1.length; _a++) {
1312
- var c = stateFilteredChoices_1[_a];
1313
- var text = label_for_database_record(field, c);
1314
- if (uniques.has(text))
1315
- continue; // duplicate found
1316
- uniques.add(text);
1317
- filtered.push(c);
1318
- }
1319
- return filtered;
1320
- }, [field, stateFilteredChoices]);
1321
- if (!doneLoading)
1322
- return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
1323
- 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
1324
- ? ''
1325
- : label_for_database_record(field, o)); }, value: value, disabled: disabled, onChange: function (_, v) {
1326
- var _a, _b, _d, _e, _f;
1327
- if (v.length && onDatabaseSelect) {
1328
- onDatabaseSelect(((_a = field.options) === null || _a === void 0 ? void 0 : _a.radio)
1329
- ? [v[v.length - 1]] // if radio, only last selected
1330
- : v);
1331
- }
1332
- return onChange((!((_b = field.options) === null || _b === void 0 ? void 0 : _b.radio)
1333
- ? v.map(function (_v) {
1334
- var _a;
1335
- return ({
1336
- databaseId: (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseId,
1337
- recordId: _v.id,
1338
- text: label_for_database_record(field, _v),
1339
- });
1340
- })
1341
- : [{
1342
- databaseId: (_d = field.options) === null || _d === void 0 ? void 0 : _d.databaseId,
1343
- recordId: (_f = (_e = v[v.length - 1]) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : '',
1344
- text: label_for_database_record(field, v[v.length - 1]),
1345
- }]), field.id);
1346
- }, 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 }) })); },
1347
- // use custom Chip to ensure very long entries break properly (whitespace: normal)
1348
- renderTags: function (value, getTagProps) {
1349
- 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 } }))); });
1350
- } }), 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 }))] }));
915
+ // DatabaseSelectInput logic is shared with inputs.tsx to avoid duplication
916
+ // Import the interface and component from the shared implementation
917
+ var inputs_2 = require("./inputs");
918
+ // Wrap the shared DatabaseSelectInput component with v2-specific props
919
+ var DatabaseSelectInput = function (props) {
920
+ // Pass all props plus v2-specific defaultInputProps to the shared component
921
+ return (0, jsx_runtime_1.jsx)(inputs_2.DatabaseSelectInput, __assign({}, props, { inputProps: exports.defaultInputProps }));
1351
922
  };
1352
923
  exports.DatabaseSelectInput = DatabaseSelectInput;
1353
924
  var displayTermsCache = undefined;
@@ -1724,7 +1295,7 @@ var contact_is_valid = function (e) {
1724
1295
  exports.contact_is_valid = contact_is_valid;
1725
1296
  var RelatedContactsInput = function (_a) {
1726
1297
  var _b, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _w, _x;
1727
- var field = _a.field, _value = _a.value, onChange = _a.onChange, props = __rest(_a, ["field", "value", "onChange"]);
1298
+ var field = _a.field, _value = _a.value, onChange = _a.onChange, parentError = _a.error, props = __rest(_a, ["field", "value", "onChange", "error"]);
1728
1299
  // safeguard against any rogue values like empty string
1729
1300
  var value = Array.isArray(_value) ? _value : [];
1730
1301
  var _y = (0, react_1.useState)(value.length === 1 ? 0 : -1), editing = _y[0], setEditing = _y[1];
@@ -1743,7 +1314,7 @@ var RelatedContactsInput = function (_a) {
1743
1314
  (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')) &&
1744
1315
  (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')) &&
1745
1316
  (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')) &&
1746
- (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 &&
1317
+ (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.trim() }) : v; }), field.id); } }) }))] })) })), (((_w = field.options) === null || _w === void 0 ? void 0 : _w.tableChoices) || []).length > 0 &&
1747
1318
  (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) {
1748
1319
  var info = _a.info, label = _a.label, type = _a.type;
1749
1320
  return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 6 }, { children: type === 'Text'
@@ -1763,7 +1334,7 @@ var RelatedContactsInput = function (_a) {
1763
1334
  return i === editing ? __assign(__assign({}, v), { fields: __assign(__assign({}, fields_1), (_a = {}, _a[label] = e.target.value, _a)) }) : v;
1764
1335
  }), 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)); })] }))] })))
1765
1336
  : null }), i));
1766
- }) })) })), (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 &&
1337
+ }) })) })), (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", disabled: !!errorMessage || !!parentError }, { children: "Save Contact" })) })), errorMessage &&
1767
1338
  (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 })) }))] })));
1768
1339
  }
1769
1340
  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" })) }))] })));