@jsb188/app-settings-web 1.1.5 → 1.1.6
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 +3 -3
- package/src/AppSettingsLayout.tsx +29 -6
- package/src/ChangeCredentialsLayout.tsx +212 -0
- package/src/main.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/app-settings-web",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "App settings module for web.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "jsb188",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
".": "./src/main.ts"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@jsb188/app": "1.1.
|
|
13
|
-
"@jsb188/react-web": "1.1.
|
|
12
|
+
"@jsb188/app": "1.1.6",
|
|
13
|
+
"@jsb188/react-web": "1.1.6",
|
|
14
14
|
"react-router": "^7.8.2",
|
|
15
15
|
"jotai": "^2.13.1",
|
|
16
16
|
"react": "^19.1.1"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModalContentContainer, ModalFloatingSaveButton, ModalSideNav, ModalSideNavIface } from '@jsb188/react-web/ui/ModalUI';
|
|
2
2
|
import type { ModalHandlerProps, OpenModalPopUpFn } from '@jsb188/react/states';
|
|
3
|
-
import { useKeyDown } from '@jsb188/react/states';
|
|
4
|
-
import { useEffect, useState } from 'react';
|
|
3
|
+
import { useClosePopOver, useKeyDown } from '@jsb188/react/states';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Types
|
|
@@ -33,6 +33,8 @@ export function AppSettingsLayout(p: ModalHandlerProps & {
|
|
|
33
33
|
}) {
|
|
34
34
|
const { SwitchCaseComponent, openModalPopUp, options } = p;
|
|
35
35
|
const [keyDown, setKeyDown] = useKeyDown();
|
|
36
|
+
const closePopOver = useClosePopOver();
|
|
37
|
+
const scrollAreaRef = useRef<HTMLDivElement | null>(null);
|
|
36
38
|
|
|
37
39
|
// const setKeyDown = (value: any) => {
|
|
38
40
|
// dispatchApp({
|
|
@@ -53,9 +55,6 @@ export function AppSettingsLayout(p: ModalHandlerProps & {
|
|
|
53
55
|
|
|
54
56
|
const onClickNavItem = (value: any) => {
|
|
55
57
|
const handlerValue = p.onClickNavItem?.(value);
|
|
56
|
-
// @ts-ignore - value will be undefined or boolean
|
|
57
|
-
console.log('handlerValue', handlerValue);
|
|
58
|
-
|
|
59
58
|
if (handlerValue !== false) {
|
|
60
59
|
setController({
|
|
61
60
|
switchCase: value,
|
|
@@ -98,6 +97,26 @@ export function AppSettingsLayout(p: ModalHandlerProps & {
|
|
|
98
97
|
}
|
|
99
98
|
}, [keyDown.pressed]);
|
|
100
99
|
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
// Listen to scroll events inside scrollAreaRef
|
|
102
|
+
|
|
103
|
+
const scrollArea = scrollAreaRef.current;
|
|
104
|
+
if (!scrollArea) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const onScroll = () => {
|
|
109
|
+
// Close pop over on scroll
|
|
110
|
+
closePopOver();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
scrollArea.addEventListener('scroll', onScroll);
|
|
114
|
+
|
|
115
|
+
return () => {
|
|
116
|
+
scrollArea.removeEventListener('scroll', onScroll);
|
|
117
|
+
};
|
|
118
|
+
}, [closePopOver]);
|
|
119
|
+
|
|
101
120
|
return (
|
|
102
121
|
<div className='cw md h_top f rel of'>
|
|
103
122
|
<ModalSideNav
|
|
@@ -106,7 +125,11 @@ export function AppSettingsLayout(p: ModalHandlerProps & {
|
|
|
106
125
|
onClickItem={onClickNavItem}
|
|
107
126
|
/>
|
|
108
127
|
|
|
109
|
-
<ModalContentContainer
|
|
128
|
+
<ModalContentContainer
|
|
129
|
+
ref={scrollAreaRef}
|
|
130
|
+
addFooterPadding
|
|
131
|
+
addYOverflow
|
|
132
|
+
>
|
|
110
133
|
<div className='f py_md px_lg'>
|
|
111
134
|
<SwitchCaseComponent
|
|
112
135
|
key={`switch_case_${controller.resetCounter}`}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import i18n from '@jsb188/app/i18n';
|
|
2
|
+
import { useConfirmPassword } from '@jsb188/graphql/hooks/use-auth-mtn';
|
|
3
|
+
import { Input } from '@jsb188/react-web/modules/Form';
|
|
4
|
+
import { AlertPopUp, ModalErrorMessage } from '@jsb188/react-web/ui/ModalUI';
|
|
5
|
+
import type { ModalPopUpComponentProps } from '@jsb188/react/states';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Types
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export interface ConfirmPasswordProps extends ModalPopUpComponentProps {
|
|
13
|
+
confirmPasswordTitle?: string;
|
|
14
|
+
confirmPasswordMessage?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ChangeCredentialsFinishedProps extends ModalPopUpComponentProps {
|
|
18
|
+
finishedIconName?: string;
|
|
19
|
+
finishedTitle?: string;
|
|
20
|
+
finishedMessage?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ChangeCredentialsProps extends ConfirmPasswordProps {
|
|
24
|
+
iconName: string;
|
|
25
|
+
skipPassword?: boolean;
|
|
26
|
+
title: string;
|
|
27
|
+
message: string;
|
|
28
|
+
|
|
29
|
+
finishedIconName?: string;
|
|
30
|
+
finishedTitle?: string;
|
|
31
|
+
finishedMessage?: string;
|
|
32
|
+
|
|
33
|
+
verifyIconName?: string;
|
|
34
|
+
verifyTitle?: string;
|
|
35
|
+
verifyMessage?: string;
|
|
36
|
+
|
|
37
|
+
confirmText?: string;
|
|
38
|
+
status: 'WAITING_FOR_INPUT' | 'WAITING_FOR_VERIFICATION' | 'WAITING_FOR_CODE' | 'FINISHED';
|
|
39
|
+
onSubmit: (values: string[]) => void;
|
|
40
|
+
|
|
41
|
+
loading?: boolean;
|
|
42
|
+
error: any;
|
|
43
|
+
resetErrors: () => void;
|
|
44
|
+
inputs: {
|
|
45
|
+
label: string;
|
|
46
|
+
placeholder?: string;
|
|
47
|
+
}[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Confirm password before changinge sensitive account settings
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
function ConfirmPasswordForm(p: ConfirmPasswordProps & {
|
|
55
|
+
setPasswordVerified: (verified: boolean) => void;
|
|
56
|
+
}) {
|
|
57
|
+
const { setPasswordVerified, onCloseModal, confirmPasswordTitle, confirmPasswordMessage } = p;
|
|
58
|
+
const [password, setPassword] = useState('');
|
|
59
|
+
|
|
60
|
+
const { confirmPassword, error, resetErrors, saving } = useConfirmPassword({
|
|
61
|
+
onCompleted: (data: any) => {
|
|
62
|
+
if (data.confirmPassword) {
|
|
63
|
+
setPasswordVerified(true);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
onError: () => {
|
|
67
|
+
setPassword('');
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const onConfirmPassword = () => {
|
|
72
|
+
confirmPassword({
|
|
73
|
+
variables: {
|
|
74
|
+
password,
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const onPressEnter = (e: React.KeyboardEvent) => {
|
|
80
|
+
if (e.key === 'Enter' && password) {
|
|
81
|
+
onConfirmPassword();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return <AlertPopUp
|
|
86
|
+
loading={saving}
|
|
87
|
+
iconName='password-lock-1'
|
|
88
|
+
confirmText={i18n.t('form.authenticate')}
|
|
89
|
+
cancelText={i18n.t('form.cancel')}
|
|
90
|
+
onConfirm={onConfirmPassword}
|
|
91
|
+
onCancel={onCloseModal}
|
|
92
|
+
disabledConfirm={!password}
|
|
93
|
+
title={confirmPasswordTitle ?? i18n.t('account.enter_password')}
|
|
94
|
+
message={confirmPasswordMessage ?? i18n.t('account.enter_password_msg')}
|
|
95
|
+
>
|
|
96
|
+
{error && (
|
|
97
|
+
<div className='px_md mt_md -mb_df'>
|
|
98
|
+
<ModalErrorMessage
|
|
99
|
+
error={error}
|
|
100
|
+
resetErrors={resetErrors}
|
|
101
|
+
/>
|
|
102
|
+
</div>
|
|
103
|
+
)}
|
|
104
|
+
|
|
105
|
+
<div className='mt_df mx_md'>
|
|
106
|
+
<Input
|
|
107
|
+
type='password'
|
|
108
|
+
label={i18n.t('account.password')}
|
|
109
|
+
placeholder='••••'
|
|
110
|
+
value={password}
|
|
111
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
112
|
+
onKeyDown={onPressEnter}
|
|
113
|
+
autoFocus
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
</AlertPopUp>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Change account settings that require confirmations (such as credentials)
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
export function ChangeCredentialsLayout(p: ChangeCredentialsProps) {
|
|
124
|
+
const {
|
|
125
|
+
iconName, skipPassword, title, message, confirmText, loading, error, resetErrors, inputs, onSubmit, status,
|
|
126
|
+
finishedIconName, finishedTitle, finishedMessage,
|
|
127
|
+
verifyIconName, verifyTitle, verifyMessage,
|
|
128
|
+
...rest
|
|
129
|
+
} = p;
|
|
130
|
+
const { onCloseModal } = rest;
|
|
131
|
+
const [passwordVerified, setPasswordVerified] = useState(false);
|
|
132
|
+
const [values, setValues] = useState(['', '']);
|
|
133
|
+
|
|
134
|
+
switch (status) {
|
|
135
|
+
case 'FINISHED':
|
|
136
|
+
return <AlertPopUp
|
|
137
|
+
onCloseModal={onCloseModal}
|
|
138
|
+
iconName={finishedIconName || 'circle-check'}
|
|
139
|
+
onCancel={onCloseModal}
|
|
140
|
+
title={finishedTitle || i18n.t('form.success_')}
|
|
141
|
+
message={finishedMessage || i18n.t('form.your_request_is_completed_msg')}
|
|
142
|
+
/>;
|
|
143
|
+
case 'WAITING_FOR_CODE':
|
|
144
|
+
return 'waiting for code';
|
|
145
|
+
case 'WAITING_FOR_VERIFICATION':
|
|
146
|
+
return <AlertPopUp
|
|
147
|
+
onCloseModal={onCloseModal}
|
|
148
|
+
iconName={verifyIconName || iconName}
|
|
149
|
+
onCancel={onCloseModal}
|
|
150
|
+
title={verifyTitle || i18n.t('form.please_verify')}
|
|
151
|
+
message={verifyMessage || i18n.t('form.request_will_complete_once_verified_msg')}
|
|
152
|
+
/>;
|
|
153
|
+
case 'WAITING_FOR_INPUT':
|
|
154
|
+
default:
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!passwordVerified && !skipPassword) {
|
|
158
|
+
return <ConfirmPasswordForm
|
|
159
|
+
{...rest}
|
|
160
|
+
setPasswordVerified={setPasswordVerified}
|
|
161
|
+
/>;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const hasTwoInputs = inputs.length >= 2;
|
|
165
|
+
const hasValidInputs = !!(hasTwoInputs ? values[0]?.trim() && values[1]?.trim() : values[0]?.trim());
|
|
166
|
+
|
|
167
|
+
const onPressEnter = (e: React.KeyboardEvent) => {
|
|
168
|
+
if (e.key === 'Enter' && hasValidInputs) {
|
|
169
|
+
onSubmit(values);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
return <AlertPopUp
|
|
174
|
+
iconName={iconName}
|
|
175
|
+
doNotExitOnConfirm
|
|
176
|
+
loading={loading}
|
|
177
|
+
onCloseModal={onCloseModal}
|
|
178
|
+
onConfirm={() => onSubmit(values)}
|
|
179
|
+
title={title}
|
|
180
|
+
message={message}
|
|
181
|
+
confirmText={confirmText}
|
|
182
|
+
cancelText={i18n.t('form.cancel')}
|
|
183
|
+
disabledConfirm={!hasValidInputs}
|
|
184
|
+
>
|
|
185
|
+
{error && (
|
|
186
|
+
<div className='px_md mt_md -mb_df'>
|
|
187
|
+
<ModalErrorMessage
|
|
188
|
+
error={error}
|
|
189
|
+
resetErrors={resetErrors}
|
|
190
|
+
/>
|
|
191
|
+
</div>
|
|
192
|
+
)}
|
|
193
|
+
|
|
194
|
+
<div className='mt_df mx_md'>
|
|
195
|
+
{inputs.map((obj, i) => {
|
|
196
|
+
return <Input
|
|
197
|
+
key={i}
|
|
198
|
+
type='text'
|
|
199
|
+
{...obj}
|
|
200
|
+
value={values[i]}
|
|
201
|
+
onChange={(e) => {
|
|
202
|
+
const newValues = [...values];
|
|
203
|
+
newValues[i] = e.target.value;
|
|
204
|
+
setValues(newValues);
|
|
205
|
+
}}
|
|
206
|
+
onKeyDown={onPressEnter}
|
|
207
|
+
autoFocus={!i}
|
|
208
|
+
/>
|
|
209
|
+
})}
|
|
210
|
+
</div>
|
|
211
|
+
</AlertPopUp>;
|
|
212
|
+
};
|
package/src/main.ts
CHANGED