@frontegg/react-hooks 6.178.0-alpha.2 → 6.178.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 (139) hide show
  1. package/FronteggProvider/index.d.ts +12 -1
  2. package/FronteggProvider/index.js +133 -1
  3. package/FronteggStoreContext/index.d.ts +13 -1
  4. package/FronteggStoreContext/index.js +14 -1
  5. package/audits/auditLogs.d.ts +4 -2
  6. package/audits/auditLogs.js +6 -8
  7. package/audits/auditsMetadata.d.ts +4 -2
  8. package/audits/auditsMetadata.js +6 -8
  9. package/audits/hooks.d.ts +8 -0
  10. package/audits/hooks.js +30 -6
  11. package/auth/{allAccounts.d.ts → MSP/allAccounts.d.ts} +4 -2
  12. package/auth/MSP/allAccounts.js +15 -0
  13. package/auth/acceptInvitation.js +5 -10
  14. package/auth/activateAccount.js +4 -10
  15. package/auth/apiTokens.d.ts +2 -0
  16. package/auth/apiTokens.js +6 -8
  17. package/auth/customLogin.d.ts +5 -2
  18. package/auth/customLogin.js +11 -10
  19. package/auth/entitlements.d.ts +14 -14
  20. package/auth/entitlements.js +21 -25
  21. package/auth/forgotPassword.d.ts +2 -0
  22. package/auth/forgotPassword.js +6 -8
  23. package/auth/groups.d.ts +4 -0
  24. package/auth/groups.js +13 -12
  25. package/auth/hooks.d.ts +11 -10
  26. package/auth/hooks.js +58 -30
  27. package/auth/impersonate.d.ts +2 -0
  28. package/auth/impersonate.js +6 -7
  29. package/auth/index.d.ts +18 -15
  30. package/auth/index.js +19 -16
  31. package/auth/login.d.ts +1 -1
  32. package/auth/login.js +4 -13
  33. package/auth/mfa.d.ts +1 -1
  34. package/auth/mfa.js +4 -13
  35. package/auth/passkeys.d.ts +4 -1
  36. package/auth/passkeys.js +6 -7
  37. package/auth/profile.d.ts +4 -2
  38. package/auth/profile.js +8 -9
  39. package/auth/provisioning.d.ts +3 -1
  40. package/auth/provisioning.js +6 -7
  41. package/auth/resetPhoneNumber.d.ts +3 -1
  42. package/auth/resetPhoneNumber.js +6 -7
  43. package/auth/roles.d.ts +3 -1
  44. package/auth/roles.js +6 -7
  45. package/auth/security/restrictions.d.ts +2 -0
  46. package/auth/security/restrictions.js +10 -10
  47. package/auth/security/securityCenter.d.ts +4 -1
  48. package/auth/security/securityCenter.js +6 -8
  49. package/auth/security/securityPolicy.d.ts +11 -5
  50. package/auth/security/securityPolicy.js +30 -19
  51. package/auth/security/sessionsPolicy.d.ts +3 -1
  52. package/auth/security/sessionsPolicy.js +6 -8
  53. package/auth/sessions.d.ts +3 -1
  54. package/auth/sessions.js +6 -7
  55. package/auth/signup.d.ts +1 -1
  56. package/auth/signup.js +4 -13
  57. package/auth/sms.d.ts +4 -1
  58. package/auth/sms.js +6 -7
  59. package/auth/socialLogin.d.ts +1 -1
  60. package/auth/socialLogin.js +4 -10
  61. package/auth/sso.d.ts +1 -1
  62. package/auth/sso.js +4 -10
  63. package/auth/stepUp/index.d.ts +2 -0
  64. package/auth/stepUp/index.js +2 -0
  65. package/auth/stepUp/interfaces.d.ts +2 -0
  66. package/auth/stepUp/interfaces.js +1 -0
  67. package/auth/{stepUp.d.ts → stepUp/stepUp.d.ts} +2 -0
  68. package/auth/{stepUp.js → stepUp/stepUp.js} +6 -9
  69. package/auth/team.d.ts +1 -9
  70. package/auth/team.js +4 -22
  71. package/auth/tenants.d.ts +3 -1
  72. package/auth/tenants.js +6 -8
  73. package/common/CustomComponentHolder.js +1 -3
  74. package/common/index.js +3 -3
  75. package/connectivity/hooks.d.ts +5 -2
  76. package/connectivity/hooks.js +9 -6
  77. package/index.d.ts +2 -2
  78. package/index.js +3 -3
  79. package/node/FronteggProvider/index.js +134 -9
  80. package/node/FronteggStoreContext/index.js +35 -11
  81. package/node/audits/auditLogs.js +6 -8
  82. package/node/audits/auditsMetadata.js +6 -8
  83. package/node/audits/hooks.js +34 -7
  84. package/node/auth/MSP/allAccounts.js +24 -0
  85. package/node/auth/acceptInvitation.js +5 -7
  86. package/node/auth/activateAccount.js +4 -7
  87. package/node/auth/apiTokens.js +6 -8
  88. package/node/auth/customLogin.js +12 -11
  89. package/node/auth/entitlements.js +20 -24
  90. package/node/auth/forgotPassword.js +6 -8
  91. package/node/auth/groups.js +12 -12
  92. package/node/auth/hooks.js +62 -33
  93. package/node/auth/impersonate.js +6 -7
  94. package/node/auth/index.js +120 -91
  95. package/node/auth/login.js +4 -10
  96. package/node/auth/mfa.js +4 -10
  97. package/node/auth/passkeys.js +6 -7
  98. package/node/auth/profile.js +9 -10
  99. package/node/auth/provisioning.js +6 -7
  100. package/node/auth/resetPhoneNumber.js +6 -7
  101. package/node/auth/roles.js +6 -7
  102. package/node/auth/security/restrictions.js +10 -10
  103. package/node/auth/security/securityCenter.js +6 -8
  104. package/node/auth/security/securityPolicy.js +30 -16
  105. package/node/auth/security/sessionsPolicy.js +6 -8
  106. package/node/auth/sessions.js +6 -7
  107. package/node/auth/signup.js +4 -10
  108. package/node/auth/sms.js +6 -7
  109. package/node/auth/socialLogin.js +4 -7
  110. package/node/auth/sso.js +4 -7
  111. package/node/auth/stepUp/index.js +27 -0
  112. package/node/auth/stepUp/interfaces.js +5 -0
  113. package/node/auth/{stepUp.js → stepUp/stepUp.js} +7 -10
  114. package/node/auth/team.js +4 -25
  115. package/node/auth/tenants.js +6 -8
  116. package/node/common/CustomComponentHolder.js +1 -3
  117. package/node/common/index.js +2 -2
  118. package/node/connectivity/hooks.js +8 -5
  119. package/node/index.js +16 -16
  120. package/node/subscriptions/hooks.js +51 -84
  121. package/node/tests/hooks.tsc-test.js +318 -0
  122. package/node/vendor/hooks.js +6 -5
  123. package/package.json +3 -3
  124. package/subscriptions/hooks.d.ts +10 -32
  125. package/subscriptions/hooks.js +49 -81
  126. package/tests/hooks.tsc-test.js +317 -0
  127. package/vendor/hooks.d.ts +1 -0
  128. package/vendor/hooks.js +7 -9
  129. package/FronteggProvider/FronteggProvider.d.ts +0 -12
  130. package/FronteggProvider/FronteggProvider.js +0 -134
  131. package/FronteggStoreContext/FronteggStoreContext.d.ts +0 -9
  132. package/FronteggStoreContext/FronteggStoreContext.js +0 -16
  133. package/auth/allAccounts.js +0 -20
  134. package/auth/security/index.d.ts +0 -4
  135. package/auth/security/index.js +0 -4
  136. package/node/FronteggProvider/FronteggProvider.js +0 -140
  137. package/node/FronteggStoreContext/FronteggStoreContext.js +0 -26
  138. package/node/auth/allAccounts.js +0 -27
  139. package/node/auth/security/index.js +0 -49
