@tellescope/react-components 1.226.0 → 1.227.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -792,23 +792,60 @@ var MultipleChoiceInput = function (_a) {
792
792
  var _b;
793
793
  var field = _a.field, form = _a.form, _value = _a.value, onChange = _a.onChange;
794
794
  var value = typeof _value === 'string' ? [_value] : _value; // if loading existingResponses, allows them to be a string
795
- var _d = field.options, choices = _d.choices, radio = _d.radio, other = _d.other;
795
+ var _d = field.options, choices = _d.choices, radio = _d.radio, other = _d.other, optionDetails = _d.optionDetails;
796
+ var _e = (0, react_1.useState)({}), expandedDescriptions = _e[0], setExpandedDescriptions = _e[1];
796
797
  // current other string
797
798
  var enteringOtherStringRef = react_1.default.useRef(''); // if typing otherString as prefix of a checkbox value, don't auto-select
798
799
  var otherString = (_b = value === null || value === void 0 ? void 0 : value.find(function (v) { var _a; return v === enteringOtherStringRef.current || !((_a = (choices !== null && choices !== void 0 ? choices : [])) === null || _a === void 0 ? void 0 : _a.find(function (c) { return c === v; })); })) !== null && _b !== void 0 ? _b : '';
800
+ var getDescriptionForChoice = (0, react_1.useCallback)(function (choice) {
801
+ var _a;
802
+ return (_a = optionDetails === null || optionDetails === void 0 ? void 0 : optionDetails.find(function (detail) { return detail.option === choice; })) === null || _a === void 0 ? void 0 : _a.description;
803
+ }, [optionDetails]);
804
+ var toggleDescription = (0, react_1.useCallback)(function (index) {
805
+ setExpandedDescriptions(function (prev) {
806
+ var _a;
807
+ return (__assign(__assign({}, prev), (_a = {}, _a[index] = !prev[index], _a)));
808
+ });
809
+ }, []);
799
810
  return ((0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center" }, { children: [radio
800
811
  ? ((0, jsx_runtime_1.jsxs)(material_1.FormControl, __assign({ fullWidth: true }, { children: [(0, jsx_runtime_1.jsx)(material_1.FormLabel, __assign({ id: "radio-group-".concat(field.id, "-label") }, { children: (0, __1.form_display_text_for_language)(form, "Select One") })), (0, jsx_runtime_1.jsx)(material_1.RadioGroup, __assign({ "aria-labelledby": "radio-group-".concat(field.id, "-label"), defaultValue: "female", name: "radio-group-".concat(field.id) }, { children: (choices !== null && choices !== void 0 ? choices : []).map(function (c, i) {
801
- return (0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { color: "primary", label: c, sx: multipleChoiceItemSx, style: { marginLeft: '0px' }, checked: !!(value === null || value === void 0 ? void 0 : value.includes(c)) && c !== otherString, control: (0, jsx_runtime_1.jsx)(material_1.Radio, { onClick: function () { return onChange((value === null || value === void 0 ? void 0 : value.includes(c)) ? [] : [c], field.id); } }) }, i);
802
- }) }))] }))) : ((choices !== null && choices !== void 0 ? choices : []).map(function (c, i) { return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ xs: 12, onClick: function () {
803
- var _a, _b, _d, _e;
804
- return onChange(((value === null || value === void 0 ? void 0 : value.includes(c))
805
- ? ((radio || ((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.radioChoices) === null || _b === void 0 ? void 0 : _b.includes(c)))
806
- ? []
807
- : value.filter(function (v) { return v !== c; }))
808
- : ((radio || ((_e = (_d = field.options) === null || _d === void 0 ? void 0 : _d.radioChoices) === null || _e === void 0 ? void 0 : _e.includes(c)))
809
- ? [c]
810
- : __spreadArray(__spreadArray([], (value !== null && value !== void 0 ? value : []).filter(function (x) { var _a, _b; return !((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.radioChoices) === null || _b === void 0 ? void 0 : _b.includes(x)); }), true), [c], false))), field.id);
811
- } }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap", sx: multipleChoiceItemSx }, { children: [(0, jsx_runtime_1.jsx)(material_1.Checkbox, { color: "primary", checked: !!(value === null || value === void 0 ? void 0 : value.includes(c)) && c !== otherString, inputProps: { 'aria-label': 'primary checkbox' } }), (0, jsx_runtime_1.jsxs)(material_1.Typography, __assign({ component: "span" }, { children: [" ", c, " "] }))] })) }), i)); })), other &&
812
+ var description = getDescriptionForChoice(c);
813
+ var hasDescription = !!description;
814
+ var isExpanded = expandedDescriptions[i];
815
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: { width: '100%' } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, __assign({ sx: { display: 'flex', alignItems: 'center', width: '100%' } }, { children: (0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { sx: __assign(__assign({}, multipleChoiceItemSx), { flex: 1, marginLeft: '0px' }), checked: !!(value === null || value === void 0 ? void 0 : value.includes(c)) && c !== otherString, control: (0, jsx_runtime_1.jsx)(material_1.Radio, { onClick: function () { return onChange((value === null || value === void 0 ? void 0 : value.includes(c)) ? [] : [c], field.id); } }), label: (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: { display: 'flex', alignItems: 'center', width: '100%' } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ component: "span", sx: { flex: 1 } }, { children: c })), hasDescription && ((0, jsx_runtime_1.jsx)(material_1.IconButton, __assign({ size: "small", onClick: function (e) {
816
+ e.stopPropagation();
817
+ toggleDescription(i);
818
+ }, sx: {
819
+ transform: isExpanded ? 'rotate(180deg)' : 'rotate(0deg)',
820
+ transition: 'transform 0.2s',
821
+ ml: 1
822
+ } }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, { fontSize: "small" }) })))] })) }) })), hasDescription && ((0, jsx_runtime_1.jsx)(material_1.Collapse, __assign({ in: isExpanded }, { children: (0, jsx_runtime_1.jsx)(material_1.Box, __assign({ sx: { pl: '42px', pr: 2, pb: 1 } }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "body2", color: "text.secondary" }, { children: description })) })) })))] }), i));
823
+ }) }))] }))) : ((choices !== null && choices !== void 0 ? choices : []).map(function (c, i) {
824
+ var description = getDescriptionForChoice(c);
825
+ var hasDescription = !!description;
826
+ var isExpanded = expandedDescriptions[i];
827
+ return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ xs: 12 }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: { width: '100%' } }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: __assign(__assign({}, multipleChoiceItemSx), { display: 'flex', alignItems: 'center', cursor: 'pointer', width: '100%' }), onClick: function (e) {
828
+ var _a, _b, _d, _e;
829
+ // Don't trigger selection if clicking on the expand button
830
+ if (e.target.closest('.expand-button')) {
831
+ return;
832
+ }
833
+ onChange(((value === null || value === void 0 ? void 0 : value.includes(c))
834
+ ? ((radio || ((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.radioChoices) === null || _b === void 0 ? void 0 : _b.includes(c)))
835
+ ? []
836
+ : value.filter(function (v) { return v !== c; }))
837
+ : ((radio || ((_e = (_d = field.options) === null || _d === void 0 ? void 0 : _d.radioChoices) === null || _e === void 0 ? void 0 : _e.includes(c)))
838
+ ? [c]
839
+ : __spreadArray(__spreadArray([], (value !== null && value !== void 0 ? value : []).filter(function (x) { var _a, _b; return !((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.radioChoices) === null || _b === void 0 ? void 0 : _b.includes(x)); }), true), [c], false))), field.id);
840
+ } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Checkbox, { color: "primary", checked: !!(value === null || value === void 0 ? void 0 : value.includes(c)) && c !== otherString, inputProps: { 'aria-label': 'primary checkbox' } }), (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ component: "span", sx: { flex: 1 } }, { children: c })), hasDescription && ((0, jsx_runtime_1.jsx)(material_1.IconButton, __assign({ className: "expand-button", size: "small", onClick: function (e) {
841
+ e.stopPropagation();
842
+ toggleDescription(i);
843
+ }, sx: {
844
+ transform: isExpanded ? 'rotate(180deg)' : 'rotate(0deg)',
845
+ transition: 'transform 0.2s',
846
+ ml: 1
847
+ } }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, { fontSize: "small" }) })))] })), hasDescription && ((0, jsx_runtime_1.jsx)(material_1.Collapse, __assign({ in: isExpanded }, { children: (0, jsx_runtime_1.jsx)(material_1.Box, __assign({ sx: { pl: '42px', pr: 2, pb: 1 } }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "body2", color: "text.secondary" }, { children: description })) })) })))] })) }), i));
848
+ })), other &&
812
849
  (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField // className={classes.textField}
813
850
  , { InputProps: { sx: { borderRadius: 2.5 } }, sx: { width: radio ? "calc(100% - 15px)" : '100%' }, size: "small", "aria-label": (0, __1.form_display_text_for_language)(form, "Other"), value: otherString, placeholder: (0, __1.form_display_text_for_language)(form, "Other"), variant: "outlined",
814
851
  // onClick={() => !otherChecked && handleOtherChecked()} // allow click to enable when disabled
@@ -832,17 +869,48 @@ var StripeInput = function (_a) {
832
869
  var _f = (0, react_1.useState)(''), businessName = _f[0], setBusinessName = _f[1];
833
870
  var _g = (0, react_1.useState)(false), isCheckout = _g[0], setIsCheckout = _g[1];
834
871
  var _h = (0, react_1.useState)(), stripePromise = _h[0], setStripePromise = _h[1];
835
- var _j = (0, __1.useProducts)({ dontFetch: true }), findProduct = _j[1].findById;
836
- var _k = (0, react_1.useState)(''), answertext = _k[0], setAnswertext = _k[1];
837
- var _l = (0, react_1.useState)(''), error = _l[0], setError = _l[1];
872
+ var _j = (0, react_1.useState)(''), answertext = _j[0], setAnswertext = _j[1];
873
+ var _k = (0, react_1.useState)(''), error = _k[0], setError = _k[1];
874
+ var _l = (0, react_1.useState)([]), selectedProducts = _l[0], setSelectedProducts = _l[1];
875
+ var _m = (0, react_1.useState)(false), showProductSelection = _m[0], setShowProductSelection = _m[1];
876
+ var _o = (0, react_1.useState)([]), availableProducts = _o[0], setAvailableProducts = _o[1];
877
+ var _p = (0, react_1.useState)(false), loadingProducts = _p[0], setLoadingProducts = _p[1];
838
878
  var fetchRef = (0, react_1.useRef)(false);
839
879
  (0, react_1.useEffect)(function () {
840
- var _a;
880
+ var _a, _b, _d;
841
881
  if (fetchRef.current)
842
882
  return;
843
883
  if (value && ((_a = session.userInfo) === null || _a === void 0 ? void 0 : _a.stripeCustomerId)) {
844
884
  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
845
885
  }
886
+ // Check if product selection mode is enabled
887
+ 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) {
888
+ setShowProductSelection(true);
889
+ setLoadingProducts(true);
890
+ // Fetch product data with real-time Stripe pricing via proxy_read
891
+ var productIds = (field.options.productIds || []).join(',');
892
+ session.api.integrations.proxy_read({
893
+ integration: 'Stripe',
894
+ type: 'product-prices',
895
+ id: productIds,
896
+ query: field.options.stripeKey
897
+ })
898
+ .then(function (_a) {
899
+ var data = _a.data;
900
+ setAvailableProducts(data.products || []);
901
+ setLoadingProducts(false);
902
+ })
903
+ .catch(function (e) {
904
+ var _a, _b;
905
+ console.error('Error loading product data:', e);
906
+ 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:'))
907
+ ? e.message.replace('Stripe pricing error: ', '')
908
+ : 'Failed to load product information from Stripe';
909
+ setError("Product configuration error: ".concat(errorMessage));
910
+ setLoadingProducts(false);
911
+ });
912
+ return;
913
+ }
846
914
  fetchRef.current = true;
847
915
  session.api.form_responses.stripe_details({ fieldId: field.id, enduserId: enduserId })
848
916
  .then(function (_a) {
@@ -861,8 +929,71 @@ var StripeInput = function (_a) {
861
929
  }
862
930
  });
863
931
  }, [session, value, field.id, enduserId]);
864
- var cost = ((((_b = field.options) === null || _b === void 0 ? void 0 : _b.productIds) || []).map(function (id) { return findProduct(id, { batch: false }); }) // seems to be having issues with bulk read
865
- .reduce(function (t, p) { var _a; return t + (((_a = p === null || p === void 0 ? void 0 : p.cost) === null || _a === void 0 ? void 0 : _a.amount) || 0); }, 0));
932
+ var cost = (showProductSelection
933
+ ? selectedProducts.reduce(function (total, productId) {
934
+ var _a;
935
+ var product = availableProducts.find(function (p) { return p._id === productId; });
936
+ if (product === null || product === void 0 ? void 0 : product.currentPrice) {
937
+ return total + (product.currentPrice.amount || 0);
938
+ }
939
+ return total + (((_a = product === null || product === void 0 ? void 0 : product.cost) === null || _a === void 0 ? void 0 : _a.amount) || 0);
940
+ }, 0)
941
+ : 0 // Will be calculated by existing Stripe flow when not in selection mode
942
+ );
943
+ // Handle product selection step
944
+ if (showProductSelection) {
945
+ if (error) {
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)(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 })) }))] })));
947
+ }
948
+ if (loadingProducts) {
949
+ 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..." }) }))] })));
950
+ }
951
+ var isSingleSelection_1 = ((_b = field.options) === null || _b === void 0 ? void 0 : _b.radio) === true;
952
+ var handleProductSelection_1 = function (productId) {
953
+ if (isSingleSelection_1) {
954
+ setSelectedProducts([productId]);
955
+ }
956
+ else {
957
+ setSelectedProducts(function (prev) {
958
+ return prev.includes(productId)
959
+ ? prev.filter(function (id) { return id !== productId; })
960
+ : __spreadArray(__spreadArray([], prev, true), [productId], false);
961
+ });
962
+ }
963
+ };
964
+ var handleContinueToPayment = function () {
965
+ if (selectedProducts.length === 0)
966
+ return;
967
+ setShowProductSelection(false);
968
+ fetchRef.current = true;
969
+ // Now fetch Stripe details with selected products
970
+ session.api.form_responses.stripe_details(__assign({ fieldId: field.id, enduserId: enduserId }, (selectedProducts.length > 0 && { selectedProductIds: selectedProducts }) // Pass selected products to Stripe checkout
971
+ ))
972
+ .then(function (_a) {
973
+ var clientSecret = _a.clientSecret, publishableKey = _a.publishableKey, stripeAccount = _a.stripeAccount, businessName = _a.businessName, customerId = _a.customerId, isCheckout = _a.isCheckout, answerText = _a.answerText;
974
+ setAnswertext(answerText || '');
975
+ setIsCheckout(!!isCheckout);
976
+ setClientSecret(clientSecret);
977
+ setStripePromise((0, stripe_js_1.loadStripe)(publishableKey, { stripeAccount: stripeAccount }));
978
+ setBusinessName(businessName);
979
+ setCustomerId(customerId);
980
+ })
981
+ .catch(function (e) {
982
+ console.error(e);
983
+ if (typeof (e === null || e === void 0 ? void 0 : e.message) === 'string') {
984
+ setError(e.message);
985
+ }
986
+ });
987
+ };
988
+ 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) {
989
+ var _a;
990
+ // Use real-time Stripe pricing if available, fallback to Tellescope pricing
991
+ var price = product.currentPrice || product.cost;
992
+ var priceAmount = (price === null || price === void 0 ? void 0 : price.amount) || 0;
993
+ var priceCurrency = (price === null || price === void 0 ? void 0 : price.currency) || 'USD';
994
+ return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true }, { children: (0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { control: isSingleSelection_1 ? ((0, jsx_runtime_1.jsx)(material_1.Radio, { checked: selectedProducts.includes(product._id), onChange: function () { return handleProductSelection_1(product._id); } })) : ((0, jsx_runtime_1.jsx)(material_1.Checkbox, { checked: selectedProducts.includes(product._id), onChange: function () { return handleProductSelection_1(product._id); } })), label: (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "body1", fontWeight: "bold" }, { children: product.title })), product.description && ((0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "body2", color: "textSecondary" }, { children: product.description }))), (0, jsx_runtime_1.jsxs)(material_1.Typography, __assign({ variant: "body2", color: "primary" }, { children: ["$", (priceAmount / 100).toFixed(2), " ", priceCurrency.toUpperCase(), ((_a = product.currentPrice) === null || _a === void 0 ? void 0 : _a.isSubscription) && ((0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ component: "span", variant: "caption", sx: { ml: 0.5 } }, { children: "/month" })))] }))] }) }) }), product._id));
995
+ }), (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" })) }))] })));
996
+ }
866
997
  if (error) {
867
998
  return ((0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error" }, { children: error })));
868
999
  }
@@ -1065,14 +1196,14 @@ var get_other_answers = function (_value, typing) {
1065
1196
  return [];
1066
1197
  };
1067
1198
  var DatabaseSelectInput = function (_a) {
1068
- var _b, _d, _e, _f, _g, _h;
1069
- 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;
1070
- var _j = (0, react_1.useState)(''), typing = _j[0], setTyping = _j[1];
1071
- var _k = useDatabaseChoices({
1199
+ var _b, _d, _e, _f, _g, _h, _j, _k;
1200
+ 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;
1201
+ var _l = (0, react_1.useState)(''), typing = _l[0], setTyping = _l[1];
1202
+ var _m = useDatabaseChoices({
1072
1203
  databaseId: (_b = field.options) === null || _b === void 0 ? void 0 : _b.databaseId,
1073
1204
  field: field,
1074
1205
  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),
1075
- }), addChoice = _k.addChoice, choices = _k.choices, doneLoading = _k.doneLoading;
1206
+ }), addChoice = _m.addChoice, choices = _m.choices, doneLoading = _m.doneLoading;
1076
1207
  var value = react_1.default.useMemo(function () {
1077
1208
  var _a, _b;
1078
1209
  try {
@@ -1095,6 +1226,24 @@ var DatabaseSelectInput = function (_a) {
1095
1226
  ? (_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
1096
1227
  : undefined);
1097
1228
  }, [responses, (_e = field.options) === null || _e === void 0 ? void 0 : _e.databaseFilter]);
1229
+ // State filtering logic similar to Insurance component
1230
+ var addressQuestion = (0, react_1.useMemo)(function () { return responses === null || responses === void 0 ? void 0 : responses.find(function (r) {
1231
+ var _a;
1232
+ if (r.answer.type !== 'Address')
1233
+ return false;
1234
+ if (r.field.intakeField !== 'Address')
1235
+ return false;
1236
+ // make sure state is actually defined (in case of multiple address questions, where 1+ are blank)
1237
+ if (!((_a = r.answer.value) === null || _a === void 0 ? void 0 : _a.state))
1238
+ return false;
1239
+ return true;
1240
+ }); }, [responses]);
1241
+ var state = (0, react_1.useMemo)(function () {
1242
+ var _a, _b, _d, _e;
1243
+ return (((_a = field.options) === null || _a === void 0 ? void 0 : _a.filterByEnduserState)
1244
+ ? ((((_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))
1245
+ : undefined);
1246
+ }, [enduser === null || enduser === void 0 ? void 0 : enduser.state, addressQuestion, (_f = field.options) === null || _f === void 0 ? void 0 : _f.filterByEnduserState]);
1098
1247
  var filteredChoicesWithPotentialDuplicates = (0, react_1.useMemo)(function () {
1099
1248
  var _a, _b;
1100
1249
  if (!choices)
@@ -1132,12 +1281,24 @@ var DatabaseSelectInput = function (_a) {
1132
1281
  }
1133
1282
  return false;
1134
1283
  }));
1135
- }, [choices, filterResponse, (_f = field.options) === null || _f === void 0 ? void 0 : _f.databaseFilter, value]);
1284
+ }, [choices, filterResponse, (_g = field.options) === null || _g === void 0 ? void 0 : _g.databaseFilter, value]);
1285
+ // Apply state filtering as a secondary filter (doesn't modify existing logic)
1286
+ var stateFilteredChoices = (0, react_1.useMemo)(function () {
1287
+ var _a;
1288
+ if (!((_a = field.options) === null || _a === void 0 ? void 0 : _a.filterByEnduserState) || !state) {
1289
+ return filteredChoicesWithPotentialDuplicates;
1290
+ }
1291
+ return filteredChoicesWithPotentialDuplicates.filter(function (c) {
1292
+ var _a, _b;
1293
+ 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()) || '';
1294
+ return !recordState || recordState === state;
1295
+ });
1296
+ }, [filteredChoicesWithPotentialDuplicates, (_h = field.options) === null || _h === void 0 ? void 0 : _h.filterByEnduserState, state]);
1136
1297
  var filteredChoices = (0, react_1.useMemo)(function () {
1137
1298
  var filtered = [];
1138
1299
  var uniques = new Set([]);
1139
- for (var _a = 0, filteredChoicesWithPotentialDuplicates_1 = filteredChoicesWithPotentialDuplicates; _a < filteredChoicesWithPotentialDuplicates_1.length; _a++) {
1140
- var c = filteredChoicesWithPotentialDuplicates_1[_a];
1300
+ for (var _a = 0, stateFilteredChoices_1 = stateFilteredChoices; _a < stateFilteredChoices_1.length; _a++) {
1301
+ var c = stateFilteredChoices_1[_a];
1141
1302
  var text = label_for_database_record(field, c);
1142
1303
  if (uniques.has(text))
1143
1304
  continue; // duplicate found
@@ -1145,7 +1306,7 @@ var DatabaseSelectInput = function (_a) {
1145
1306
  filtered.push(c);
1146
1307
  }
1147
1308
  return filtered;
1148
- }, [field, filteredChoicesWithPotentialDuplicates]);
1309
+ }, [field, stateFilteredChoices]);
1149
1310
  if (!doneLoading)
1150
1311
  return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
1151
1312
  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
@@ -1175,7 +1336,7 @@ var DatabaseSelectInput = function (_a) {
1175
1336
  // use custom Chip to ensure very long entries break properly (whitespace: normal)
1176
1337
  renderTags: function (value, getTagProps) {
1177
1338
  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 } }))); });
1178
- } }), AddToDatabase && ((_g = field === null || field === void 0 ? void 0 : field.options) === null || _g === void 0 ? void 0 : _g.allowAddToDatabase) && ((0, jsx_runtime_1.jsx)(AddToDatabase, { databaseId: (_h = field.options) === null || _h === void 0 ? void 0 : _h.databaseId, onAdd: addChoice }))] }));
1339
+ } }), 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 }))] }));
1179
1340
  };
1180
1341
  exports.DatabaseSelectInput = DatabaseSelectInput;
1181
1342
  var displayTermsCache = undefined;