@schematichq/schematic-components 0.7.4 → 0.7.5

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.
@@ -10794,6 +10794,7 @@ function BillingProductDetailResponseDataFromJSONTyped(json, ignoreDiscriminator
10794
10794
  currency: json["currency"],
10795
10795
  environmentId: json["environment_id"],
10796
10796
  externalId: json["external_id"],
10797
+ isActive: json["is_active"],
10797
10798
  name: json["name"],
10798
10799
  price: json["price"],
10799
10800
  priceDecimal: json["price_decimal"] == null ? void 0 : json["price_decimal"],
@@ -10853,6 +10854,7 @@ function BillingProductResponseDataFromJSONTyped(json, ignoreDiscriminator) {
10853
10854
  currency: json["currency"],
10854
10855
  environmentId: json["environment_id"],
10855
10856
  externalId: json["external_id"],
10857
+ isActive: json["is_active"],
10856
10858
  name: json["name"],
10857
10859
  price: json["price"],
10858
10860
  priceDecimal: json["price_decimal"] == null ? void 0 : json["price_decimal"],
@@ -11249,6 +11251,7 @@ function CompanyDetailResponseDataFromJSONTyped(json, ignoreDiscriminator) {
11249
11251
  BillingSubscriptionViewFromJSON
11250
11252
  ),
11251
11253
  createdAt: new Date(json["created_at"]),
11254
+ defaultPaymentMethod: json["default_payment_method"] == null ? void 0 : PaymentMethodResponseDataFromJSON(json["default_payment_method"]),
11252
11255
  entityTraits: json["entity_traits"].map(
11253
11256
  EntityTraitDetailResponseDataFromJSON
11254
11257
  ),
@@ -13190,7 +13193,7 @@ var EmbedProvider = ({
13190
13193
  (0, import_react11.useEffect)(() => {
13191
13194
  if (accessToken) {
13192
13195
  const { headers = {} } = apiConfig ?? {};
13193
- headers["X-Schematic-Components-Version"] = "0.7.4";
13196
+ headers["X-Schematic-Components-Version"] = "0.7.5";
13194
13197
  headers["X-Schematic-Session-ID"] = sessionIdRef.current;
13195
13198
  const config = new Configuration({
13196
13199
  ...apiConfig,
@@ -19568,8 +19571,8 @@ var PaymentMethod = (0, import_react37.forwardRef)(({ children, className, porta
19568
19571
  const props = resolveDesignProps5(rest);
19569
19572
  const { data, setLayout } = useEmbed();
19570
19573
  const paymentMethod = (0, import_react37.useMemo)(() => {
19571
- return data.subscription?.paymentMethod;
19572
- }, [data.subscription?.paymentMethod]);
19574
+ return data.subscription?.paymentMethod || data.company?.defaultPaymentMethod;
19575
+ }, [data.company?.defaultPaymentMethod, data.subscription?.paymentMethod]);
19573
19576
  const monthsToExpiration = (0, import_react37.useMemo)(() => {
19574
19577
  let expiration;
19575
19578
  if (typeof paymentMethod?.cardExpYear === "number" && typeof paymentMethod?.cardExpMonth === "number") {
@@ -19627,10 +19630,10 @@ var PaymentMethodDetails = ({
19627
19630
  const [showDifferentPaymentMethods, setShowDifferentPaymentMethods] = (0, import_react38.useState)(false);
19628
19631
  const [paymentMethod, setPaymentMethod] = (0, import_react38.useState)(void 0);
19629
19632
  (0, import_react38.useEffect)(() => {
19630
- if (data.subscription?.paymentMethod) {
19631
- setPaymentMethod(data.subscription.paymentMethod);
19632
- }
19633
- }, [data.subscription?.paymentMethod]);
19633
+ setPaymentMethod(
19634
+ data.subscription?.paymentMethod || data.company?.defaultPaymentMethod
19635
+ );
19636
+ }, [data.company?.defaultPaymentMethod, data.subscription?.paymentMethod]);
19634
19637
  const monthsToExpiration = (0, import_react38.useMemo)(() => {
19635
19638
  let expiration;
19636
19639
  if (typeof paymentMethod?.cardExpYear === "number" && typeof paymentMethod?.cardExpMonth === "number") {
@@ -19687,15 +19690,31 @@ var PaymentMethodDetails = ({
19687
19690
  if (setPaymentMethodId) {
19688
19691
  setPaymentMethodId(updatePaymentMethodResponse.data.externalId);
19689
19692
  }
19690
- if (data.subscription) {
19691
- setData({
19692
- ...data,
19693
+ setData({
19694
+ ...data,
19695
+ // Optimistic update
19696
+ // If there is subscription - we have set payment method to subscription
19697
+ ...data.subscription ? {
19693
19698
  subscription: {
19694
19699
  ...data.subscription,
19695
19700
  paymentMethod: updatePaymentMethodResponse.data
19696
19701
  }
19697
- });
19698
- }
19702
+ } : {},
19703
+ ...data.company ? {
19704
+ company: {
19705
+ ...data.company,
19706
+ paymentMethods: [
19707
+ updatePaymentMethodResponse.data,
19708
+ ...data.company?.paymentMethods || []
19709
+ ],
19710
+ // Optimistic update
19711
+ // If there is no subscription - we have updated default payment method in company
19712
+ ...data.subscription ? {} : {
19713
+ defaultPaymentMethod: updatePaymentMethodResponse.data
19714
+ }
19715
+ }
19716
+ } : {}
19717
+ });
19699
19718
  } catch {
19700
19719
  setError(t2("Error updating payment method. Please try again."));
19701
19720
  } finally {
@@ -268,6 +268,12 @@ declare interface BillingProductDetailResponseData {
268
268
  * @memberof BillingProductDetailResponseData
269
269
  */
270
270
  externalId: string;
271
+ /**
272
+ *
273
+ * @type {boolean}
274
+ * @memberof BillingProductDetailResponseData
275
+ */
276
+ isActive: boolean;
271
277
  /**
272
278
  *
273
279
  * @type {string}
@@ -524,6 +530,12 @@ declare interface BillingProductResponseData {
524
530
  * @memberof BillingProductResponseData
525
531
  */
526
532
  externalId: string;
533
+ /**
534
+ *
535
+ * @type {boolean}
536
+ * @memberof BillingProductResponseData
537
+ */
538
+ isActive: boolean;
527
539
  /**
528
540
  *
529
541
  * @type {string}
@@ -1190,6 +1202,12 @@ declare interface CompanyDetailResponseData {
1190
1202
  * @memberof CompanyDetailResponseData
1191
1203
  */
1192
1204
  createdAt: Date;
1205
+ /**
1206
+ *
1207
+ * @type {PaymentMethodResponseData}
1208
+ * @memberof CompanyDetailResponseData
1209
+ */
1210
+ defaultPaymentMethod?: PaymentMethodResponseData;
1193
1211
  /**
1194
1212
  *
1195
1213
  * @type {Array<EntityTraitDetailResponseData>}
@@ -10741,6 +10741,7 @@ function BillingProductDetailResponseDataFromJSONTyped(json, ignoreDiscriminator
10741
10741
  currency: json["currency"],
10742
10742
  environmentId: json["environment_id"],
10743
10743
  externalId: json["external_id"],
10744
+ isActive: json["is_active"],
10744
10745
  name: json["name"],
10745
10746
  price: json["price"],
10746
10747
  priceDecimal: json["price_decimal"] == null ? void 0 : json["price_decimal"],
@@ -10800,6 +10801,7 @@ function BillingProductResponseDataFromJSONTyped(json, ignoreDiscriminator) {
10800
10801
  currency: json["currency"],
10801
10802
  environmentId: json["environment_id"],
10802
10803
  externalId: json["external_id"],
10804
+ isActive: json["is_active"],
10803
10805
  name: json["name"],
10804
10806
  price: json["price"],
10805
10807
  priceDecimal: json["price_decimal"] == null ? void 0 : json["price_decimal"],
@@ -11196,6 +11198,7 @@ function CompanyDetailResponseDataFromJSONTyped(json, ignoreDiscriminator) {
11196
11198
  BillingSubscriptionViewFromJSON
11197
11199
  ),
11198
11200
  createdAt: new Date(json["created_at"]),
11201
+ defaultPaymentMethod: json["default_payment_method"] == null ? void 0 : PaymentMethodResponseDataFromJSON(json["default_payment_method"]),
11199
11202
  entityTraits: json["entity_traits"].map(
11200
11203
  EntityTraitDetailResponseDataFromJSON
11201
11204
  ),
@@ -13137,7 +13140,7 @@ var EmbedProvider = ({
13137
13140
  useEffect2(() => {
13138
13141
  if (accessToken) {
13139
13142
  const { headers = {} } = apiConfig ?? {};
13140
- headers["X-Schematic-Components-Version"] = "0.7.4";
13143
+ headers["X-Schematic-Components-Version"] = "0.7.5";
13141
13144
  headers["X-Schematic-Session-ID"] = sessionIdRef.current;
13142
13145
  const config = new Configuration({
13143
13146
  ...apiConfig,
@@ -19529,8 +19532,8 @@ var PaymentMethod = forwardRef11(({ children, className, portal, allowEdit = tru
19529
19532
  const props = resolveDesignProps5(rest);
19530
19533
  const { data, setLayout } = useEmbed();
19531
19534
  const paymentMethod = useMemo12(() => {
19532
- return data.subscription?.paymentMethod;
19533
- }, [data.subscription?.paymentMethod]);
19535
+ return data.subscription?.paymentMethod || data.company?.defaultPaymentMethod;
19536
+ }, [data.company?.defaultPaymentMethod, data.subscription?.paymentMethod]);
19534
19537
  const monthsToExpiration = useMemo12(() => {
19535
19538
  let expiration;
19536
19539
  if (typeof paymentMethod?.cardExpYear === "number" && typeof paymentMethod?.cardExpMonth === "number") {
@@ -19588,10 +19591,10 @@ var PaymentMethodDetails = ({
19588
19591
  const [showDifferentPaymentMethods, setShowDifferentPaymentMethods] = useState14(false);
19589
19592
  const [paymentMethod, setPaymentMethod] = useState14(void 0);
19590
19593
  useEffect7(() => {
19591
- if (data.subscription?.paymentMethod) {
19592
- setPaymentMethod(data.subscription.paymentMethod);
19593
- }
19594
- }, [data.subscription?.paymentMethod]);
19594
+ setPaymentMethod(
19595
+ data.subscription?.paymentMethod || data.company?.defaultPaymentMethod
19596
+ );
19597
+ }, [data.company?.defaultPaymentMethod, data.subscription?.paymentMethod]);
19595
19598
  const monthsToExpiration = useMemo13(() => {
19596
19599
  let expiration;
19597
19600
  if (typeof paymentMethod?.cardExpYear === "number" && typeof paymentMethod?.cardExpMonth === "number") {
@@ -19648,15 +19651,31 @@ var PaymentMethodDetails = ({
19648
19651
  if (setPaymentMethodId) {
19649
19652
  setPaymentMethodId(updatePaymentMethodResponse.data.externalId);
19650
19653
  }
19651
- if (data.subscription) {
19652
- setData({
19653
- ...data,
19654
+ setData({
19655
+ ...data,
19656
+ // Optimistic update
19657
+ // If there is subscription - we have set payment method to subscription
19658
+ ...data.subscription ? {
19654
19659
  subscription: {
19655
19660
  ...data.subscription,
19656
19661
  paymentMethod: updatePaymentMethodResponse.data
19657
19662
  }
19658
- });
19659
- }
19663
+ } : {},
19664
+ ...data.company ? {
19665
+ company: {
19666
+ ...data.company,
19667
+ paymentMethods: [
19668
+ updatePaymentMethodResponse.data,
19669
+ ...data.company?.paymentMethods || []
19670
+ ],
19671
+ // Optimistic update
19672
+ // If there is no subscription - we have updated default payment method in company
19673
+ ...data.subscription ? {} : {
19674
+ defaultPaymentMethod: updatePaymentMethodResponse.data
19675
+ }
19676
+ }
19677
+ } : {}
19678
+ });
19660
19679
  } catch {
19661
19680
  setError(t2("Error updating payment method. Please try again."));
19662
19681
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematichq/schematic-components",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "main": "dist/schematic-components.cjs.js",
5
5
  "module": "dist/schematic-components.esm.js",
6
6
  "types": "dist/schematic-components.d.ts",