@@ -0,0 +1,318 @@
1
+ "use strict";
2
+
3
+ var _index = require("../index");
4
+ // noinspection JSUnusedLocalSymbols
5
+
6
+ /**
7
+ * useAuth hook typescript tests
8
+ */
9
+ {
10
+ const {
11
+ isAuthenticated,
12
+ isLoading
13
+ } = (0, _index.useAuth)();
14
+ const isLoadingDirect = (0, _index.useAuth)(state => state.isLoading);
15
+ isLoadingDirect.valueOf();
16
+ const {
17
+ user
18
+ } = (0, _index.useAuth)(state => ({
19
+ user: state.user
20
+ }));
21
+ const {
22
+ loginUrl
23
+ } = (0, _index.useAuth)(state => state.routes);
24
+ const {
25
+ loadProfile,
26
+ setLoginState
27
+ } = (0, _index.useAuthActions)();
28
+ }
29
+
30
+ /**
31
+ * useAcceptInvitationState hook typescript tests
32
+ */
33
+ {
34
+ const {
35
+ step
36
+ } = (0, _index.useAcceptInvitationState)();
37
+ const errorDirect = (0, _index.useAcceptInvitationState)(state => state.error);
38
+ errorDirect == null ? void 0 : errorDirect.substring(0);
39
+ const {
40
+ acceptInvitation
41
+ } = (0, _index.useAcceptInvitationActions)();
42
+ }
43
+
44
+ /**
45
+ * useActivateAccountState hook typescript tests
46
+ */
47
+ {
48
+ const {
49
+ step
50
+ } = (0, _index.useActivateAccountState)();
51
+ const loadingDirect = (0, _index.useActivateAccountState)(state => state.loading);
52
+ loadingDirect.valueOf();
53
+ const {
54
+ activateAccount
55
+ } = (0, _index.useActivateAccountActions)();
56
+ }
57
+
58
+ /**
59
+ * useApiTokensState hook typescript tests
60
+ */
61
+ {
62
+ const {
63
+ roles
64
+ } = (0, _index.useApiTokensState)();
65
+ const loadingDirect = (0, _index.useApiTokensState)(state => state.loaders);
66
+ let m = loadingDirect.LOAD_API_TOKENS;
67
+ const {
68
+ loadUserApiTokens
69
+ } = (0, _index.useApiTokensActions)();
70
+ }
71
+
72
+ /**
73
+ * useForgotPasswordState hook typescript tests
74
+ */
75
+ {
76
+ const {
77
+ step
78
+ } = (0, _index.useForgotPasswordState)();
79
+ const emailDirect = (0, _index.useForgotPasswordState)(state => state.email);
80
+ emailDirect.substring(0);
81
+ const {
82
+ forgotPassword
83
+ } = (0, _index.useForgotPasswordActions)();
84
+ }
85
+
86
+ /**
87
+ * useMfaState hook typescript tests
88
+ */
89
+ {
90
+ const {
91
+ step
92
+ } = (0, _index.useMfaState)();
93
+ const loadingDirect = (0, _index.useMfaState)(state => state.loading);
94
+ loadingDirect.valueOf();
95
+ const {
96
+ enrollMfa
97
+ } = (0, _index.useMfaActions)();
98
+ }
99
+
100
+ /**
101
+ * useLoginState hook typescript tests
102
+ */
103
+ {
104
+ const {
105
+ step
106
+ } = (0, _index.useLoginState)();
107
+ const loadingDirect = (0, _index.useLoginState)(state => state.loading);
108
+ loadingDirect.valueOf();
109
+ const {
110
+ logout
111
+ } = (0, _index.useLoginActions)();
112
+ }
113
+
114
+ /**
115
+ * useLoginState hook typescript tests
116
+ */
117
+ {
118
+ const {
119
+ profile
120
+ } = (0, _index.useProfileState)();
121
+ const loadingDirect = (0, _index.useProfileState)(state => state.loading);
122
+ loadingDirect.valueOf();
123
+ const {
124
+ loadProfile
125
+ } = (0, _index.useProfileActions)();
126
+ }
127
+
128
+ /**
129
+ * useResetPhoneNumberState hook typescript tests
130
+ */
131
+ {
132
+ const {
133
+ step
134
+ } = (0, _index.useResetPhoneNumberState)();
135
+ const loadingDirect = (0, _index.useResetPhoneNumberState)(state => state.loading);
136
+ loadingDirect.valueOf();
137
+ const {
138
+ resetPhoneNumber
139
+ } = (0, _index.useResetPhoneNumberActions)();
140
+ }
141
+
142
+ /**
143
+ * useRolesState hook typescript tests
144
+ */
145
+ {
146
+ const {
147
+ saving
148
+ } = (0, _index.useRolesState)();
149
+ const loadingDirect = (0, _index.useRolesState)(state => state.loading);
150
+ loadingDirect.valueOf();
151
+ const {
152
+ loadRolesAndPermissions
153
+ } = (0, _index.useRolesActions)();
154
+ }
155
+
156
+ /**
157
+ * useSecurityPolicyState hook typescript tests
158
+ */
159
+ {
160
+ const {
161
+ lockoutPolicy
162
+ } = (0, _index.useSecurityPolicyState)();
163
+ const captchaPolicy = (0, _index.useSecurityPolicyState)(state => state.captchaPolicy);
164
+ captchaPolicy.loading.valueOf();
165
+ const {
166
+ loadPublicSecurityPolicy
167
+ } = (0, _index.useSecurityPolicyActions)();
168
+ }
169
+
170
+ /**
171
+ * useSessionsState hook typescript tests
172
+ */
173
+ {
174
+ const {
175
+ sessions
176
+ } = (0, _index.useSessionsState)();
177
+ const loadingDirect = (0, _index.useSessionsState)(state => state.loading);
178
+ loadingDirect.valueOf();
179
+ const {
180
+ deleteUserSession
181
+ } = (0, _index.useSessionsActions)();
182
+ }
183
+
184
+ /**
185
+ * useSessionsPolicyState hook typescript tests
186
+ */
187
+ {
188
+ const {
189
+ configurations
190
+ } = (0, _index.useSessionsPolicyState)();
191
+ const loadingDirect = (0, _index.useSessionsPolicyState)(state => state.loading);
192
+ loadingDirect.valueOf();
193
+ const {
194
+ resetSessionsPolicyState
195
+ } = (0, _index.useSessionsPolicyActions)();
196
+ }
197
+
198
+ /**
199
+ * useSSOState hook typescript tests
200
+ */
201
+ {
202
+ const {
203
+ authorizationRoles
204
+ } = (0, _index.useSSOState)();
205
+ const loadingDirect = (0, _index.useSSOState)(state => state.loading);
206
+ loadingDirect.valueOf();
207
+ const {
208
+ loadSSOConfigurationsV2
209
+ } = (0, _index.useSSOActions)();
210
+ }
211
+
212
+ /**
213
+ * useSignUpState hook typescript tests
214
+ */
215
+ {
216
+ const {
217
+ stage
218
+ } = (0, _index.useSignUpState)();
219
+ const loadingDirect = (0, _index.useSignUpState)(state => state.loading);
220
+ loadingDirect.valueOf();
221
+ const {
222
+ setSignUpState
223
+ } = (0, _index.useSignUpActions)();
224
+ }
225
+
226
+ /**
227
+ * useSocialLoginState hook typescript tests
228
+ */
229
+ {
230
+ const {
231
+ socialLoginsConfig
232
+ } = (0, _index.useSocialLoginState)();
233
+ const loadingDirect = (0, _index.useSocialLoginState)(state => state.loading);
234
+ loadingDirect.valueOf();
235
+ const {
236
+ loadSocialLoginsConfiguration
237
+ } = (0, _index.useSocialLoginActions)();
238
+ }
239
+
240
+ /**
241
+ * useSocialLoginState hook typescript tests
242
+ */
243
+ {
244
+ const {
245
+ tenants
246
+ } = (0, _index.useTenantsState)();
247
+ const loadingDirect = (0, _index.useTenantsState)(state => state.loading);
248
+ loadingDirect.valueOf();
249
+ const {
250
+ loadTenants
251
+ } = (0, _index.useTenantsActions)();
252
+ }
253
+
254
+ /**
255
+ * useVendorState hook typescript tests
256
+ */
257
+ {
258
+ const {
259
+ loading
260
+ } = (0, _index.useVendorState)();
261
+ const isLoadingDirect = (0, _index.useVendorState)(state => state.loading);
262
+ isLoadingDirect.valueOf();
263
+ const {
264
+ whiteLabelMode
265
+ } = (0, _index.useVendorState)(state => ({
266
+ whiteLabelMode: state.whiteLabelMode
267
+ }));
268
+ const {
269
+ loadVendorPublicInfo
270
+ } = (0, _index.useVendorActions)();
271
+ }
272
+
273
+ /**
274
+ * useConnectivityState hook typescript tests
275
+ */
276
+ {
277
+ const {
278
+ isLoading,
279
+ error
280
+ } = (0, _index.useConnectivityState)();
281
+ const processIds = (0, _index.useConnectivityState)(state => state.processIds);
282
+ processIds.map(id => id);
283
+ const {
284
+ email
285
+ } = (0, _index.useConnectivityState)(state => {
286
+ var _state$email;
287
+ return {
288
+ email: (_state$email = state.email) != null ? _state$email : []
289
+ };
290
+ });
291
+ email.length;
292
+ const {
293
+ loadScope,
294
+ loadDataAction
295
+ } = (0, _index.useConnectivityActions)();
296
+ }
297
+
298
+ /**
299
+ * useAuditsState hook typescript tests
300
+ */
301
+ {
302
+ const {
303
+ auditLogsState
304
+ } = (0, _index.useAuditsState)();
305
+ const {
306
+ columns
307
+ } = (0, _index.useAuditsState)(state => state.auditsMetadataState);
308
+ const {
309
+ loading
310
+ } = (0, _index.useAuditsState)(state => ({
311
+ loading: state.auditLogsState.loading
312
+ }));
313
+ loading.valueOf();
314
+ let x = columns == null ? void 0 : columns.length;
315
+ const {
316
+ loadAuditLogs
317
+ } = (0, _index.useAuditsActions)();
318
+ }
@@ -5,15 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useVendorActions = void 0;
7
7
  exports.useVendorState = useVendorState;
