@tellescope/react-components 1.230.2 → 1.232.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/lib/cjs/Forms/forms.js +2 -2
  2. package/lib/cjs/Forms/forms.js.map +1 -1
  3. package/lib/cjs/Forms/forms.v2.js +4 -4
  4. package/lib/cjs/Forms/forms.v2.js.map +1 -1
  5. package/lib/cjs/Forms/hooks.d.ts +111 -3
  6. package/lib/cjs/Forms/hooks.d.ts.map +1 -1
  7. package/lib/cjs/Forms/hooks.js +30 -38
  8. package/lib/cjs/Forms/hooks.js.map +1 -1
  9. package/lib/cjs/Forms/inputs.d.ts +2 -2
  10. package/lib/cjs/Forms/inputs.d.ts.map +1 -1
  11. package/lib/cjs/Forms/inputs.js +71 -18
  12. package/lib/cjs/Forms/inputs.js.map +1 -1
  13. package/lib/cjs/Forms/inputs.v2.d.ts +2 -4
  14. package/lib/cjs/Forms/inputs.v2.d.ts.map +1 -1
  15. package/lib/cjs/Forms/inputs.v2.js +13 -242
  16. package/lib/cjs/Forms/inputs.v2.js.map +1 -1
  17. package/lib/esm/CMS/components.d.ts +1 -0
  18. package/lib/esm/CMS/components.d.ts.map +1 -1
  19. package/lib/esm/Forms/form_responses.d.ts +1 -0
  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 +2 -2
  23. package/lib/esm/Forms/forms.js.map +1 -1
  24. package/lib/esm/Forms/forms.v2.d.ts +3 -3
  25. package/lib/esm/Forms/forms.v2.js +4 -4
  26. package/lib/esm/Forms/forms.v2.js.map +1 -1
  27. package/lib/esm/Forms/hooks.d.ts +112 -3
  28. package/lib/esm/Forms/hooks.d.ts.map +1 -1
  29. package/lib/esm/Forms/hooks.js +31 -39
  30. package/lib/esm/Forms/hooks.js.map +1 -1
  31. package/lib/esm/Forms/inputs.d.ts +3 -3
  32. package/lib/esm/Forms/inputs.d.ts.map +1 -1
  33. package/lib/esm/Forms/inputs.js +72 -19
  34. package/lib/esm/Forms/inputs.js.map +1 -1
  35. package/lib/esm/Forms/inputs.v2.d.ts +3 -5
  36. package/lib/esm/Forms/inputs.v2.d.ts.map +1 -1
  37. package/lib/esm/Forms/inputs.v2.js +15 -244
  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 +1 -0
  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 +2 -2
  47. package/src/Forms/forms.v2.tsx +12 -12
  48. package/src/Forms/hooks.tsx +49 -62
  49. package/src/Forms/inputs.tsx +73 -6
  50. package/src/Forms/inputs.v2.tsx +23 -404
@@ -861,20 +861,59 @@ var MultipleChoiceInput = function (_a) {
861
861
  } }) }))] })));
862
862
  };
863
863
  exports.MultipleChoiceInput = MultipleChoiceInput;
