@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;
@@ -20,7 +20,7 @@ export declare const RatingInput: ({ field, value, onChange }: FormInputProps<'r
20
20
  export declare const RankingInput: ({ field, value, onChange }: FormInputProps<'ranking'>) => JSX.Element;
21
21
  export declare const DateInput: ({ field, value, onChange, placement, ...props }: {
22
22
  field: FormField;
23
- placement?: "bottom" | "left" | "right" | "top" | undefined;
23
+ placement?: "left" | "right" | "bottom" | "top" | undefined;
24
24
  } & FormInputProps<"date"> & Styled) => JSX.Element;
25
25
  export declare const TableInput: ({ field, value, onChange, ...props }: FormInputProps<'Input Table'>) => JSX.Element;
26
26
  export declare const AutoFocusTextField: (props: TextFieldProps) => JSX.Element;
@@ -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_templated: (url: string) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"inputs.v2.d.ts","sourceRoot":"","sources":["../../../src/Forms/inputs.v2.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwE,MAAM,OAAO,CAAA;AAE5F,OAAO,EAAuJ,OAAO,EAAa,cAAc,EAAc,MAAM,eAAe,CAAA;AACnO,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAIxC,OAAO,EAAmC,OAAO,EAAuB,iBAAiB,EAA6H,MAAM,0BAA0B,CAAA;AAOtP,OAAO,EAAc,QAAQ,EAAgD,MAAM,EAAiF,MAAM,IAAI,CAAA;AAC9K,OAAO,EAAiB,cAAc,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAanF,eAAO,MAAM,cAAc;WAAkC,MAAM;kBAAgB,MAAM,KAAK,IAAI;iBAgBjG,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE;IAAE,EAAE,EAAE,OAAO,CAAA;CAgB3C,CAAA;AACF,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,aAEvC,CAAA;AAED,eAAO,MAAM,SAAS;SAAiC,MAAM;;iBAoE5D,CAAA;AAED,eAAO,MAAM,WAAW,+BAAgC,eAAe,QAAQ,CAAC,gBA0B/E,CAAA;AAkCD,eAAO,MAAM,YAAY,+BAAgC,eAAe,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AAM,cAAc,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;iBA6CxE,CAAA"}
@@ -72,10 +72,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
72
72
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
73
73
  import React, { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from "react";
74
74
  import axios from "axios";
75
- import { Autocomplete, Box, Button, Checkbox, Chip, Divider, FormControl, FormControlLabel, Grid, InputLabel, MenuItem, Radio, RadioGroup, Select, TextField, Typography } from "@mui/material";
75
+ import { Autocomplete, Box, Button, Checkbox, Chip, Divider, FormControl, Grid, InputLabel, MenuItem, RadioGroup, Select, TextField, Typography } from "@mui/material";
76
76
  import { useDropzone } from "react-dropzone";
77
77
  import { CANVAS_TITLE, EMOTII_TITLE, INSURANCE_RELATIONSHIPS, INSURANCE_RELATIONSHIPS_CANVAS, PRIMARY_HEX, RELATIONSHIP_TYPES, TELLESCOPE_GENDERS } from "@tellescope/constants";
78
- import { MM_DD_YYYY_to_YYYY_MM_DD, capture_is_supported, downloadFile, emit_gtm_event, first_letter_capitalized, form_response_value_to_string, format_stripe_subscription_interval, getLocalTimezone, getPublicFileURL, mm_dd_yyyy, replace_enduser_template_values, truncate_string, update_local_storage, user_display_name } from "@tellescope/utilities";
78
+ import { MM_DD_YYYY_to_YYYY_MM_DD, capture_is_supported, downloadFile, emit_gtm_event, first_letter_capitalized, form_response_value_to_string, getLocalTimezone, getPublicFileURL, mm_dd_yyyy, replace_enduser_template_values, truncate_string, update_local_storage, user_display_name } from "@tellescope/utilities";
79
79
  import { TIMEZONES_USA } from "@tellescope/types-models";
80
80
  import { VALID_STATES, emailValidator, phoneValidator } from "@tellescope/validation";
81
81
  import Slider from '@mui/material/Slider';
@@ -89,8 +89,6 @@ import DragIndicatorIcon from '@mui/icons-material/DragIndicator';
89
89
  import heic2any from "heic2any";
90
90
  import AddPhotoAlternateIcon from '@mui/icons-material/AddPhotoAlternate';
91
91
  import LanguageIcon from '@mui/icons-material/Language';
92
- import { Elements, PaymentElement, useStripe, useElements, EmbeddedCheckout, EmbeddedCheckoutProvider } from '@stripe/react-stripe-js';
93
- import { loadStripe } from '@stripe/stripe-js';
94
92
  import { CheckCircleOutline, Delete, Edit, UploadFile } from "@mui/icons-material";
95
93
  import { WYSIWYG } from "./wysiwyg";
96
94
  export var LanguageSelect = function (_a) {
@@ -805,211 +803,11 @@ export var MultipleChoiceInput = function (_a) {
805
803
  ? __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);
806
804
  } }) }))] })));