8
+ var _react = require("react");
9
+ var _reduxStore = require("@frontegg/redux-store");
10
+ var _reactRedux = require("react-redux");
8
11
  var _FronteggStoreContext = require("../FronteggStoreContext");
9
- var _react = require("valtio/react");
10
12
  const defaultMapper = state => state;
11
- // @deprecated use useVendorState() instead
12
13
  function useVendorState(stateMapper = defaultMapper) {
13
- const state = (0, _FronteggStoreContext.useStore)().store.vendor;
14
- return stateMapper((0, _react.useSnapshot)(state));
14
+ return (0, _FronteggStoreContext.useSelector)(state => stateMapper(state[_reduxStore.vendorStoreName]), _reactRedux.shallowEqual);
15
15
  }
16
16
  const useVendorActions = () => {
17
- return (0, _FronteggStoreContext.useStore)().stateActions.vendor;
17
+ const dispatch = (0, _FronteggStoreContext.useDispatch)();
18
+ return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.vendorActions, dispatch), [_reduxStore.vendorActions]);
18
19
  };
19
20
  exports.useVendorActions = useVendorActions;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/react-hooks",
3
- "version": "6.178.0-alpha.2",
3
+ "version": "6.178.0",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.18.6",
9
- "@frontegg/redux-store": "6.178.0-alpha.2",
10
- "@frontegg/types": "6.178.0-alpha.2",
9
+ "@frontegg/redux-store": "6.178.0",
10
+ "@frontegg/types": "6.178.0",
11
11
  "@types/react": "*",
