@jsb188/app-settings-web 1.1.9 → 1.1.11

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/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
- "name": "@jsb188/app-settings-web",
3
- "version": "1.1.9",
4
- "description": "App settings module for web.",
5
- "license": "ISC",
6
- "author": "jsb188",
7
- "type": "module",
8
- "exports": {
9
- ".": "./src/main.ts"
10
- },
11
- "peerDependencies": {
12
- "@jsb188/app": "1.1.9",
13
- "@jsb188/react-web": "1.1.9",
14
- "jotai": "^2.20.0",
15
- "react": "^19.2.7",
16
- "react-router": "^7.16.0"
17
- },
18
- "scripts": {
19
- "test": "echo \"Error: no test specified\" && exit 1",
20
- "build": "tsc"
21
- }
2
+ "name": "@jsb188/app-settings-web",
3
+ "version": "1.1.11",
4
+ "description": "App settings module for web.",
5
+ "license": "ISC",
6
+ "author": "jsb188",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": "./src/main.ts"
10
+ },
11
+ "peerDependencies": {
12
+ "@jsb188/app": "1.1.11",
13
+ "@jsb188/react-web": "1.1.11",
14
+ "jotai": "^2.20.2",
15
+ "react": "^19.2.8",
16
+ "react-router": "^8.3.0"
17
+ },
18
+ "scripts": {
19
+ "test": "echo \"Error: no test specified\" && exit 1",
20
+ "build": "tsc"
21
+ }
22
22
  }
@@ -1,7 +1,12 @@
1
- import { getErrorMessageContent } from '@jsb188/react-web/modules/Layout';
1
+ import { getErrorMessageContent } from '@jsb188/react-web/modules/layout/MainLayout';
2
2
  import { Icon } from '@jsb188/react-web/svgs/Icon';
3
3
  import Markdown from '@jsb188/react-web/ui/Markdown';
4
- import { ModalContentContainer, ModalFloatingSaveButton, ModalSideNav, ModalSideNavIface } from '@jsb188/react-web/ui/ModalUI';
4
+ import {
5
+ ModalContentContainer,
6
+ ModalFloatingSaveButton,
7
+ ModalSideNav,
8
+ ModalSideNavIface,
9
+ } from '@jsb188/react-web/ui/ModalUI';
5
10
  import { TableListMockClient } from '@jsb188/react-web/ui/TableListUI';
6
11
  import type { ModalHandlerProps, OpenModalPopUpFn } from '@jsb188/react/states';
7
12
  import { useClosePopOver, useKeyDown } from '@jsb188/react/states';
@@ -12,24 +17,24 @@ import { useEffect, useRef, useState, type ReactNode } from 'react';
12
17
  */
13
18
 
14
19
  interface ControllerState {
15
- switchCase: string;
16
- hasChanges: boolean;
17
- saving: boolean;
18
- saveCounter: number;
19
- resetCounter: number;
20
- };
20
+ switchCase: string;
21
+ hasChanges: boolean;
22
+ saving: boolean;
23
+ saveCounter: number;
24
+ resetCounter: number;
25
+ }
21
26
 
22
27
  export interface AppSettingsSwitchCaseProps extends ControllerState {
23
- onSave: () => void;
24
- onChangeDiff: (hasChanges?: boolean, saving?: boolean) => void;
25
- openModalPopUp: OpenModalPopUpFn;
28
+ onSave: () => void;
29
+ onChangeDiff: (hasChanges?: boolean, saving?: boolean) => void;
30
+ openModalPopUp: OpenModalPopUpFn;
26
31
  }
27
32
 
28
33
  export interface AppSettingsTableContentProps {
29
- notReady?: boolean;
30
- gridLayoutStyle: string;
31
- children?: ReactNode;
32
- error?: any;
34
+ notReady?: boolean;
35
+ gridLayoutStyle: string;
36
+ children?: ReactNode;
37
+ error?: any;
33
38
  }
34
39
 
35
40
  /**
@@ -37,175 +42,172 @@ export interface AppSettingsTableContentProps {
37
42
  */
38
43
 
