@opexa/portal-components 0.1.25 → 0.1.26

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.
@@ -17,7 +17,7 @@ export function UpdateMobilePhoneNumber({ shouldOnlyShow = 'MobileVerified', } =
17
17
  updateMobilePhoneNumber: ctx.updateMobilePhoneNumber,
18
18
  kyc: ctx.kyc,
19
19
  })));
20
- const { step, step1Form, step2Form, cooldown, formRef, mobileNumberParser, submitStep1, submitStep2, resend, goBackToStep1, } = useUpdateMobileFlow();
20
+ const { step, step1Form, step2Form, cooldown, formRef, mobileNumberParser, submitStep1, submitStep2, resend, goBackToStep1, } = useUpdateMobileFlow(shouldOnlyShow);
21
21
  const isOpen = globalStore.updateMobilePhoneNumber.open && !globalStore.kyc.open;
22
22
  return (_jsx(Dialog.Root, { open: isOpen, lazyMount: true, unmountOnExit: true, closeOnEscape: false, closeOnInteractOutside: false, children: _jsxs(Portal, { children: [_jsx(Dialog.Backdrop, {}), _jsx(Dialog.Positioner, { className: "flex items-center", children: _jsxs(Dialog.Content, { className: "flex w-[375px] flex-col items-center space-y-4 rounded-xl bg-[#111827] p-6 text-center", style: {
23
23
  backgroundImage: `url(${lightBg.src})`,
@@ -1,3 +1,4 @@
1
+ import type { UpdateMobilePhoneNumberShouldOnlyShow } from './useAutoOpen';
1
2
  /**
2
3
  * Encapsulates the entire two-step mobile number update flow:
3
4
  * - step state
@@ -8,7 +9,7 @@
8
9
  * - resend cooldown
9
10
  * - helpers used by the two step components
10
11
  */
11
- export declare function useUpdateMobileFlow(): {
12
+ export declare function useUpdateMobileFlow(shouldOnlyShow?: UpdateMobilePhoneNumberShouldOnlyShow): {
12
13
  step: number;
13
14
  step1Form: import("react-hook-form").UseFormReturn<{
14
15
  mobileNumber: string;
@@ -2,10 +2,12 @@
2
2
  import { zodResolver } from '@hookform/resolvers/zod';
3
3
  import { useRef, useState } from 'react';
4
4
  import { useForm } from 'react-hook-form';
5
+ import { useTimeout } from 'usehooks-ts';
5
6
  import { useShallow } from 'zustand/shallow';
6
7
  import { useAccountQuery } from '../../../client/hooks/useAccountQuery.js';
7
8
  import { useCooldown } from '../../../client/hooks/useCooldown.js';
8
9
  import { useGlobalStore } from '../../../client/hooks/useGlobalStore.js';
10
+ import { useSessionQuery } from '../../../client/hooks/useSessionQuery.js';
9
11
  import { useMobileNumberParser } from '../../../client/hooks/useMobileNumberParser.js';
10
12
  import { useSendVerificationCodeMutation } from '../../../client/hooks/useSendVerificationCodeMutation.js';
11
13
  import { useUpdateMobileNumber } from '../../../client/hooks/useUpdateMobileNumber.js';
@@ -22,12 +24,34 @@ import { useMobileNumberSchemas } from './useMobileNumberSchemas.js';
22
24
  * - resend cooldown
23
25
  * - helpers used by the two step components
24
26
  */
25
- export function useUpdateMobileFlow() {
27
+ export function useUpdateMobileFlow(shouldOnlyShow = 'MobileVerified') {
26
28
  const globalStore = useGlobalStore(useShallow((ctx) => ({
27
29
  updateMobilePhoneNumber: ctx.updateMobilePhoneNumber,
28
30
  kyc: ctx.kyc,
29
31
  })));
30
- const accountQuery = useAccountQuery();
32
+ const pollForMobileVerified = shouldOnlyShow === 'MobileVerified';
33
+ const sessionQuery = useSessionQuery();
34
+ const accountQuery = useAccountQuery(pollForMobileVerified
35
+ ? {
36
+ enabled: sessionQuery.data?.status === 'authenticated' &&
37
+ globalStore.updateMobilePhoneNumber.open,
38
+ refetchInterval: (ctx) => {
39
+ if (ctx.state.data?.mobileNumberVerified === true) {
40
+ return false;
41
+ }
42
+ if (ctx.state.dataUpdateCount > 5) {
43
+ return false;
44
+ }
45
+ return 1000;
46
+ },
47
+ }
48
+ : undefined);
49
+ useTimeout(() => {
50
+ globalStore.updateMobilePhoneNumber.setOpen(false);
51
+ }, pollForMobileVerified &&
52
+ accountQuery.data?.mobileNumberVerified === true
53
+ ? 1
54
+ : null);
31
55
  const mobileNumberParser = useMobileNumberParser();
32
56
  const { Step1Definition, Step2Definition } = useMobileNumberSchemas();
33
57
  const [step, setStep] = useState(1);
@@ -150,7 +150,7 @@ function getErrorMessage(code) {
150
150
  case 'MEMBER_ACCOUNT_SUSPENDED':
151
151
  return 'Your account has been temporarily suspended. Please reach out to the Chat Support team to learn more and get help with resolving the issue.';
152
152
  case 'MEMBER_ACCOUNT_DISABLED':
153
- return 'Your account is being created. Please try again later.';
153
+ return 'Your account is being created. It may take a few minutes to complete. Please try again later.';
154
154
  case 'INVALID_RECAPTCHA_RESPONSE':
155
155
  return 'Invalid reCAPTCHA response';
156
156
  case 'MEMBER_NOT_FOUND':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opexa/portal-components",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
4
4
  "exports": {
5
5
  "./ui/*": {
6
6
  "types": "./dist/ui/*/index.d.ts",