12
12
  "get-value": "^3.0.1",
13
13
  "react-redux": "^7.x"
@@ -1,43 +1,21 @@
1
- import { CheckoutActions, CheckoutState, PaymentProviderConfigActions, PaymentProviderConfigState, PlansActions, PlansState, StripeActions, StripeState, SubscriptionState, BillingInformationState, InvoicesState, PaymentMethodState, BillingStateActions, VendorPublicConfigurationState, VendorPublicConfigurationActions } from '@frontegg/redux-store';
1
+ import { CheckoutActions, CheckoutState, PaymentProviderConfigActions, PaymentProviderConfigState, PlansActions, PlansState, StripeActions, StripeState, SubscriptionActions, SubscriptionState, VendorPublicConfigurationActions, VendorPublicConfigurationState } from '@frontegg/redux-store';
2
2
  export declare const usePaymentProvider: () => PaymentProviderConfigState;
3
3
  export declare const usePaymentProviderActions: () => PaymentProviderConfigActions;
4
4
  export declare const usePlans: () => PlansState;
5
5
  export declare const usePlansActions: () => PlansActions;
6
6
  export declare const useCheckout: () => CheckoutState;
7
7
  export declare const useCheckoutActions: () => CheckoutActions;
8
- export declare const useBillingInformation: () => BillingInformationState;
9
- export declare const useBillingInformationActions: () => {
10
- setBillingInformationState: (state: Partial<BillingInformationState>) => void;
11
- resetBillingInformationState: () => void;
12
- loadSummaries: (tenantId: string, forceActive?: boolean | undefined) => Promise<void>;
13
- loadBillingInformation: (forceActive?: boolean | undefined) => Promise<void>;
14
- };
15
- export declare const usePaymentMethod: () => PaymentMethodState;
16
- export declare const usePaymentMethodActions: () => {
17
- setBillingPaymentMethodState: (state: Partial<{}>) => void;
18
- resetBillingPaymentMethodState: () => void;
19
- loadPaymentMethod: () => Promise<void>;
20
- submitPaymentMethod: () => Promise<void>;
21
- submitPaymentMethodError: (error: string) => Promise<void>;
22
- submitPaymentMethodSuccess: () => Promise<void>;
23
- updatePaymentMethodBillingDetails: (payload: import("@frontegg/redux-store").WithCallback<import("@frontegg/redux-store").WithId<import("@frontegg/rest-api").ISubscriptionUpdatePaymentMethodBillingDetails>, boolean>) => Promise<void>;
24
- };
25
- export declare const useInvoices: () => InvoicesState;
26
- export declare const useInvoicesActions: () => {
27
- setBillingInvoiceState: (state: Partial<InvoicesState>) => void;
28
- resetBillingInvoiceState: () => void;
29
- loadInvoices: () => Promise<void>;
30
- loadBillingInvoices: () => Promise<void>;
31
- downloadInvoice: (payload: import("@frontegg/redux-store").DownloadInvoiceActionPayload) => Promise<void>;
32
- downloadBillingInvoice: (payload: import("@frontegg/redux-store").DownloadInvoiceActionPayload) => Promise<void>;
33
- };
8
+ export declare const useBillingInformation: () => import("@frontegg/redux-store").BillingInformationState;
9
+ export declare const useBillingInformationActions: () => import("@frontegg/redux-store").BillingInformationActions;
10
+ export declare const usePaymentMethod: () => import("@frontegg/redux-store").PaymentMethodState;
11
+ export declare const usePaymentMethodActions: () => import("@frontegg/redux-store").PaymentMethodActions;
12
+ export declare const useInvoices: () => import("@frontegg/redux-store").InvoicesState;
13
+ export declare const useInvoicesActions: () => import("@frontegg/redux-store").InvoicesActions;
14
+ export declare const useStripeState: () => StripeState;
15
+ export declare const useStripeActions: () => StripeActions;
34
16
  export declare const useSubscriptionCancellation: () => SubscriptionState['cancellation'];
