@opexa/portal-components 0.1.7 → 0.1.12

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.
@@ -138,7 +138,12 @@ export function InstapayGCashWithdrawal() {
138
138
  bankCode: 'BNKGCH',
139
139
  });
140
140
  });
141
- return (_jsxs("form", { onSubmit: handleSubmit, noValidate: true, autoComplete: "off", id: "hook-form", children: [_jsxs(Field.Root, { invalid: !!form.formState.errors.accountNumber, className: "mt-3xl", children: [_jsx(Field.Label, { children: "Phone Number" }), _jsx(Field.Input, { type: "number", ...form.register('accountNumber'), onKeyDown: (e) => {
141
+ return (_jsxs("form", { onSubmit: handleSubmit, noValidate: true, autoComplete: "off", id: "hook-form", children: [_jsxs(Field.Root, { invalid: !!form.formState.errors.accountNumber, className: "mt-3xl", children: [_jsx(Field.Label, { children: "Phone Number" }), _jsx(Field.Input, { type: "text", inputMode: "numeric", pattern: "[0-9]*", ...form.register('accountNumber', {
142
+ setValueAs: (value) => value.replace(/\D/g, ''),
143
+ onChange: (e) => {
144
+ e.target.value = e.target.value.replace(/\D/g, '');
145
+ },
146
+ }), onKeyDown: (e) => {
142
147
  if (['e', 'E', '.', '-', '+', ','].includes(e.key)) {
143
148
  e.preventDefault();
144
149
  }
@@ -138,7 +138,12 @@ export function InstapayPaymayaWithdrawal() {
138
138
  bankCode: 'BNKMYA',
139
139
  });
140
140
  });
141
- return (_jsxs("form", { onSubmit: handleSubmit, noValidate: true, autoComplete: "off", id: "hook-form", children: [_jsxs(Field.Root, { invalid: !!form.formState.errors.accountNumber, className: "mt-3xl", children: [_jsx(Field.Label, { children: "Phone Number" }), _jsx(Field.Input, { type: "number", ...form.register('accountNumber'), onKeyDown: (e) => {
141
+ return (_jsxs("form", { onSubmit: handleSubmit, noValidate: true, autoComplete: "off", id: "hook-form", children: [_jsxs(Field.Root, { invalid: !!form.formState.errors.accountNumber, className: "mt-3xl", children: [_jsx(Field.Label, { children: "Phone Number" }), _jsx(Field.Input, { type: "text", inputMode: "numeric", pattern: "[0-9]*", ...form.register('accountNumber', {
142
+ setValueAs: (value) => value.replace(/\D/g, ''),
143
+ onChange: (e) => {
144
+ e.target.value = e.target.value.replace(/\D/g, '');
145
+ },
146
+ }), onKeyDown: (e) => {
142
147
  if (['e', 'E', '.', '-', '+', ','].includes(e.key)) {
143
148
  e.preventDefault();
144
149
  }
@@ -177,7 +177,12 @@ export function InstapayWithdrawal() {
177
177
  sameWidth: true,
178
178
  }, value: o.field.value ? [o.field.value] : [], onValueChange: (details) => {
179
179
  o.field.onChange(details.value.at(0) ?? '');
180
- }, children: [_jsx(Select.Label, { children: "Bank" }), _jsx(Select.Control, { children: _jsxs(Select.Trigger, { children: [_jsx(Select.ValueText, {}), _jsx(Select.Indicator, { asChild: true, children: _jsx(ChevronDownIcon, {}) })] }) }), _jsx(Select.Positioner, { children: _jsx(Select.Content, { children: _jsx(Select.ItemGroup, { children: bankCollection.items.map((item) => (_jsxs(Select.Item, { item: item, children: [_jsx(Select.ItemText, { children: item.name }), _jsx(Select.ItemIndicator, { asChild: true, children: _jsx(CheckIcon, {}) })] }, item.id))) }) }) })] }), _jsx(Field.ErrorText, { children: form.formState.errors.bankCode?.message })] })) }), _jsxs(Field.Root, { invalid: !!form.formState.errors.accountNumber, className: "mt-3xl", children: [_jsx(Field.Label, { children: "Account number" }), _jsx(Field.Input, { type: "number", ...form.register('accountNumber'), onKeyDown: (e) => {
180
+ }, children: [_jsx(Select.Label, { children: "Bank" }), _jsx(Select.Control, { children: _jsxs(Select.Trigger, { children: [_jsx(Select.ValueText, {}), _jsx(Select.Indicator, { asChild: true, children: _jsx(ChevronDownIcon, {}) })] }) }), _jsx(Select.Positioner, { children: _jsx(Select.Content, { children: _jsx(Select.ItemGroup, { children: bankCollection.items.map((item) => (_jsxs(Select.Item, { item: item, children: [_jsx(Select.ItemText, { children: item.name }), _jsx(Select.ItemIndicator, { asChild: true, children: _jsx(CheckIcon, {}) })] }, item.id))) }) }) })] }), _jsx(Field.ErrorText, { children: form.formState.errors.bankCode?.message })] })) }), _jsxs(Field.Root, { invalid: !!form.formState.errors.accountNumber, className: "mt-3xl", children: [_jsx(Field.Label, { children: "Account number" }), _jsx(Field.Input, { type: "text", inputMode: "numeric", pattern: "[0-9]*", ...form.register('accountNumber', {
181
+ setValueAs: (value) => value.replace(/\D/g, ''),
182
+ onChange: (e) => {
183
+ e.target.value = e.target.value.replace(/\D/g, '');
184
+ },
185
+ }), onKeyDown: (e) => {
181
186
  if (['e', 'E', '.', '-', '+', ','].includes(e.key)) {
182
187
  e.preventDefault();
183
188
  }
@@ -1 +1,6 @@
1
- export declare function UpdateMobilePhoneNumber(): import("react/jsx-runtime").JSX.Element;
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 { useAutoOpenWhenUnverified } from './hooks/useAutoOpenWhenUnverified.js';
13
+ import { useAutoOpen, } from './hooks/useAutoOpen.js';
14
14
  import { useUpdateMobileFlow } from './hooks/useUpdateMobileFlow.js';
15
- export function UpdateMobilePhoneNumber() {
16
- useAutoOpenWhenUnverified();
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opexa/portal-components",
3
- "version": "0.1.7",
3
+ "version": "0.1.12",
4
4
  "exports": {
5
5
  "./ui/*": {
6
6
  "types": "./dist/ui/*/index.d.ts",