39
44
  export function AppSettingsTableContent(p: AppSettingsTableContentProps) {
40
- const { notReady, gridLayoutStyle, children, error } = p;
41
-
42
- if (notReady) {
43
- if (error) {
44
- const errObj = getErrorMessageContent(error);
45
- return <div className='h_item gap_df'>
46
- <div className='bd_2 bd_lt w_80 h_80 v_center r_df ic_lg ft_md rel pattern_texture medium_bf of'>
47
- <span className='rel'>
48
- <Icon
49
- tryColor
50
- name={errObj.titleIconName}
51
- backupName='alert-circle'
52
- />
53
- </span>
54
- </div>
55
-
56
- <div className='lh_2'>
57
- <div className='ft_medium ft_df mt_1 mb_4'>
58
- {errObj.title}
59
- </div>
60
- <Markdown
61
- as='p'
62
- preset='article'
63
- className='ft_sm cl_lt'
64
- >
65
- {errObj.message}
66
- </Markdown>
67
- </div>
68
- </div>;
69
- }
70
-
71
- return <TableListMockClient
72
- removeHorizontalPadding
73
- removeAvatarElement
74
- isSmallerRows
75
- removeBorderLine
76
- gridLayoutStyle={gridLayoutStyle}
77
- />;
78
- }
79
-
80
- return children;
45
+ const { notReady, gridLayoutStyle, children, error } = p;
46
+
47
+ if (notReady) {
48
+ if (error) {
49
+ const errObj = getErrorMessageContent(error);
50
+ return (
51
+ <div className="h_item gap_df">
52
+ <div className="bd_2 bd_lt w_80 h_80 v_center r_df ic_lg ft_md rel pattern_texture medium_bf of">
53
+ <span className="rel">
54
+ <Icon
55
+ tryColor
56
+ name={errObj.titleIconName}
57
+ backupName="alert-circle"
58
+ />
59
+ </span>
60
+ </div>
61
+
62
+ <div className="lh_2">
63
+ <div className="ft_medium ft_df mt_1 mb_4">{errObj.title}</div>
64
+ <Markdown as="p" preset="article" className="ft_sm cl_lt">
65
+ {errObj.message}
66
+ </Markdown>
67
+ </div>
68
+ </div>
69
+ );
70
+ }
71
+
72
+ return (
73
+ <TableListMockClient
74
+ removeHorizontalPadding
75
+ removeAvatarElement
76
+ isSmallerRows
77
+ removeBorderLine
78
+ gridLayoutStyle={gridLayoutStyle}
79
+ />
80
+ );
81
+ }
82
+
83
+ return children;
81
84
  }
82
85
 
83
86
  /**
84
87
  * App settings layout
85
88
  */
86
89
 