864
+ // Helper to emit GTM purchase event for Stripe payments (single source of truth)
865
+ var emitStripePurchaseEvent = function (field, cost) {
866
+ var _a;
867
+ (0, utilities_1.emit_gtm_event)({
868
+ event: 'form_purchase',
869
+ productIds: ((_a = field.options) === null || _a === void 0 ? void 0 : _a.productIds) || [],
870
+ fieldId: field.id,
871
+ value: cost / 100,
872
+ currency: 'USD',
873
+ });
874
+ };
864
875
  var StripeInput = function (_a) {
865
- var _b, _d;
866
- var field = _a.field, value = _a.value, onChange = _a.onChange, setCustomerId = _a.setCustomerId, enduserId = _a.enduserId;
876
+ var _b, _d, _e;
877
+ var field = _a.field, value = _a.value, onChange = _a.onChange, setCustomerId = _a.setCustomerId, enduserId = _a.enduserId, form = _a.form, responses = _a.responses, enduser = _a.enduser;
867
878
  var session = (0, __1.useResolvedSession)();
868
- var _e = (0, react_1.useState)(''), clientSecret = _e[0], setClientSecret = _e[1];
869
- var _f = (0, react_1.useState)(''), businessName = _f[0], setBusinessName = _f[1];
870
- var _g = (0, react_1.useState)(false), isCheckout = _g[0], setIsCheckout = _g[1];
871
- var _h = (0, react_1.useState)(), stripePromise = _h[0], setStripePromise = _h[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];
879
+ var _f = (0, react_1.useState)(''), clientSecret = _f[0], setClientSecret = _f[1];
880
+ var _g = (0, react_1.useState)(''), businessName = _g[0], setBusinessName = _g[1];
881
+ var _h = (0, react_1.useState)(false), isCheckout = _h[0], setIsCheckout = _h[1];
882
+ var _j = (0, react_1.useState)(), stripePromise = _j[0], setStripePromise = _j[1];
883
+ var _k = (0, react_1.useState)(''), answertext = _k[0], setAnswertext = _k[1];
884
+ var _l = (0, react_1.useState)(''), error = _l[0], setError = _l[1];
885
+ var _m = (0, react_1.useState)([]), selectedProducts = _m[0], setSelectedProducts = _m[1];
886
+ var _o = (0, react_1.useState)(false), showProductSelection = _o[0], setShowProductSelection = _o[1];
887
+ var _p = (0, react_1.useState)([]), availableProducts = _p[0], setAvailableProducts = _p[1];
888
+ var _q = (0, react_1.useState)(false), loadingProducts = _q[0], setLoadingProducts = _q[1];
889
+ // Compute visible products based on conditional logic
890
+ var visibleProducts = (0, react_1.useMemo)(function () {
891
+ if (!showProductSelection || availableProducts.length === 0) {
892
+ return availableProducts;
893
+ }
894
+ return availableProducts.filter(function (product) {
895
+ var _a, _b;
896
+ // Find condition for this product
897
+ var productCondition = (_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.productConditions) === null || _b === void 0 ? void 0 : _b.find(function (c) { return c.productId === product._id; });
898
+ // If no condition defined, show by default
899
+ if (!(productCondition === null || productCondition === void 0 ? void 0 : productCondition.showCondition) || (0, utilities_1.object_is_empty)(productCondition.showCondition)) {
900
+ return true;
901
+ }
902
+ // Evaluate condition against current form responses
903
+ return (0, utilities_1.responses_satisfy_conditions)(responses || [], productCondition.showCondition, {
904
+ dateOfBirth: enduser === null || enduser === void 0 ? void 0 : enduser.dateOfBirth,
905
+ gender: enduser === null || enduser === void 0 ? void 0 : enduser.gender,
906
+ state: enduser === null || enduser === void 0 ? void 0 : enduser.state,
907
+ form: form,
908
+ activeResponses: responses,
909
+ });
910
+ });
911
+ }, [availableProducts, (_b = field.options) === null || _b === void 0 ? void 0 : _b.productConditions, responses, showProductSelection, enduser, form]);
912
+ // Automatically deselect products that become hidden
913
+ (0, react_1.useEffect)(function () {
914
+ var visibleProductIds = visibleProducts.map(function (p) { return p._id; });
915
+ setSelectedProducts(function (prev) { return prev.filter(function (id) { return visibleProductIds.includes(id); }); });
916
+ }, [visibleProducts]);
878
917
  var fetchRef = (0, react_1.useRef)(false);
879
918
  (0, react_1.useEffect)(function () {
880
919
  var _a, _b, _d;
@@ -940,6 +979,16 @@ var StripeInput = function (_a) {
940
979
  }, 0)
941
980
  : 0 // Will be calculated by existing Stripe flow when not in selection mode
942
981
  );
982
+ // Emit GTM purchase event once when success screen is displayed
983
+ var purchaseEmittedRef = (0, react_1.useRef)(false);
984
+ (0, react_1.useEffect)(function () {
985
+ var _a;
986
+ // Only emit for actual purchases (chargeImmediately), not for saving card details
987
+ if (value && ((_a = field.options) === null || _a === void 0 ? void 0 : _a.chargeImmediately) && !purchaseEmittedRef.current) {
988
+ emitStripePurchaseEvent(field, cost);
989
+ purchaseEmittedRef.current = true;
990
+ }
991
+ }, [value, field, cost]);
943
992
  // Handle product selection step
944
993
  if (showProductSelection) {
945
994
  if (error) {
@@ -948,7 +997,11 @@ var StripeInput = function (_a) {
948
997
  if (loadingProducts) {
949
998
  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
999
  }
951
- var isSingleSelection_1 = ((_b = field.options) === null || _b === void 0 ? void 0 : _b.radio) === true;
1000
+ // Check if all products are filtered out by conditional logic
1001
+ if (visibleProducts.length === 0) {
1002
+ return ((0, jsx_runtime_1.jsx)(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: "textSecondary" }, { children: "No products are available based on your previous answers." })) })) })));
1003
+ }
1004
+ var isSingleSelection_1 = ((_d = field.options) === null || _d === void 0 ? void 0 : _d.radio) === true;
952
1005
  var handleProductSelection_1 = function (productId) {
953
1006
  if (isSingleSelection_1) {
954
1007
  setSelectedProducts([productId]);
@@ -985,7 +1038,7 @@ var StripeInput = function (_a) {
985
1038
  }
986
1039
  });
