@jsb188/app-settings-web 1.1.8 → 1.1.10

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsb188/app-settings-web",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "App settings module for web.",
5
5
  "license": "ISC",
6
6
  "author": "jsb188",
@@ -9,11 +9,11 @@
9
9
  ".": "./src/main.ts"
10
10
  },
11
11
  "peerDependencies": {
12
- "@jsb188/app": "1.1.8",
13
- "@jsb188/react-web": "1.1.8",
14
- "react-router": "^7.8.2",
15
- "jotai": "^2.13.1",
16
- "react": "^19.1.1"
12
+ "@jsb188/app": "1.1.10",
13
+ "@jsb188/react-web": "1.1.10",
14
+ "jotai": "^2.20.0",
15
+ "react": "^19.2.7",
16
+ "react-router": "^7.16.0"
17
17
  },
18
18
  "scripts": {
19
19
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -1,7 +1,11 @@
1
+ import { getErrorMessageContent } from '@jsb188/react-web/modules/Layout';
2
+ import { Icon } from '@jsb188/react-web/svgs/Icon';
3
+ import Markdown from '@jsb188/react-web/ui/Markdown';
1
4
  import { ModalContentContainer, ModalFloatingSaveButton, ModalSideNav, ModalSideNavIface } from '@jsb188/react-web/ui/ModalUI';
5
+ import { TableListMockClient } from '@jsb188/react-web/ui/TableListUI';
2
6
  import type { ModalHandlerProps, OpenModalPopUpFn } from '@jsb188/react/states';
3
7
  import { useClosePopOver, useKeyDown } from '@jsb188/react/states';
4
- import { useEffect, useRef, useState } from 'react';
8
+ import { useEffect, useRef, useState, type ReactNode } from 'react';
5
9
 
6
10
  /**
7
11
  * Types
@@ -21,6 +25,61 @@ export interface AppSettingsSwitchCaseProps extends ControllerState {
21
25
  openModalPopUp: OpenModalPopUpFn;
22
26
  }
23
27
 
28
+ export interface AppSettingsTableContentProps {
29
+ notReady?: boolean;
30
+ gridLayoutStyle: string;
31
+ children?: ReactNode;
32
+ error?: any;
33
+ }
34
+
35
+ /**
36
+ * App settings table content helper with a built-in loading table state
37
+ */
38
+
39
+ 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;
81
+ }
82
+
24
83
  /**
25
84
  * App settings layout
26
85
  */
@@ -1,6 +1,6 @@
1
- import i18n from '@jsb188/app/i18n';
1
+ import i18n from '@jsb188/app/i18n/index.ts';
2
2
  import { useConfirmPassword } from '@jsb188/graphql/hooks/use-auth-mtn';
3
- import { Input } from '@jsb188/react-web/modules/Form';
3
+ import { FormOptions, Input, SMSCodeInput } from '@jsb188/react-web/modules/Form';
4
4
  import { AlertPopUp, ModalErrorMessage } from '@jsb188/react-web/ui/ModalUI';
5
5
  import type { ModalPopUpComponentProps } from '@jsb188/react/states';
6
6
  import { useState } from 'react';
@@ -12,6 +12,7 @@ import { useState } from 'react';
12
12
  export interface ConfirmPasswordProps extends ModalPopUpComponentProps {
13
13
  confirmPasswordTitle?: string;
14
14
  confirmPasswordMessage?: string;
15
+ onPasswordVerified?: (password: string) => void;
15
16
  }
16
17
 