87
- export function AppSettingsLayout(p: ModalHandlerProps & {
88
- switchCase: string;
89
- SwitchCaseComponent: React.ComponentType<AppSettingsSwitchCaseProps>;
90
- options: ModalSideNavIface[][];
91
- onClickNavItem?: (value: string) => boolean | void; // If "false" is returned, it denies the switchCase change
92
- }) {
93
- const { SwitchCaseComponent, openModalPopUp, options } = p;
94
- const [keyDown, setKeyDown] = useKeyDown();
95
- const closePopOver = useClosePopOver();
96
- const scrollAreaRef = useRef<HTMLDivElement | null>(null);
97
-
98
- // const setKeyDown = (value: any) => {
99
- // dispatchApp({
100
- // pressed: null,
101
- // alert: keyDown.alert,
102
- // modal: keyDown.modal,
103
- // ...value,
104
- // });
105
- // };
106
-
107
- const [controller, setController] = useState<ControllerState>({
108
- switchCase: p.switchCase,
109
- hasChanges: false,
110
- saving: false,
111
- saveCounter: 0,
112
- resetCounter: 0,
113
- });
114
-
115
- const onClickNavItem = (value: any) => {
116
- const handlerValue = p.onClickNavItem?.(value);
117
- if (handlerValue !== false) {
118
- setController({
119
- switchCase: value,
120
- hasChanges: false,
121
- saving: false,
122
- saveCounter: 0,
123
- resetCounter: 0,
124
- });
125
- }
126
- };
127
-
128
- const onSave = () => {
129
- setController({
130
- ...controller,
131
- saveCounter: controller.saveCounter + 1,
132
- });
133
- };
134
-
135
- const onReset = () => {
136
- setController({
137
- ...controller,
138
- resetCounter: controller.resetCounter + 1,
139
- });
140
- };
141
-
142
- const onChangeDiff = (hasChanges?: boolean, saving?: boolean) => {
143
- setController({
144
- ...controller,
145
- hasChanges: typeof hasChanges === 'boolean' ? hasChanges : controller.hasChanges,
146
- saving: typeof saving === 'boolean' ? saving : controller.saving,
147
- });
148
- };
149
-
150
- useEffect(() => {
151
- if (!keyDown.alert && keyDown.pressed === 's') {
152
- setKeyDown({
153
- pressed: null,
154
- });
155
- onSave();
156
- }
157
- }, [keyDown.pressed]);
158
-
159
- useEffect(() => {
160
- // Listen to scroll events inside scrollAreaRef
161
-
162
- const scrollArea = scrollAreaRef.current;
163
- if (!scrollArea) {
164
- return;
165
- }
166
-
167
- const onScroll = () => {
168
- // Close pop over on scroll
169
- closePopOver();
170
- };
171
-
172
- scrollArea.addEventListener('scroll', onScroll);
173
-
174
- return () => {
175
- scrollArea.removeEventListener('scroll', onScroll);
176
- };
177
- }, [closePopOver]);
178
-
179
- return (
180
- <div className='cw md h_top f rel of'>
181
- <ModalSideNav
182
- selectedValue={controller.switchCase}
183
- options={options}
184
- onClickItem={onClickNavItem}
185
- />
186
-
187
- <ModalContentContainer
188
- ref={scrollAreaRef}
189
- addFooterPadding
190
- addYOverflow
191
- >
192
- <div className='f py_md px_lg'>
193
- <SwitchCaseComponent
194
- key={`switch_case_${controller.resetCounter}`}
195
- onSave={onSave}
196
- onChangeDiff={onChangeDiff}
197
- openModalPopUp={openModalPopUp}
198
- {...controller}
199
- />
200
- </div>
201
- </ModalContentContainer>
202
-
203
- <ModalFloatingSaveButton
204
- hasChanges={controller.hasChanges}
205
- saving={controller.saving}
206
- onSave={onSave}
207
- onReset={onReset}
208
- />
209
- </div>
210
- );
90
+ export function AppSettingsLayout(
91
+ p: ModalHandlerProps & {
92
+ switchCase: string;
93
+ SwitchCaseComponent: React.ComponentType<AppSettingsSwitchCaseProps>;
94
+ options: ModalSideNavIface[][];
95
+ onClickNavItem?: (value: string) => boolean | void; // If "false" is returned, it denies the switchCase change
96
+ },
97
+ ) {
98
+ const { SwitchCaseComponent, openModalPopUp, options } = p;
99
+ const [keyDown, setKeyDown] = useKeyDown();
100
+ const closePopOver = useClosePopOver();
101
+ const scrollAreaRef = useRef<HTMLDivElement | null>(null);
102
+
103
+ // const setKeyDown = (value: any) => {
104
+ // dispatchApp({
105
+ // pressed: null,
106
+ // alert: keyDown.alert,
107
+ // modal: keyDown.modal,
108
+ // ...value,
109
+ // });
110
+ // };
111
+
112
+ const [controller, setController] = useState<ControllerState>({
113
+ switchCase: p.switchCase,
114
+ hasChanges: false,
115
+ saving: false,
116
+ saveCounter: 0,
117
+ resetCounter: 0,
118
+ });
119
+
120
+ const onClickNavItem = (value: any) => {
121
+ const handlerValue = p.onClickNavItem?.(value);
122
+ if (handlerValue !== false) {
123
+ setController({
124
+ switchCase: value,
125
+ hasChanges: false,
126
+ saving: false,
127
+ saveCounter: 0,
128
+ resetCounter: 0,
129
+ });
130
+ }
131
+ };
132
+
133
+ const onSave = () => {
134
+ setController({
135
+ ...controller,
136
+ saveCounter: controller.saveCounter + 1,
137
+ });
138
+ };
139
+
140
+ const onReset = () => {
141
+ setController({
142
+ ...controller,
143
+ resetCounter: controller.resetCounter + 1,
144
+ });
145
+ };
146
+
147
+ const onChangeDiff = (hasChanges?: boolean, saving?: boolean) => {
148
+ setController({
149
+ ...controller,
150
+ hasChanges:
151
+ typeof hasChanges === 'boolean' ? hasChanges : controller.hasChanges,
152
+ saving: typeof saving === 'boolean' ? saving : controller.saving,
153
+ });
154
+ };
155
+
156
+ useEffect(() => {
157
+ if (!keyDown.alert && keyDown.pressed === 's') {
158
+ setKeyDown({
159
+ pressed: null,
160
+ });
161
+ onSave();
162
+ }
163
+ }, [keyDown.pressed]);
164
+
165
+ useEffect(() => {
166
+ // Listen to scroll events inside scrollAreaRef
167
+
168
+ const scrollArea = scrollAreaRef.current;
169
+ if (!scrollArea) {
170
+ return;
171
+ }
172
+
173
+ const onScroll = () => {
174
+ // Close pop over on scroll
175
+ closePopOver();
176
+ };
177
+
178
+ scrollArea.addEventListener('scroll', onScroll);
179
+
180
+ return () => {
181
+ scrollArea.removeEventListener('scroll', onScroll);
182
+ };
183
+ }, [closePopOver]);
184
+
185
+ return (
186
+ <div className="cw md h_top f rel of">
187
+ <ModalSideNav
188
+ selectedValue={controller.switchCase}
189
+ options={options}
190
+ onClickItem={onClickNavItem}
191
+ />
192
+
193
+ <ModalContentContainer ref={scrollAreaRef} addFooterPadding addYOverflow>
194
+ <div className="f py_md px_lg">
195
+ <SwitchCaseComponent
196
+ key={`switch_case_${controller.resetCounter}`}
197
+ onSave={onSave}
198
+ onChangeDiff={onChangeDiff}
199
+ openModalPopUp={openModalPopUp}
200
+ {...controller}
201
+ />
202
+ </div>
203
+ </ModalContentContainer>
204
+
205
+ <ModalFloatingSaveButton
206
+ hasChanges={controller.hasChanges}
207
+ saving={controller.saving}
208
+ onSave={onSave}
209
+ onReset={onReset}
210
+ />
211
+ </div>
212
+ );
211
213
  }
@@ -1,6 +1,10 @@
1
1
  import i18n from '@jsb188/app/i18n/index.ts';
2
2
  import { useConfirmPassword } from '@jsb188/graphql/hooks/use-auth-mtn';
3
- import { FormOptions, Input, SMSCodeInput } from '@jsb188/react-web/modules/Form';
3
+ import {
4
+ FormOptions,
5
+ Input,
6
+ SMSCodeInput,
7
+ } from '@jsb188/react-web/modules/Form';
4
8
  import { AlertPopUp, ModalErrorMessage } from '@jsb188/react-web/ui/ModalUI';
5
9
  import type { ModalPopUpComponentProps } from '@jsb188/react/states';
6
10
  import { useState } from 'react';
@@ -12,123 +16,142 @@ import { useState } from 'react';
12
16
  export interface ConfirmPasswordProps extends ModalPopUpComponentProps {
13
17
  confirmPasswordTitle?: string;
14
18
  confirmPasswordMessage?: string;
15
- onPasswordVerified?: (password: string) => void;
19
+ onPasswordVerified?: (password: string) => void;
16
20
  }
17
21
 
18
- export interface ChangeCredentialsFinishedProps extends ModalPopUpComponentProps {
19
- finishedIconName?: string;
20
- finishedTitle?: string;
21
- finishedMessage?: string;
22
+ export interface ChangeCredentialsFinishedProps
23
+ extends ModalPopUpComponentProps {
24
+ finishedIconName?: string;
25
+ finishedTitle?: string;
26
+ finishedMessage?: string;
22
27
  }
23
28
 
24
29
  export interface ChangeCredentialsProps extends ConfirmPasswordProps {
25
30
  iconName: string;
26
31
  skipPassword?: boolean;
27
- title: string;
28
- message: string;
32
+ title: string;
33
+ message: string;
29
34
 
30
- finishedIconName?: string;
31
- finishedTitle?: string;
32
- finishedMessage?: string;
35
+ finishedIconName?: string;
36
+ finishedTitle?: string;
37
+ finishedMessage?: string;
33
38
 
34
- verifyIconName?: string;
35
- verifyTitle?: string;
36
- verifyMessage?: string;
39
+ verifyIconName?: string;
40
+ verifyTitle?: string;
41
+ verifyMessage?: string;
37
42
 
38
- confirmText?: string;
39
- confirmSMSCodeText?: string;
40
- status: 'WAITING_FOR_INPUT' | 'WAITING_FOR_VERIFICATION' | 'WAITING_FOR_SMS_CODE' | 'FINISHED';
41
- onSubmit: (values: string[], confirmedPassword?: string) => void;
42
- onSubmitSMSCode?: (smsCode: string, values: string[], confirmedPassword?: string) => void;
43
+ confirmText?: string;
44
+ confirmSMSCodeText?: string;
45
+ status:
46
+ | 'WAITING_FOR_INPUT'
47
+ | 'WAITING_FOR_VERIFICATION'
48
+ | 'WAITING_FOR_SMS_CODE'
49
+ | 'FINISHED';
50
+ onSubmit: (values: string[], confirmedPassword?: string) => void;
51
+ onSubmitSMSCode?: (
52
+ smsCode: string,
53
+ values: string[],
54
+ confirmedPassword?: string,
55
+ ) => void;
43
56
 
44
- loading?: boolean;
45
- error: any;
46
- resetErrors: () => void;
47
- inputs: ({
48
- __type: 'TEXT_INPUT';
49
- type?: 'text' | 'password';
50
- label: string;
51
- placeholder?: string;
52
- } | {
53
- __type: 'OPTIONS_LIST',
54
- label: string;
55
- defaultValue?: string;
56
- options: {
57
- text: string;
58
- value: string;
59
- disabled?: boolean;
60
- }[];
61
- })[];
57
+ loading?: boolean;
58
+ error: any;
59
+ resetErrors: () => void;
60
+ inputs: (
61
+ | {
62
+ __type: 'TEXT_INPUT';
63
+ type?: 'text' | 'password';
64
+ label: string;
65
+ placeholder?: string;
66
+ }
67
+ | {
68
+ __type: 'OPTIONS_LIST';
69
+ label: string;
70
+ defaultValue?: string;
71
+ options: {
72
+ text: string;
73
+ value: string;
74
+ disabled?: boolean;
75
+ }[];
76
+ }
77
+ )[];
62
78
  }
63
79
 
64
80
  /**
65
81
  * Confirm password before changinge sensitive account settings
66
82
  */
67
83
 
68
- function ConfirmPasswordForm(p: ConfirmPasswordProps & {
69
- setPasswordVerified: (verified: boolean) => void;
70
- }) {
71
- const { setPasswordVerified, onCloseModal, confirmPasswordTitle, confirmPasswordMessage, onPasswordVerified } = p;
72
- const [password, setPassword] = useState('');
84
+ function ConfirmPasswordForm(
85
+ p: ConfirmPasswordProps & {
86
+ setPasswordVerified: (verified: boolean) => void;
87
+ },
88
+ ) {
89
+ const {
90
+ setPasswordVerified,
91
+ onCloseModal,
92
+ confirmPasswordTitle,
93
+ confirmPasswordMessage,
94
+ onPasswordVerified,
95
+ } = p;
96
+ const [password, setPassword] = useState('');
97
+
98
+ const { confirmPassword, error, resetErrors, saving } = useConfirmPassword({
99
+ onCompleted: (data: any) => {
100
+ if (data.confirmPassword) {
101
+ onPasswordVerified?.(password);
102
+ setPasswordVerified(true);
103
+ }
104
+ },
105
+ onError: () => {
106
+ setPassword('');
107
+ },
108
+ });
73
109
 
74
- const { confirmPassword, error, resetErrors, saving } = useConfirmPassword({
75
- onCompleted: (data: any) => {
76
- if (data.confirmPassword) {
77
- onPasswordVerified?.(password);
78
- setPasswordVerified(true);
79
- }
80
- },
81
- onError: () => {
82
- setPassword('');
83
- }
84
- });
110
+ const onConfirmPassword = () => {
111
+ confirmPassword({
112
+ variables: {
113
+ password,
114
+ },
115
+ });
116
+ };
85
117
 
86
- const onConfirmPassword = () => {
87
- confirmPassword({
88
- variables: {
89
- password,
90
- }
91
- });
92
- };
118
+ const onPressEnter = (e: React.KeyboardEvent) => {
119
+ if (e.key === 'Enter' && password) {
120
+ onConfirmPassword();
121
+ }
122
+ };
93
123
 
94
- const onPressEnter = (e: React.KeyboardEvent) => {
95
- if (e.key === 'Enter' && password) {
96
- onConfirmPassword();
97
- }
98
- }
124
+ return (
125
+ <AlertPopUp
126
+ loading={saving}
127
+ iconName="password-lock-2"
128
+ confirmText={i18n.t('form.authenticate')}
129
+ cancelText={i18n.t('form.cancel')}
130
+ onConfirm={onConfirmPassword}
131
+ onCancel={onCloseModal}
132
+ disabledConfirm={!password}
133
+ title={confirmPasswordTitle ?? i18n.t('account.enter_password')}
134
+ message={confirmPasswordMessage ?? i18n.t('account.enter_password_msg')}
135
+ >
136
+ {error && (
137
+ <div className="px_md mt_md -mb_df">
138
+ <ModalErrorMessage error={error} resetErrors={resetErrors} />
139
+ </div>
140
+ )}
99
141
 
100
- return <AlertPopUp
101
- loading={saving}
102
- iconName='password-lock-2'
103
- confirmText={i18n.t('form.authenticate')}
104
- cancelText={i18n.t('form.cancel')}
105
- onConfirm={onConfirmPassword}
106
- onCancel={onCloseModal}
107
- disabledConfirm={!password}
108
- title={confirmPasswordTitle ?? i18n.t('account.enter_password')}
109
- message={confirmPasswordMessage ?? i18n.t('account.enter_password_msg')}
110
- >
111
- {error && (
112
- <div className='px_md mt_md -mb_df'>
113
- <ModalErrorMessage
114
- error={error}
115
- resetErrors={resetErrors}
142
+ <div className="mt_df mx_md">
143
+ <Input
144
+ type="password"
145
+ label={i18n.t('account.password')}
146
+ placeholder="••••"
147
+ value={password}
148
+ onChange={(e) => setPassword(e.target.value)}
149
+ onKeyDown={onPressEnter}
150
+ autoFocus
116
151
  />
117
152
  </div>
118
- )}
119
-
120
- <div className='mt_df mx_md'>
121
- <Input
122
- type='password'
123
- label={i18n.t('account.password')}
124
- placeholder='••••'
125
- value={password}
126
- onChange={(e) => setPassword(e.target.value)}
127
- onKeyDown={onPressEnter}
128
- autoFocus
129
- />
130
- </div>
131
- </AlertPopUp>;
153
+ </AlertPopUp>
154
+ );
132
155
  }
133
156
 
134
157
  /**
@@ -137,153 +160,191 @@ function ConfirmPasswordForm(p: ConfirmPasswordProps & {
137
160
 
138
161
  export function ChangeCredentialsLayout(p: ChangeCredentialsProps) {
139
162
  const {
140
- iconName, skipPassword, title, message, confirmText, confirmSMSCodeText, loading, error, resetErrors, inputs, onSubmit, onSubmitSMSCode, status,
141
- finishedIconName, finishedTitle, finishedMessage,
142
- verifyIconName, verifyTitle, verifyMessage,
143
- ...rest
144
- } = p;
145
- const { onCloseModal } = rest;
163
+ iconName,
164
+ skipPassword,
165
+ title,
166
+ message,
167
+ confirmText,
168
+ confirmSMSCodeText,
169
+ loading,
170
+ error,
171
+ resetErrors,
172
+ inputs,
173
+ onSubmit,
174
+ onSubmitSMSCode,
175
+ status,
176
+ finishedIconName,
177
+ finishedTitle,
178
+ finishedMessage,
179
+ verifyIconName,
180
+ verifyTitle,
181
+ verifyMessage,
182
+ ...rest
183
+ } = p;
184
+ const { onCloseModal } = rest;
146
185
  const [passwordVerified, setPasswordVerified] = useState(false);
147
- const [confirmedPassword, setConfirmedPassword] = useState('');
148
- const [smsCode, setSMSCode] = useState('');
149
- const [values, setValues] = useState(() => inputs.map((input) =>
150
- input.__type === 'OPTIONS_LIST'
151
- ? (input.defaultValue || '')
152
- : ''
153
- ));
186
+ const [confirmedPassword, setConfirmedPassword] = useState('');
187
+ const [smsCode, setSMSCode] = useState('');
188
+ const [values, setValues] = useState(() =>
189
+ inputs.map((input) =>
190
+ input.__type === 'OPTIONS_LIST' ? input.defaultValue || '' : '',
191
+ ),
192
+ );
154
193
 
155
- switch (status) {
156
- case 'FINISHED':
157
- return <AlertPopUp
158
- onCloseModal={onCloseModal}
159
- iconName={finishedIconName || 'circle-check'}
160
- onCancel={onCloseModal}
161
- title={finishedTitle || i18n.t('form.success_')}
162
- message={finishedMessage || i18n.t('form.your_request_is_completed_msg')}
163
- />;
164
- case 'WAITING_FOR_VERIFICATION':
165
- return <AlertPopUp
166
- onCloseModal={onCloseModal}
167
- iconName={verifyIconName || iconName}
168
- onCancel={onCloseModal}
169
- title={verifyTitle || i18n.t('form.please_verify')}
170
- message={verifyMessage || i18n.t('form.request_will_complete_once_verified_msg')}
171
- />;
172
- case 'WAITING_FOR_SMS_CODE': {
173
- const hasSMSCode = !!smsCode.trim();
194
+ switch (status) {
195
+ case 'FINISHED':
196
+ return (
197
+ <AlertPopUp
198
+ onCloseModal={onCloseModal}
199
+ iconName={finishedIconName || 'circle-check'}
200
+ onCancel={onCloseModal}
201
+ title={finishedTitle || i18n.t('form.success_')}
202
+ message={
203
+ finishedMessage || i18n.t('form.your_request_is_completed_msg')
204
+ }
205
+ />
206
+ );
207
+ case 'WAITING_FOR_VERIFICATION':
208
+ return (
209
+ <AlertPopUp
210
+ onCloseModal={onCloseModal}
211
+ iconName={verifyIconName || iconName}
212
+ onCancel={onCloseModal}
213
+ title={verifyTitle || i18n.t('form.please_verify')}
214
+ message={
215
+ verifyMessage ||
216
+ i18n.t('form.request_will_complete_once_verified_msg')
217
+ }
218
+ />
219
+ );
220
+ case 'WAITING_FOR_SMS_CODE': {
221
+ const hasSMSCode = !!smsCode.trim();
174
222
 
175
- return <AlertPopUp
176
- iconName={verifyIconName || iconName}
177
- loading={loading}
178
- onCloseModal={onCloseModal}
179
- onCancel={onCloseModal}
180
- doNotExitOnConfirm
181
- onConfirm={() => {
182
- onSubmitSMSCode?.(smsCode.trim(), values, confirmedPassword);
183
- }}
184
- title={verifyTitle || i18n.t('form.please_verify')}
185
- message={verifyMessage || i18n.t('form.request_will_complete_once_verified_msg')}
186
- confirmText={confirmSMSCodeText || i18n.t('form.ok')}
187
- cancelText={i18n.t('form.cancel')}
188
- disabledConfirm={!hasSMSCode}
189
- >
190
- {error && (
191
- <div className='px_md mt_md -mb_df'>
192
- <ModalErrorMessage
193
- error={error}
194
- resetErrors={resetErrors}
195
- />
196
- </div>
197
- )}
223
+ return (
224
+ <AlertPopUp
225
+ iconName={verifyIconName || iconName}
226
+ loading={loading}
227
+ onCloseModal={onCloseModal}
228
+ onCancel={onCloseModal}
229
+ doNotExitOnConfirm
230
+ onConfirm={() => {
231
+ onSubmitSMSCode?.(smsCode.trim(), values, confirmedPassword);
232
+ }}
233
+ title={verifyTitle || i18n.t('form.please_verify')}
234
+ message={
235
+ verifyMessage ||
236
+ i18n.t('form.request_will_complete_once_verified_msg')
237
+ }
238
+ confirmText={confirmSMSCodeText || i18n.t('form.ok')}
239
+ cancelText={i18n.t('form.cancel')}
240
+ disabledConfirm={!hasSMSCode}
241
+ >
242
+ {error && (
243
+ <div className="px_md mt_md -mb_df">
244
+ <ModalErrorMessage error={error} resetErrors={resetErrors} />
245
+ </div>
246
+ )}
198
247
 
199
- <div className='mt_md mx_md'>
200
- <SMSCodeInput
201
- saving={loading}
202
- error={error}
203
- onChangeCode={setSMSCode}
204
- onSubmit={(smsCode) => {
205
- onSubmitSMSCode?.(smsCode.trim(), values, confirmedPassword);
206
- }}
207
- />
208
- </div>
209
- </AlertPopUp>;
210
- }
211
- case 'WAITING_FOR_INPUT':
212
- default:
213
- }
248
+ <div className="mt_md mx_md">
249
+ <SMSCodeInput
250
+ saving={loading}
251
+ error={error}
252
+ onChangeCode={setSMSCode}
253
+ onSubmit={(smsCode) => {
254
+ onSubmitSMSCode?.(smsCode.trim(), values, confirmedPassword);
255
+ }}
256
+ />
257
+ </div>
258
+ </AlertPopUp>
259
+ );
260
+ }
261
+ case 'WAITING_FOR_INPUT':
262
+ default:
263
+ }
214
264
 
215
265
  if (!passwordVerified && !skipPassword) {
216
- return <ConfirmPasswordForm
217
- {...rest}
218
- setPasswordVerified={setPasswordVerified}
219
- onPasswordVerified={setConfirmedPassword}
220
- />;
266
+ return (
267
+ <ConfirmPasswordForm
268
+ {...rest}
269
+ setPasswordVerified={setPasswordVerified}
270
+ onPasswordVerified={setConfirmedPassword}
271
+ />
272
+ );
221
273
  }
222
274
 
223
- const hasTwoInputs = inputs.length >= 2;
224
- const hasValidInputs = !!(hasTwoInputs ? values[0]?.trim() && values[1]?.trim() : values[0]?.trim());
275
+ const hasTwoInputs = inputs.length >= 2;
276
+ const hasValidInputs = !!(hasTwoInputs
277
+ ? values[0]?.trim() && values[1]?.trim()
278
+ : values[0]?.trim());
225
279
 
226
- const onPressEnter = (e: React.KeyboardEvent) => {
227
- if (e.key === 'Enter' && hasValidInputs) {
228
- onSubmit(values, confirmedPassword);
229
- }
230
- };
280
+ const onPressEnter = (e: React.KeyboardEvent) => {
281
+ if (e.key === 'Enter' && hasValidInputs) {
282
+ onSubmit(values, confirmedPassword);
283
+ }
284
+ };
231
285
 
232
- return <AlertPopUp
233
- iconName={iconName}
234
- doNotExitOnConfirm
235
- loading={loading}
236
- onCloseModal={onCloseModal}
237
- onConfirm={() => onSubmit(values, confirmedPassword)}
238
- title={title}
239
- message={message}
240
- confirmText={confirmText}
241
- cancelText={i18n.t('form.cancel')}
242
- disabledConfirm={!hasValidInputs}
243
- >
244
- {error && (
245
- <div className='px_md mt_md -mb_df'>
246
- <ModalErrorMessage
247
- error={error}
248
- resetErrors={resetErrors}
249
- />
250
- </div>
251
- )}
286
+ return (
287
+ <AlertPopUp
288
+ iconName={iconName}
289
+ doNotExitOnConfirm
290
+ loading={loading}
291
+ onCloseModal={onCloseModal}
292
+ onConfirm={() => onSubmit(values, confirmedPassword)}
293
+ title={title}
294
+ message={message}
295
+ confirmText={confirmText}
296
+ cancelText={i18n.t('form.cancel')}
297
+ disabledConfirm={!hasValidInputs}
298
+ >
299
+ {error && (
300
+ <div className="px_md mt_md -mb_df">
301
+ <ModalErrorMessage error={error} resetErrors={resetErrors} />
302
+ </div>
303
+ )}
252
304
 
253
- <div className='mt_df mx_md'>
254
- {inputs.map((obj, i) => {
255
- switch (obj.__type) {
256
- case 'OPTIONS_LIST':
257
- return <FormOptions
258
- key={i}
259
- name={obj.label}
260
- label={obj.label}
261
- value={values[i]}
262
- options={obj.options}
263
- onChange={(_e: React.MouseEvent, _name: string, value: string | number | null) => {
264
- const newValues = [...values];
265
- newValues[i] = value === null ? '' : String(value);
266
- setValues(newValues);
267
- }}
268
- />;
269
- case 'TEXT_INPUT':
270
- default:
271
- }
305
+ <div className="mt_df mx_md">
306
+ {inputs.map((obj, i) => {
307
+ switch (obj.__type) {
308
+ case 'OPTIONS_LIST':
309
+ return (
310
+ <FormOptions
311
+ key={i}
312
+ name={obj.label}
313
+ label={obj.label}
314
+ value={values[i]}
315
+ options={obj.options}
316
+ onChange={(
317
+ _e: React.MouseEvent,
318
+ _name: string,
319
+ value: string | number | null,
320
+ ) => {
321
+ const newValues = [...values];
322
+ newValues[i] = value === null ? '' : String(value);
323
+ setValues(newValues);
324
+ }}
325
+ />
326
+ );
327
+ case 'TEXT_INPUT':
328
+ default:
329
+ }
272
330
 
273
- return <Input
274
- key={i}
275
- type={obj.type || 'text'}
276
- {...obj}
277
- value={values[i]}
278
- onChange={(e) => {
279
- const newValues = [...values];
280
- newValues[i] = e.target.value;
281
- setValues(newValues);
282
- }}
283
- onKeyDown={onPressEnter}
284
- autoFocus={!i}
285
- />
286
- })}
287
- </div>
288
- </AlertPopUp>;
289
- };
331
+ return (
332
+ <Input
333
+ key={i}
334
+ type={obj.type || 'text'}
335
+ {...obj}
336
+ value={values[i]}
337
+ onChange={(e) => {
338
+ const newValues = [...values];
339
+ newValues[i] = e.target.value;
340
+ setValues(newValues);
341
+ }}
342
+ onKeyDown={onPressEnter}
343
+ autoFocus={!i}
344
+ />
345
+ );
346
+ })}
347
+ </div>
348
+ </AlertPopUp>
349
+ );
350
+ }