807
805
  };
808
- export var StripeInput = function (_a) {
809
- var _b, _d;
810
- var field = _a.field, value = _a.value, onChange = _a.onChange, setCustomerId = _a.setCustomerId, enduserId = _a.enduserId;
811
- var session = useResolvedSession();
812
- var _e = useState(''), clientSecret = _e[0], setClientSecret = _e[1];
813
- var _f = useState(''), businessName = _f[0], setBusinessName = _f[1];
814
- var _g = useState(false), isCheckout = _g[0], setIsCheckout = _g[1];
815
- var _h = useState(), stripePromise = _h[0], setStripePromise = _h[1];
816
- var _j = useState(''), answertext = _j[0], setAnswertext = _j[1];
817
- var _k = useState(''), error = _k[0], setError = _k[1];
818
- var _l = useState([]), selectedProducts = _l[0], setSelectedProducts = _l[1];
819
- var _m = useState(false), showProductSelection = _m[0], setShowProductSelection = _m[1];
820
- var _o = useState([]), availableProducts = _o[0], setAvailableProducts = _o[1];
821
- var _p = useState(false), loadingProducts = _p[0], setLoadingProducts = _p[1];
822
- var fetchRef = useRef(false);
823
- useEffect(function () {
824
- var _a, _b, _d;
825
- if (fetchRef.current)
826
- return;
827
- if (value && ((_a = session.userInfo) === null || _a === void 0 ? void 0 : _a.stripeCustomerId)) {
828
- 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
829
- }
830
- // Check if product selection mode is enabled
831
- 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) {
832
- setShowProductSelection(true);
833
- setLoadingProducts(true);
834
- // Fetch product data with real-time Stripe pricing via proxy_read
835
- var productIds = (field.options.productIds || []).join(',');
836
- session.api.integrations.proxy_read({
837
- integration: 'Stripe',
838
- type: 'product-prices',
839
- id: productIds,
840
- query: field.options.stripeKey
841
- })
842
- .then(function (_a) {
843
- var data = _a.data;
844
- setAvailableProducts(data.products || []);
845
- setLoadingProducts(false);
846
- })
847
- .catch(function (e) {
848
- var _a, _b;
849
- console.error('Error loading product data:', e);
850
- 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:'))
851
- ? e.message.replace('Stripe pricing error: ', '')
852
- : 'Failed to load product information from Stripe';
853
- setError("Product configuration error: ".concat(errorMessage));
854
- setLoadingProducts(false);
855
- });
856
- return;
857
- }
858
- fetchRef.current = true;
859
- session.api.form_responses.stripe_details({ fieldId: field.id, enduserId: enduserId })
860
- .then(function (_a) {
861
- var clientSecret = _a.clientSecret, publishableKey = _a.publishableKey, stripeAccount = _a.stripeAccount, businessName = _a.businessName, customerId = _a.customerId, isCheckout = _a.isCheckout, answerText = _a.answerText;
862
- setAnswertext(answerText || '');
863
- setIsCheckout(!!isCheckout);
864
- setClientSecret(clientSecret);
865
- setStripePromise(loadStripe(publishableKey, { stripeAccount: stripeAccount }));
866
- setBusinessName(businessName);
867
- setCustomerId(customerId);
868
- })
869
- .catch(function (e) {
870
- console.error(e);
871
- if (typeof (e === null || e === void 0 ? void 0 : e.message) === 'string') {
872
- setError(e.message);
873
- }
874
- });
875
- }, [session, value, field.id, enduserId]);
876
- var cost = (showProductSelection
877
- ? selectedProducts.reduce(function (total, productId) {
878
- var _a;
879
- var product = availableProducts.find(function (p) { return p._id === productId; });
880
- if (product === null || product === void 0 ? void 0 : product.currentPrice) {
881
- return total + (product.currentPrice.amount || 0);
882
- }
883
- return total + (((_a = product === null || product === void 0 ? void 0 : product.cost) === null || _a === void 0 ? void 0 : _a.amount) || 0);
884
- }, 0)
885
- : 0 // Will be calculated by existing Stripe flow when not in selection mode
886
- );
887
- // Handle product selection step
888
- if (showProductSelection) {
889
- if (error) {
890
- return (_jsxs(Grid, __assign({ container: true, direction: "column", spacing: 2, alignItems: "center" }, { children: [_jsx(Grid, __assign({ item: true }, { children: _jsx(Typography, __assign({ color: "error", variant: "h6" }, { children: "Product Configuration Error" })) })), _jsx(Grid, __assign({ item: true }, { children: _jsx(Typography, __assign({ color: "error", sx: { textAlign: 'center' } }, { children: error })) }))] })));
891
- }
892
- if (loadingProducts) {
893
- return (_jsxs(Grid, __assign({ container: true, direction: "column", spacing: 2, alignItems: "center" }, { children: [_jsx(Grid, __assign({ item: true }, { children: _jsx(LinearProgress, {}) })), _jsx(Grid, __assign({ item: true }, { children: _jsx(Typography, { children: "Loading product information..." }) }))] })));
894
- }
895
- var isSingleSelection_1 = ((_b = field.options) === null || _b === void 0 ? void 0 : _b.radio) === true;
896
- var handleProductSelection_1 = function (productId) {
897
- if (isSingleSelection_1) {
898
- setSelectedProducts([productId]);
899
- }
900
- else {
901
- setSelectedProducts(function (prev) {
902
- return prev.includes(productId)
903
- ? prev.filter(function (id) { return id !== productId; })
904
- : __spreadArray(__spreadArray([], prev, true), [productId], false);
905
- });
906
- }
907
- };
908
- var handleContinueToPayment = function () {
909
- if (selectedProducts.length === 0)
910
- return;
911
- setShowProductSelection(false);
912
- fetchRef.current = true;
913
- // Now fetch Stripe details with selected products
914
- session.api.form_responses.stripe_details(__assign({ fieldId: field.id, enduserId: enduserId }, (selectedProducts.length > 0 && { selectedProductIds: selectedProducts }) // Pass selected products to Stripe checkout
915
- ))
916
- .then(function (_a) {
917
- var clientSecret = _a.clientSecret, publishableKey = _a.publishableKey, stripeAccount = _a.stripeAccount, businessName = _a.businessName, customerId = _a.customerId, isCheckout = _a.isCheckout, answerText = _a.answerText;
918
- setAnswertext(answerText || '');
919
- setIsCheckout(!!isCheckout);
920
- setClientSecret(clientSecret);
921
- setStripePromise(loadStripe(publishableKey, { stripeAccount: stripeAccount }));
922
- setBusinessName(businessName);
923
- setCustomerId(customerId);
924
- })
925
- .catch(function (e) {
926
- console.error(e);
927
- if (typeof (e === null || e === void 0 ? void 0 : e.message) === 'string') {
928
- setError(e.message);
929
- }
930
- });
931
- };
932
- return (_jsxs(Grid, __assign({ container: true, direction: "column", spacing: 2 }, { children: [_jsx(Grid, __assign({ item: true }, { children: _jsxs(Typography, __assign({ variant: "h6" }, { children: ["Select Product", isSingleSelection_1 ? '' : 's'] })) })), availableProducts.map(function (product) {
933
- var _a, _b, _d;
934
- // Use real-time Stripe pricing if available, fallback to Tellescope pricing
935
- var price = product.currentPrice || product.cost;
936
- var priceAmount = (price === null || price === void 0 ? void 0 : price.amount) || 0;
937
- var priceCurrency = (price === null || price === void 0 ? void 0 : price.currency) || 'USD';
938
- return (_jsx(Grid, __assign({ item: true }, { children: _jsx(FormControlLabel, { control: isSingleSelection_1 ? (_jsx(Radio, { checked: selectedProducts.includes(product._id), onChange: function () { return handleProductSelection_1(product._id); } })) : (_jsx(Checkbox, { checked: selectedProducts.includes(product._id), onChange: function () { return handleProductSelection_1(product._id); } })), label: _jsxs(Box, { children: [_jsx(Typography, __assign({ variant: "body1", fontWeight: "bold" }, { children: product.title })), product.description && (_jsx(Typography, __assign({ variant: "body2", color: "textSecondary" }, { children: product.description }))), _jsxs(Typography, __assign({ variant: "body2", color: "primary" }, { children: ["$", (priceAmount / 100).toFixed(2), " ", priceCurrency.toUpperCase(), ((_a = product.currentPrice) === null || _a === void 0 ? void 0 : _a.isSubscription) && (_jsx(Typography, __assign({ component: "span", variant: "caption", sx: { ml: 0.5 } }, { children: 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));
939
- }), _jsx(Grid, __assign({ item: true }, { children: _jsx(Button, __assign({ variant: "contained", onClick: handleContinueToPayment, disabled: selectedProducts.length === 0, sx: { mt: 2 } }, { children: "Continue to Payment" })) }))] })));
940
- }
941
- if (error) {
942
- return (_jsx(Typography, __assign({ color: "error" }, { children: error })));
943
- }
944
- if (value) {
945
- return (_jsxs(Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap" }, { children: [_jsx(CheckCircleOutline, { color: "success" }), _jsx(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!" }))] })));
946
- }
947
- if (!(clientSecret && stripePromise))
948
- return _jsx(LinearProgress, {});
949
- if (isCheckout && stripePromise)
950
- return (_jsx(EmbeddedCheckoutProvider, __assign({ stripe: stripePromise, options: {
951
- clientSecret: clientSecret,
952
- onComplete: function () { return onChange(answertext || 'Completed checkout', field.id); },
953
- } }, { children: _jsx(EmbeddedCheckout, {}) })));
954
- return (_jsx(Elements, __assign({ stripe: stripePromise, options: {
955
- clientSecret: clientSecret,
956
- } }, { children: _jsx(StripeForm, { businessName: businessName, onSuccess: function () { return onChange(answertext || 'Saved card details', field.id); }, cost: cost, field: field }) })));
957
- };
958
- var StripeForm = function (_a) {
959
- var _b, _d, _e;
960
- var businessName = _a.businessName, onSuccess = _a.onSuccess, field = _a.field, cost = _a.cost;
961
- var stripe = useStripe();
962
- var elements = useElements();
963
- var _f = useState(false), ready = _f[0], setReady = _f[1];
964
- var _g = useState(''), errorMessage = _g[0], setErrorMessage = _g[1];
965
- var handleSubmit = function (event) { return __awaiter(void 0, void 0, void 0, function () {
966
- var error;
967
- var _a, _b;
968
- return __generator(this, function (_d) {
969
- switch (_d.label) {
970
- case 0:
971
- // We don't want to let default form submission happen here,
972
- // which would refresh the page.
973
- event === null || event === void 0 ? void 0 : event.preventDefault();
974
- if (!stripe || !elements) {
975
- // Stripe.js hasn't yet loaded.
976
- // Make sure to disable form submission until Stripe.js has loaded.
977
- return [2 /*return*/, null];
978
- }
979
- return [4 /*yield*/, (((_a = field.options) === null || _a === void 0 ? void 0 : _a.chargeImmediately) ? stripe.confirmPayment : stripe.confirmSetup)({
980
- //`Elements` instance that was used to create the Payment Element
981
- elements: elements,
982
- confirmParams: {
983
- return_url: window.location.href,
984
- },
985
- redirect: 'if_required', // ensures the redirect url won't be used, unless the Bank redirect payment type is enabled (it's not, just card)
986
- })];
987
- case 1:
988
- error = (_d.sent()).error;
989
- if (error) {
990
- // This point will only be reached if there is an immediate error when
991
- // confirming the payment. Show error to your customer (for example, payment
992
- // details incomplete)
993
- setErrorMessage((_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : '');
994
- }
995
- else {
996
- onSuccess();
997
- // Your customer will be redirected to your `return_url`. For some payment
998
- // methods like iDEAL, your customer will be redirected to an intermediate
999
- // site first to authorize the payment, then redirected to the `return_url`.
1000
- }
1001
- return [2 /*return*/];
1002
- }
1003
- });
1004
- }); };
1005
- return (_jsxs("form", __assign({ onSubmit: handleSubmit }, { children: [_jsx(PaymentElement, { onReady: function () { return setReady(true); }, options: {
1006
- business: { name: businessName },
1007
- } }), _jsx(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 &&
1008
- _jsx(Typography, __assign({ sx: { mt: 0.5 } }, { children: ((_d = field.options) === null || _d === void 0 ? void 0 : _d.customPriceMessage)
1009
- ? field.options.customPriceMessage.replaceAll('{{PRICE}}', "$".concat((cost / 100).toFixed(2)))
1010
- : "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 &&
1011
- _jsx(Typography, __assign({ color: "error", sx: { mt: 0.5 } }, { children: errorMessage }))] })));
1012
- };
806
+ // StripeInput is shared between v1 and v2 forms
807
+ // Both versions use the same implementation from inputs.tsx to ensure consistent behavior
808
+ // and avoid code duplication. Re-exporting here maintains the pattern where forms.v2.tsx
809
+ // only imports from inputs.v2.tsx
810
+ export { StripeInput } from './inputs';
1013
811
  export var Progress = function (_a) {
1014
812
  var numerator = _a.numerator, denominator = _a.denominator, style = _a.style, color = _a.color;
1015
813
  return (_jsx(Box, __assign({ sx: __assign({ display: 'flex', alignItems: 'center' }, style) }, { children: _jsx(Box, __assign({ sx: { width: '100%' } }, { children: _jsx(LinearProgress, { variant: "determinate", value: (numerator / (denominator || 1)) * 100, sx: color ? {
@@ -1058,240 +856,13 @@ export var DropdownInput = function (_a) {
1058
856
  : '' }));
1059
857
  } }));
1060
858
  };
1061
- var choicesForDatabase = {};
1062
- var preventRefetch = {};
1063
- var LOAD_CHOICES_LIMIT = 500;
1064
- var useDatabaseChoices = function (_a) {
1065
- var _b, _d, _e, _f;
1066
- var _g = _a.databaseId, databaseId = _g === void 0 ? '' : _g, field = _a.field, otherAnswers = _a.otherAnswers;
1067
- var session = useResolvedSession();
1068
- var _h = useState(0), renderCount = _h[0], setRenderCount = _h[1];
1069
- // todo: make searchable, don't load all
1070
- useEffect(function () {
1071
- var _a, _b, _d, _e;
1072
- if ((_a = choicesForDatabase[databaseId]) === null || _a === void 0 ? void 0 : _a.done)
1073
- return;
1074
- if (renderCount > 100)
1075
- return; // limit to 50000 entries / prevent infinite looping
1076
- var choices = (_d = (_b = choicesForDatabase[databaseId]) === null || _b === void 0 ? void 0 : _b.records) !== null && _d !== void 0 ? _d : [];
1077
- var lastId = (_e = choicesForDatabase[databaseId]) === null || _e === void 0 ? void 0 : _e.lastId;
1078
- if (preventRefetch[databaseId + field.id + lastId])
1079
- return;
1080
- preventRefetch[databaseId + field.id + lastId] = true;
1081
- session.api.form_fields.load_choices_from_database({
1082
- fieldId: field.id,
1083
- lastId: lastId,
1084
- limit: LOAD_CHOICES_LIMIT,
1085
- databaseId: databaseId,
1086
- })
1087
- .then(function (_a) {
1088
- var _b;
1089
- var newChoices = _a.choices;
1090
- choicesForDatabase[databaseId] = {
1091
- lastId: (_b = newChoices === null || newChoices === void 0 ? void 0 : newChoices[newChoices.length - 1]) === null || _b === void 0 ? void 0 : _b.id,
1092
- records: __spreadArray(__spreadArray([], choices, true), newChoices, true).sort(function (c1, c2) { return (label_for_database_record(field, c1)
1093
- .localeCompare(label_for_database_record(field, c2))); }),
1094
- done: newChoices.length < LOAD_CHOICES_LIMIT,
1095
- };
1096
- setRenderCount(function (r) { return r + 1; });
1097
- })
1098
- .catch(function (err) {
1099
- console.error(err);
1100
- preventRefetch[databaseId + field.id + lastId] = false;
1101
- });
1102
- }, [session, field, databaseId, renderCount]);
1103
- var addChoice = useCallback(function (record) {
1104
- if (!choicesForDatabase[databaseId]) {
1105
- choicesForDatabase[databaseId] = {
1106
- done: false,
1107
- records: [],
1108
- };
1109
- }
1110
- choicesForDatabase[databaseId].records.push(record);
1111
- }, [choicesForDatabase, databaseId]);
1112
- return {
1113
- addChoice: addChoice,
1114
- doneLoading: (_d = (_b = choicesForDatabase[databaseId]) === null || _b === void 0 ? void 0 : _b.done) !== null && _d !== void 0 ? _d : false,
1115
- 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) {
1116
- var _a;
1117
- return ({
1118
- id: v.text,
1119
- databaseId: databaseId,
1120
- values: [{ label: ((_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseLabel) || '', type: 'Text', value: v.text }],
1121
- });
1122
- }), true),
1123
- renderCount: renderCount,
1124
- };
1125
- };
1126
- var label_for_database_record = function (field, record) {
1127
- var _a, _b, _d, _e;
1128
- if (!record)
1129
- return '';
1130
- var addedLabels = ((((_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseLabels) || [])
1131
- .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(); })
1132
- .filter(function (v) { return v === null || v === void 0 ? void 0 : v.trim(); }));
1133
- 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 : '')
1134
- + (addedLabels.length
1135
- ? " (".concat(addedLabels.join(', '), ")")
1136
- : ''));
1137
- };
1138
- var get_other_answers = function (_value, typing) {
1139
- try {
1140
- var existing = ((_value || [])
1141
- .filter(function (v) { return typeof v === 'string' || v.recordId === v.text; })
1142
- .map(function (v) { return typeof v === 'string' ? { databaseId: '', recordId: v, text: v } : v; }));
1143
- if (typing) {
1144
- existing.push({ text: typing, databaseId: '', recordId: typing });
1145
- }
1146
- return existing;
1147
- }
1148
- catch (err) {
1149
- console.error(err);
1150
- }
1151
- return [];
1152
- };
1153
- export var DatabaseSelectInput = function (_a) {
1154
- var _b, _d, _e, _f, _g, _h, _j, _k;
1155
- 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;
1156
- var _l = useState(''), typing = _l[0], setTyping = _l[1];
1157
- var _m = useDatabaseChoices({
1158
- databaseId: (_b = field.options) === null || _b === void 0 ? void 0 : _b.databaseId,
1159
- field: field,
1160
- 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),
1161
- }), addChoice = _m.addChoice, choices = _m.choices, doneLoading = _m.doneLoading;
1162
- var value = React.useMemo(function () {
1163
- var _a, _b;
1164
- try {
1165
- // if the value is a string (some single answer that was save), make sure we coerce to array
1166
- var __value = typeof _value === 'string' ? [_value] : _value;
1167
- return ((_b = (_a = __value === null || __value === void 0 ? void 0 : __value.map(function (v) {
1168
- return choices.find(function (c) {
1169
- return c.id === v.recordId || (typeof v === 'string' && label_for_database_record(field, c) === v);
1170
- });
1171
- })) === null || _a === void 0 ? void 0 : _a.filter(function (v) { return v; })) !== null && _b !== void 0 ? _b : []);
1172
- }
1173
- catch (err) {
1174
- console.error('Error resolving database answers for _value', err);
1175
- return [];
1176
- }
1177
- }, [_value, choices, field]);
1178
- var filterResponse = useMemo(function () {
1179
- var _a, _b, _d, _e;
1180
- return (((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseFilter) === null || _b === void 0 ? void 0 : _b.fieldId)
1181
- ? (_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
1182
- : undefined);
1183
- }, [responses, (_e = field.options) === null || _e === void 0 ? void 0 : _e.databaseFilter]);
1184
- // State filtering logic similar to Insurance component
1185
- var addressQuestion = useMemo(function () { return responses === null || responses === void 0 ? void 0 : responses.find(function (r) {
1186
- var _a;
1187
- if (r.answer.type !== 'Address')
1188
- return false;
1189
- if (r.field.intakeField !== 'Address')
1190
- return false;
1191
- // make sure state is actually defined (in case of multiple address questions, where 1+ are blank)
1192
- if (!((_a = r.answer.value) === null || _a === void 0 ? void 0 : _a.state))
1193
- return false;
1194
- return true;
1195
- }); }, [responses]);
1196
- var state = useMemo(function () {
1197
- var _a, _b, _d, _e;
1198
- return (((_a = field.options) === null || _a === void 0 ? void 0 : _a.filterByEnduserState)
1199
- ? ((((_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))
1200
- : undefined);
1201
- }, [enduser === null || enduser === void 0 ? void 0 : enduser.state, addressQuestion, (_f = field.options) === null || _f === void 0 ? void 0 : _f.filterByEnduserState]);
1202
- var filteredChoicesWithPotentialDuplicates = useMemo(function () {
1203
- var _a, _b;
1204
- if (!choices)
1205
- return [];
1206
- if (!filterResponse)
1207
- return choices;
1208
- 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))
1209
- if (!value || value.length === 0)
1210
- return choices;
1211
- return (choices
1212
- .filter(function (c) {
1213
- var _a;
1214
- 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;
1215
- if (!v)
1216
- return true;
1217
- // use .text on r values to handle Database Select types as filter source (in addition to basic text and list of text)
1218
- if (typeof v === 'object') {
1219
- return !!(Object.values(v).find(function (oVal) { return (typeof oVal === 'string' || typeof oVal === 'number'
1220
- ? (Array.isArray(filterResponse)
1221
- ? filterResponse.find(function (r) { return r === oVal.toString() || (typeof r === 'object' && r.text === oVal); })
1222
- : (typeof filterResponse === 'string' || typeof filterResponse === 'number')
1223
- ? filterResponse.toString() === oVal.toString()
1224
- : false)
1225
- : false); }));
1226
- }
1227
- if (typeof v === 'string' || typeof v === 'number') {
1228
- return !!(Array.isArray(filterResponse)
1229
- ? filterResponse.find(function (r) { return r === v.toString() || (typeof r === 'object' && r.text === v); })
1230
- : (typeof filterResponse === 'string' || typeof filterResponse === 'number')
1231
- ? filterResponse.toString() === v.toString()
1232
- : (typeof filterResponse === 'object' && filterResponse.city === v.toString()) ? true
1233
- : (typeof filterResponse === 'object' && filterResponse.state === v.toString()) ? true
1234
- : (typeof filterResponse === 'object' && filterResponse.zipCode === v.toString()) ? true
1235
- : false);
1236
- }
1237
- return false;
1238
- }));
1239
- }, [choices, filterResponse, (_g = field.options) === null || _g === void 0 ? void 0 : _g.databaseFilter, value]);
1240
- // Apply state filtering as a secondary filter (doesn't modify existing logic)
1241
- var stateFilteredChoices = useMemo(function () {
1242
- var _a;
1243
- if (!((_a = field.options) === null || _a === void 0 ? void 0 : _a.filterByEnduserState) || !state) {
1244
- return filteredChoicesWithPotentialDuplicates;
1245
- }
1246
- return filteredChoicesWithPotentialDuplicates.filter(function (c) {
1247
- var _a, _b;
1248
- 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()) || '';
1249
- return !recordState || recordState === state;
1250
- });
1251
- }, [filteredChoicesWithPotentialDuplicates, (_h = field.options) === null || _h === void 0 ? void 0 : _h.filterByEnduserState, state]);
1252
- var filteredChoices = useMemo(function () {
1253
- var filtered = [];
1254
- var uniques = new Set([]);
1255
- for (var _a = 0, stateFilteredChoices_1 = stateFilteredChoices; _a < stateFilteredChoices_1.length; _a++) {
1256
- var c = stateFilteredChoices_1[_a];
1257
- var text = label_for_database_record(field, c);
1258
- if (uniques.has(text))
1259
- continue; // duplicate found
1260
- uniques.add(text);
1261
- filtered.push(c);
1262
- }
1263
- return filtered;
1264
- }, [field, stateFilteredChoices]);
1265
- if (!doneLoading)
1266
- return _jsx(LinearProgress, {});
1267
- return (_jsxs(_Fragment, { children: [_jsx(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
1268
- ? ''
1269
- : label_for_database_record(field, o)); }, value: value, disabled: disabled, onChange: function (_, v) {
1270
- var _a, _b, _d, _e, _f;
1271
- if (v.length && onDatabaseSelect) {
1272
- onDatabaseSelect(((_a = field.options) === null || _a === void 0 ? void 0 : _a.radio)
1273
- ? [v[v.length - 1]] // if radio, only last selected
1274
- : v);
1275
- }
1276
- return onChange((!((_b = field.options) === null || _b === void 0 ? void 0 : _b.radio)
1277
- ? v.map(function (_v) {
1278
- var _a;
1279
- return ({
1280
- databaseId: (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseId,
1281
- recordId: _v.id,
1282
- text: label_for_database_record(field, _v),
1283
- });
1284
- })
1285
- : [{
1286
- databaseId: (_d = field.options) === null || _d === void 0 ? void 0 : _d.databaseId,
1287
- recordId: (_f = (_e = v[v.length - 1]) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : '',
1288
- text: label_for_database_record(field, v[v.length - 1]),
1289
- }]), field.id);
1290
- }, inputValue: typing, onInputChange: function (e, v) { return e && setTyping(v); }, renderInput: function (params) { return _jsx(TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: defaultInputProps.sx }) })); },
1291
- // use custom Chip to ensure very long entries break properly (whitespace: normal)
1292
- renderTags: function (value, getTagProps) {
1293
- return value.map(function (value, index) { return (_jsx(Chip, __assign({ label: _jsx(Typography, __assign({ style: { whiteSpace: 'normal' } }, { children: Array.isArray(value) ? '' : label_for_database_record(field, value) })) }, getTagProps({ index: index }), { sx: { height: "100%", py: 0.5 } }))); });
1294
- } }), AddToDatabase && ((_j = field === null || field === void 0 ? void 0 : field.options) === null || _j === void 0 ? void 0 : _j.allowAddToDatabase) && (_jsx(AddToDatabase, { databaseId: (_k = field.options) === null || _k === void 0 ? void 0 : _k.databaseId, onAdd: addChoice }))] }));
859
+ // DatabaseSelectInput logic is shared with inputs.tsx to avoid duplication
860
+ // Import the interface and component from the shared implementation
861
+ import { DatabaseSelectInput as SharedDatabaseSelectInput } from './inputs';
862
+ // Wrap the shared DatabaseSelectInput component with v2-specific props
863
+ export var DatabaseSelectInput = function (props) {
864
+ // Pass all props plus v2-specific defaultInputProps to the shared component
865
+ return _jsx(SharedDatabaseSelectInput, __assign({}, props, { inputProps: defaultInputProps }));
1295
866
  };
1296
867
  var displayTermsCache = undefined;
1297
868
  var DRUGS_FOR_DISPLAY_TERM = {};
@@ -1663,7 +1234,7 @@ export var contact_is_valid = function (e) {
1663
1234
  };
1664
1235
  export var RelatedContactsInput = function (_a) {
1665
1236
  var _b, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _w, _x;
1666
- var field = _a.field, _value = _a.value, onChange = _a.onChange, props = __rest(_a, ["field", "value", "onChange"]);
1237
+ var field = _a.field, _value = _a.value, onChange = _a.onChange, parentError = _a.error, props = __rest(_a, ["field", "value", "onChange", "error"]);
1667
1238
  // safeguard against any rogue values like empty string
1668
1239
  var value = Array.isArray(_value) ? _value : [];
1669
1240
  var _y = useState(value.length === 1 ? 0 : -1), editing = _y[0], setEditing = _y[1];
@@ -1682,7 +1253,7 @@ export var RelatedContactsInput = function (_a) {
1682
1253
  _jsx(Grid, __assign({ item: true, xs: 4 }, { children: _jsx(TextField, { label: "Last Name", size: "small", fullWidth: true, InputProps: 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); } }) })), _jsx(Grid, __assign({ item: true, xs: 4 }, { children: _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 : 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); } }) }))] })) })), _jsx(Grid, __assign({ item: true }, { children: _jsxs(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')) &&
1683
1254
  _jsx(Grid, __assign({ item: true, xs: 4 }, { children: _jsx(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')) &&
1684
1255
  _jsx(Grid, __assign({ item: true, xs: 4 }, { children: _jsx(TextField, { label: "Email", size: "small", fullWidth: true, type: "email", InputProps: 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')) &&
1685
- _jsx(Grid, __assign({ item: true, xs: 4 }, { children: _jsx(TextField, { label: "Phone Number", size: "small", fullWidth: true, InputProps: 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 &&
1256
+ _jsx(Grid, __assign({ item: true, xs: 4 }, { children: _jsx(TextField, { label: "Phone Number", size: "small", fullWidth: true, InputProps: 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 &&
1686
1257
  _jsx(Grid, __assign({ item: true }, { children: _jsx(Grid, __assign({ container: true, spacing: 1 }, { children: (((_x = field.options) === null || _x === void 0 ? void 0 : _x.tableChoices) || []).map(function (_a, i) {
1687
1258
  var info = _a.info, label = _a.label, type = _a.type;
1688
1259
  return (_jsx(Grid, __assign({ item: true, xs: 6 }, { children: type === 'Text'
@@ -1702,7 +1273,7 @@ export var RelatedContactsInput = function (_a) {
1702
1273
  return i === editing ? __assign(__assign({}, v), { fields: __assign(__assign({}, fields_1), (_a = {}, _a[label] = e.target.value, _a)) }) : v;
1703
1274
  }), field.id); } }, { children: [_jsx(MenuItem, __assign({ value: "" }, { children: _jsx("em", { children: "None" }) })), info.choices.map(function (c) { return (_jsx(MenuItem, __assign({ value: c }, { children: c }), c)); })] }))] })))
1704
1275
  : null }), i));
1705
- }) })) })), _jsx(Grid, __assign({ item: true, sx: { my: 0.75 } }, { children: _jsx(Button, __assign({ variant: "outlined", onClick: function () { return setEditing(-1); }, size: "small" }, { children: "Save Contact" })) })), errorMessage &&
1276
+ }) })) })), _jsx(Grid, __assign({ item: true, sx: { my: 0.75 } }, { children: _jsx(Button, __assign({ variant: "outlined", onClick: function () { return setEditing(-1); }, size: "small", disabled: !!errorMessage || !!parentError }, { children: "Save Contact" })) })), errorMessage &&
1706
1277
  _jsx(Grid, __assign({ item: true }, { children: _jsx(Typography, __assign({ color: "error" }, { children: errorMessage })) }))] })));