17
18
  export interface ChangeCredentialsFinishedProps extends ModalPopUpComponentProps {
@@ -35,16 +36,29 @@ export interface ChangeCredentialsProps extends ConfirmPasswordProps {
35
36
  verifyMessage?: string;
36
37
 
37
38
  confirmText?: string;
38
- status: 'WAITING_FOR_INPUT' | 'WAITING_FOR_VERIFICATION' | 'WAITING_FOR_CODE' | 'FINISHED';
39
- onSubmit: (values: string[]) => void;
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;
40
43
 
41
44
  loading?: boolean;
42
45
  error: any;
43
46
  resetErrors: () => void;
44
- inputs: {
47
+ inputs: ({
48
+ __type: 'TEXT_INPUT';
49
+ type?: 'text' | 'password';
45
50
  label: string;
46
51
  placeholder?: string;
47
- }[];
52
+ } | {
53
+ __type: 'OPTIONS_LIST',
54
+ label: string;
55
+ defaultValue?: string;
56
+ options: {
57
+ text: string;
58
+ value: string;
59
+ disabled?: boolean;
60
+ }[];
61
+ })[];
48
62
  }
49
63
 
50
64
  /**
@@ -54,12 +68,13 @@ export interface ChangeCredentialsProps extends ConfirmPasswordProps {
54
68
  function ConfirmPasswordForm(p: ConfirmPasswordProps & {
55
69
  setPasswordVerified: (verified: boolean) => void;
56
70
  }) {
57
- const { setPasswordVerified, onCloseModal, confirmPasswordTitle, confirmPasswordMessage } = p;
71
+ const { setPasswordVerified, onCloseModal, confirmPasswordTitle, confirmPasswordMessage, onPasswordVerified } = p;
58
72
  const [password, setPassword] = useState('');
59
73
 
60
74
  const { confirmPassword, error, resetErrors, saving } = useConfirmPassword({
61
75
  onCompleted: (data: any) => {
62
76
  if (data.confirmPassword) {
77
+ onPasswordVerified?.(password);
63
78
  setPasswordVerified(true);
64
79
  }
65
80
  },
@@ -84,7 +99,7 @@ function ConfirmPasswordForm(p: ConfirmPasswordProps & {
84
99
 
85
100
  return <AlertPopUp
86
101
  loading={saving}
87
- iconName='password-lock-1'
102
+ iconName='password-lock-2'
88
103
  confirmText={i18n.t('form.authenticate')}
89
104
  cancelText={i18n.t('form.cancel')}
90
105
  onConfirm={onConfirmPassword}
@@ -122,14 +137,20 @@ function ConfirmPasswordForm(p: ConfirmPasswordProps & {
122
137
 
123
138
  export function ChangeCredentialsLayout(p: ChangeCredentialsProps) {
124
139
  const {
125
- iconName, skipPassword, title, message, confirmText, loading, error, resetErrors, inputs, onSubmit, status,
140
+ iconName, skipPassword, title, message, confirmText, confirmSMSCodeText, loading, error, resetErrors, inputs, onSubmit, onSubmitSMSCode, status,
126
141
  finishedIconName, finishedTitle, finishedMessage,
127
142
  verifyIconName, verifyTitle, verifyMessage,
128
143
  ...rest
129
144
  } = p;
130
145
  const { onCloseModal } = rest;
131
146
  const [passwordVerified, setPasswordVerified] = useState(false);
132
- const [values, setValues] = useState(['', '']);
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
+ ));
133
154
 
134
155
  switch (status) {
135
156
  case 'FINISHED':
@@ -140,8 +161,6 @@ export function ChangeCredentialsLayout(p: ChangeCredentialsProps) {
140
161
  title={finishedTitle || i18n.t('form.success_')}
141
162
  message={finishedMessage || i18n.t('form.your_request_is_completed_msg')}
142
163
  />;
143
- case 'WAITING_FOR_CODE':
144
- return 'waiting for code';
145
164
  case 'WAITING_FOR_VERIFICATION':
146
165
  return <AlertPopUp
147
166
  onCloseModal={onCloseModal}
@@ -150,6 +169,45 @@ export function ChangeCredentialsLayout(p: ChangeCredentialsProps) {
150
169
  title={verifyTitle || i18n.t('form.please_verify')}
151
170
  message={verifyMessage || i18n.t('form.request_will_complete_once_verified_msg')}
152
171
  />;
172
+ case 'WAITING_FOR_SMS_CODE': {
173
+ const hasSMSCode = !!smsCode.trim();
174
+
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
+ )}
198
+
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
+ }
153
211
  case 'WAITING_FOR_INPUT':
154
212
  default:
155
213
  }
@@ -158,6 +216,7 @@ export function ChangeCredentialsLayout(p: ChangeCredentialsProps) {
158
216
  return <ConfirmPasswordForm
159
217
  {...rest}
160
218
  setPasswordVerified={setPasswordVerified}
219
+ onPasswordVerified={setConfirmedPassword}
161
220
  />;
162
221
  }
163
222
 
@@ -166,7 +225,7 @@ export function ChangeCredentialsLayout(p: ChangeCredentialsProps) {
166
225
 
167
226
  const onPressEnter = (e: React.KeyboardEvent) => {
168
227
  if (e.key === 'Enter' && hasValidInputs) {
169
- onSubmit(values);
228
+ onSubmit(values, confirmedPassword);
170
229
  }
171
230
  };
172
231
 
@@ -175,7 +234,7 @@ export function ChangeCredentialsLayout(p: ChangeCredentialsProps) {
175
234
  doNotExitOnConfirm
176
235
  loading={loading}
177
236
  onCloseModal={onCloseModal}
178
- onConfirm={() => onSubmit(values)}
237
+ onConfirm={() => onSubmit(values, confirmedPassword)}
179
238
  title={title}
180
239
  message={message}
181
240
  confirmText={confirmText}
@@ -193,9 +252,27 @@ export function ChangeCredentialsLayout(p: ChangeCredentialsProps) {
193
252
 
194
253
  <div className='mt_df mx_md'>
195
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
+ }
272
+
196
273
  return <Input
197
274
  key={i}
198
- type='text'
275
+ type={obj.type || 'text'}
199
276
  {...obj}
200
277
  value={values[i]}
201
278
  onChange={(e) => {