35
17
  export declare const useSubscriptionRenewal: () => SubscriptionState['renewal'];
36
18
  export declare const useSubscription: () => SubscriptionState;
37
- export declare const useSubscriptionActions: () => BillingStateActions['subscription'] & {
38
- load: () => void;
39
- };
40
- export declare const useStripeState: () => StripeState;
41
- export declare const useStripeActions: () => StripeActions;
19
+ export declare const useSubscriptionActions: () => SubscriptionActions;
42
20
  export declare const useVendorPublicConfig: () => VendorPublicConfigurationState;
43
21
  export declare const useVendorPublicConfigActions: () => VendorPublicConfigurationActions;
@@ -1,109 +1,77 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { useStore } from '../FronteggStoreContext';
3
- import { useSnapshot } from 'valtio/react';
4
- function getSubscriptionsState() {
5
- // eslint-disable-next-line react-hooks/rules-of-hooks
6
- return useStore().store.subscriptions;
1
+ import { bindActionCreators, subscriptionActions, subscriptionsStoreName } from '@frontegg/redux-store';
2
+ import { useDispatch, useSelector } from '../FronteggStoreContext';
3
+ import { shallowEqual } from 'react-redux';
4
+ import { useMemo } from 'react';
5
+ function getSubscriptionState(state) {
6
+ return state[subscriptionsStoreName];
7
7
  }
8
8
  export const usePaymentProvider = () => {
9
- const {
10
- config
11
- } = getSubscriptionsState();
12
- return useSnapshot(config);
9
+ return useSelector(state => getSubscriptionState(state).config, shallowEqual);
13
10
  };
14
11
  export const usePaymentProviderActions = () => {
15
- return useStore().stateActions.subscriptions.config;
12
+ const dispatch = useDispatch();
13
+ return useMemo(() => bindActionCreators(subscriptionActions.config, dispatch), [dispatch]);
16
14
  };
17
15
  export const usePlans = () => {
18
- const {
19
- plans
20
- } = getSubscriptionsState();
21
- return useSnapshot(plans);
16
+ return useSelector(state => getSubscriptionState(state).plans, shallowEqual);
22
17
  };
23
18
  export const usePlansActions = () => {
24
- return useStore().stateActions.subscriptions.plans;
19
+ const dispatch = useDispatch();
20
+ return useMemo(() => bindActionCreators(subscriptionActions.plans, dispatch), [dispatch]);
25
21
  };
26
22
  export const useCheckout = () => {
27
- const {
28
- checkout
29
- } = getSubscriptionsState();
30
- return useSnapshot(checkout);
23
+ return useSelector(state => getSubscriptionState(state).checkout, shallowEqual);
31
24
  };
32
25
  export const useCheckoutActions = () => {
33
- return useStore().stateActions.subscriptions.checkout;
26
+ const dispatch = useDispatch();
27
+ return useMemo(() => bindActionCreators(subscriptionActions.checkout, dispatch), [dispatch]);
34
28
  };
35
29
  const useBillingActions = billingKey => {
36
- return useStore().stateActions.subscriptions.billing[billingKey];
37
- };
38
- export const useBillingInformation = () => {
39
- const {
40
- billing
41
- } = getSubscriptionsState();
42
- return useSnapshot(billing.information);
43
- };
44
- export const useBillingInformationActions = () => {
45
- return useBillingActions('information');
46
- };
47
- export const usePaymentMethod = () => {
48
- const {
49
- billing
50
- } = getSubscriptionsState();
51
- return useSnapshot(billing.paymentMethod);
52
- };
53
- export const usePaymentMethodActions = () => {
54
- return useBillingActions('paymentMethod');
55
- };
56
- export const useInvoices = () => {
57
- const {
58
- billing
59
- } = getSubscriptionsState();
60
- return useSnapshot(billing.invoices);
30
+ const dispatch = useDispatch();
31
+ return useMemo(() => bindActionCreators(subscriptionActions.billing[billingKey], dispatch), [billingKey, dispatch]);
32
+ };
33
+ export const useBillingInformation = () => useSelector(state => getSubscriptionState(state).billing.information, shallowEqual);
34
+ export const useBillingInformationActions = () => useBillingActions('information');
35
+ export const usePaymentMethod = () => useSelector(state => getSubscriptionState(state).billing.paymentMethod, shallowEqual);
36
+ export const usePaymentMethodActions = () => useBillingActions('paymentMethod');
37
+ export const useInvoices = () => useSelector(state => getSubscriptionState(state).billing.invoices, shallowEqual);
38
+ export const useInvoicesActions = () => useBillingActions('invoices');
39
+ export const useStripeState = () => {
40
+ return useSelector(state => getSubscriptionState(state).stripe, shallowEqual);
61
41
  };
62
- export const useInvoicesActions = () => {
63
- return useBillingActions('invoices');
42
+ export const useStripeActions = () => {
43
+ const dispatch = useDispatch();
44
+ return useMemo(() => bindActionCreators(subscriptionActions.stripe, dispatch), [dispatch]);
64
45
  };
65
46
  export const useSubscriptionCancellation = () => {
66
- const {
67
- billing
68
- } = getSubscriptionsState();
69
- const {
70
- cancellation
71
- } = useSnapshot(billing.subscription);
72
- return cancellation;
47
+ return useSelector(state => getSubscriptionState(state).billing.subscription.cancellation, shallowEqual);
73
48
  };
74
49
  export const useSubscriptionRenewal = () => {
75
- const {
76
- billing
77
- } = getSubscriptionsState();
78
- const {
79
- renewal
80
- } = useSnapshot(billing.subscription);
81
- return renewal;
50
+ return useSelector(state => getSubscriptionState(state).billing.subscription.renewal, shallowEqual);
82
51
  };
83
52
  export const useSubscription = () => {
84
- const {
85
- billing
86
- } = getSubscriptionsState();
87
- return useSnapshot(billing.subscription);
53
+ return useSelector(state => {
54
+ const {
55
+ billing: {
56
+ subscription
57
+ }
58
+ } = getSubscriptionState(state);
59
+ return subscription;
60
+ }, shallowEqual);
88
61
  };
89
62
  export const useSubscriptionActions = () => {
90
- const actions = useStore().stateActions.subscriptions.billing.subscription;
91
- return _extends({}, actions, {
92
- load: actions.loadSubscription
93
- });
94
- };
95
- export const useStripeState = () => {
96
- const {
97
- stripe
98
- } = getSubscriptionsState();
99
- return useSnapshot(stripe);
100
- };
101
- export const useStripeActions = () => {
102
- return useStore().stateActions.subscriptions.stripe;
63
+ const dispatch = useDispatch();
64
+ return useMemo(() => bindActionCreators(subscriptionActions.billing.subscription, dispatch), [dispatch]);
103
65
  };
104
66
  export const useVendorPublicConfig = () => {
105
- return useSnapshot(useStore().store.subscriptions.vendorPublicConfig);
67
+ return useSelector(state => {
68
+ const {
69
+ vendorPublicConfig
70
+ } = getSubscriptionState(state);
71
+ return vendorPublicConfig;
72
+ }, shallowEqual);
106
73
  };
107
74
  export const useVendorPublicConfigActions = () => {
108
- return useStore().stateActions.subscriptions.vendorPublicConfig;
75
+ const dispatch = useDispatch();
76
+ return useMemo(() => bindActionCreators(subscriptionActions.vendorPublicConfig, dispatch), [dispatch]);
109
77
  };