1707
1278
  }
1708
1279
  return (_jsxs(Grid, __assign({ container: true, direction: "column", spacing: 1 }, { children: [_jsx(Grid, __assign({ item: true }, { children: value.map(function (contact, i) { return (_jsx(Grid, __assign({ item: true }, { children: _jsxs(Grid, __assign({ container: true, alignItems: "center", justifyContent: "space-between", wrap: "nowrap", spacing: 1 }, { children: [_jsx(Grid, __assign({ item: true }, { children: _jsxs(Grid, __assign({ container: true, alignItems: "center" }, { children: [_jsx(IconButton, __assign({ onClick: function () { return setEditing(i); }, color: "primary", size: "small" }, { children: _jsx(Edit, {}) })), _jsx(Typography, __assign({ noWrap: true }, { children: user_display_name(contact) || "Unnamed Contact ".concat(i + 1) }))] })) })), _jsx(Grid, __assign({ item: true }, { children: _jsx(LabeledIconButton, { Icon: Delete, label: "Remove", onClick: function () { return onChange(value.filter(function (v, _i) { return i !== _i; }), field.id); } }) }))] })) }), i)); }) })), _jsx(Grid, __assign({ item: true }, { children: _jsx(Button, __assign({ variant: "contained", onClick: handleAddContact }, { children: "Add Contact" })) }))] })));