987
1040
  };
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) {
1041
+ 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'] })) })), visibleProducts.map(function (product) {
989
1042
  var _a, _b, _d;
990
1043
  // Use real-time Stripe pricing if available, fallback to Tellescope pricing
991
1044
  var price = product.currentPrice || product.cost;
@@ -998,7 +1051,7 @@ var StripeInput = function (_a) {
998
1051
  return ((0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: "error" }, { children: error })));
999
1052
  }
1000
1053
  if (value) {
1001
- 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!" }))] })));
1054
+ 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: ((_e = field.options) === null || _e === void 0 ? void 0 : _e.chargeImmediately) ? 'Your purchase was successful' : "Your payment details have been saved!" }))] })));
1002
1055
  }
1003
1056
  if (!(clientSecret && stripePromise))
1004
1057
  return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
@@ -1713,7 +1766,7 @@ var contact_is_valid = function (e) {
1713
1766
  exports.contact_is_valid = contact_is_valid;
1714
1767
  var RelatedContactsInput = function (_a) {
1715
1768
  var _b, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _w, _x;
1716
- var field = _a.field, _value = _a.value, onChange = _a.onChange, props = __rest(_a, ["field", "value", "onChange"]);
1769
+ var field = _a.field, _value = _a.value, onChange = _a.onChange, parentError = _a.error, props = __rest(_a, ["field", "value", "onChange", "error"]);
1717
1770
  // safeguard against any rogue values like empty string
1718
1771
  var value = Array.isArray(_value) ? _value : [];
1719
1772
  var _y = (0, react_1.useState)(value.length === 1 ? 0 : -1), editing = _y[0], setEditing = _y[1];
@@ -1732,7 +1785,7 @@ var RelatedContactsInput = function (_a) {
1732
1785
  (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')) &&
1733
1786
  (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')) &&
1734
1787
  (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')) &&
1735
- (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 &&
1788
+ (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 &&
1736
1789
  (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) {
1737
1790
  var info = _a.info, label = _a.label, type = _a.type;
1738
1791
  return ((0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 6 }, { children: type === 'Text'
@@ -1752,7 +1805,7 @@ var RelatedContactsInput = function (_a) {
1752
1805
  return i === editing ? __assign(__assign({}, v), { fields: __assign(__assign({}, fields_1), (_a = {}, _a[label] = e.target.value, _a)) }) : v;
1753
1806
  }), 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)); })] }))] })))
1754
1807
  : null }), i));
1755
- }) })) })), (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 &&
1808
+ }) })) })), (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 &&
1756
1809
  (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 })) }))] })));
1757
1810
  }
1758
1811
  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" })) }))] })));