@opexa/portal-components 0.1.7 → 0.1.8
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.
- package/dist/components/UpdateMobilePhoneNumber/UpdateMobilePhoneNumber.d.ts +6 -1
- package/dist/components/UpdateMobilePhoneNumber/UpdateMobilePhoneNumber.js +3 -3
- package/dist/components/UpdateMobilePhoneNumber/hooks/useAutoOpen.d.ts +8 -0
- package/dist/components/UpdateMobilePhoneNumber/hooks/useAutoOpen.js +48 -0
- package/package.json +1 -1
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { type UpdateMobilePhoneNumberShouldOnlyShow } from './hooks/useAutoOpen';
|
|
2
|
+
export type { UpdateMobilePhoneNumberShouldOnlyShow };
|
|
3
|
+
type UpdateMobilePhoneNumberProps = {
|
|
4
|
+
shouldOnlyShow?: UpdateMobilePhoneNumberShouldOnlyShow;
|
|
5
|
+
};
|
|
6
|
+
export declare function UpdateMobilePhoneNumber({ shouldOnlyShow, }?: UpdateMobilePhoneNumberProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -10,10 +10,10 @@ import { Dialog } from '../../ui/Dialog/index.js';
|
|
|
10
10
|
import { Portal } from '../../ui/Portal/index.js';
|
|
11
11
|
import { Step1MobileNumberForm } from './components/Step1MobileNumberForm.js';
|
|
12
12
|
import { Step2VerificationForm } from './components/Step2VerificationForm.js';
|
|
13
|
-
import {
|
|
13
|
+
import { useAutoOpen, } from './hooks/useAutoOpen.js';
|
|
14
14
|
import { useUpdateMobileFlow } from './hooks/useUpdateMobileFlow.js';
|
|
15
|
-
export function UpdateMobilePhoneNumber() {
|
|
16
|
-
|
|
15
|
+
export function UpdateMobilePhoneNumber({ shouldOnlyShow = 'MobileVerified', } = {}) {
|
|
16
|
+
useAutoOpen(shouldOnlyShow);
|
|
17
17
|
const featureFlag = useFeatureFlag();
|
|
18
18
|
const globalStore = useGlobalStore(useShallow((ctx) => ({
|
|
19
19
|
updateMobilePhoneNumber: ctx.updateMobilePhoneNumber,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type UpdateMobilePhoneNumberShouldOnlyShow = 'MobileVerified' | 'HasMobile';
|
|
2
|
+
/**
|
|
3
|
+
* Opens the UpdateMobilePhoneNumber dialog automatically (once per mount) if
|
|
4
|
+
* the account has finished loading and:
|
|
5
|
+
* - `MobileVerified` (default): the mobile number is not verified; closes if verified.
|
|
6
|
+
* - `HasMobile`: the user has no mobile number (`mobileNumber` is null); closes if set.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useAutoOpen(shouldOnlyShow?: UpdateMobilePhoneNumberShouldOnlyShow): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { useShallow } from 'zustand/shallow';
|
|
4
|
+
import { useAccountQuery } from '../../../client/hooks/useAccountQuery.js';
|
|
5
|
+
import { useGlobalStore } from '../../../client/hooks/useGlobalStore.js';
|
|
6
|
+
/**
|
|
7
|
+
* Opens the UpdateMobilePhoneNumber dialog automatically (once per mount) if
|
|
8
|
+
* the account has finished loading and:
|
|
9
|
+
* - `MobileVerified` (default): the mobile number is not verified; closes if verified.
|
|
10
|
+
* - `HasMobile`: the user has no mobile number (`mobileNumber` is null); closes if set.
|
|
11
|
+
*/
|
|
12
|
+
export function useAutoOpen(shouldOnlyShow = 'MobileVerified') {
|
|
13
|
+
const { setOpen } = useGlobalStore(useShallow((ctx) => ({
|
|
14
|
+
setOpen: ctx.updateMobilePhoneNumber.setOpen,
|
|
15
|
+
})));
|
|
16
|
+
const accountQuery = useAccountQuery();
|
|
17
|
+
const account = accountQuery.data;
|
|
18
|
+
const isAccountLoading = accountQuery.isLoading;
|
|
19
|
+
const isMobileNumberVerified = account?.mobileNumberVerified === true;
|
|
20
|
+
const hasMobileNumber = account?.mobileNumber != null;
|
|
21
|
+
const hasExecuted = useRef(false);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!isAccountLoading && !!account && !hasExecuted.current) {
|
|
24
|
+
if (shouldOnlyShow === 'HasMobile') {
|
|
25
|
+
if (!hasMobileNumber) {
|
|
26
|
+
setOpen(true);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
setOpen(false);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (!isMobileNumberVerified) {
|
|
33
|
+
setOpen(true);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
setOpen(false);
|
|
37
|
+
}
|
|
38
|
+
hasExecuted.current = true;
|
|
39
|
+
}
|
|
40
|
+
}, [
|
|
41
|
+
isAccountLoading,
|
|
42
|
+
account,
|
|
43
|
+
hasMobileNumber,
|
|
44
|
+
isMobileNumberVerified,
|
|
45
|
+
shouldOnlyShow,
|
|
46
|
+
setOpen,
|
|
47
|
+
]);
|
|
48
|
+
}
|