@jsb188/app-settings-web 1.1.10 → 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 +20 -20
- package/src/AppSettingsLayout.tsx +182 -180
- package/src/ChangeCredentialsLayout.tsx +294 -233
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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/
|
|
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 {
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
onSave: () => void;
|
|
29
|
+
onChangeDiff: (hasChanges?: boolean, saving?: boolean) => void;
|
|
30
|
+
openModalPopUp: OpenModalPopUpFn;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
export interface AppSettingsTableContentProps {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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 {
|
|
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
|
-
|
|
19
|
+
onPasswordVerified?: (password: string) => void;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
export interface ChangeCredentialsFinishedProps
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
28
|
-
|
|
32
|
+
title: string;
|
|
33
|
+
message: string;
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
finishedIconName?: string;
|
|
36
|
+
finishedTitle?: string;
|
|
37
|
+
finishedMessage?: string;
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
verifyIconName?: string;
|
|
40
|
+
verifyTitle?: string;
|
|
41
|
+
verifyMessage?: string;
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
onError: () => {
|
|
82
|
-
setPassword('');
|
|
83
|
-
}
|
|
84
|
-
});
|
|
110
|
+
const onConfirmPassword = () => {
|
|
111
|
+
confirmPassword({
|
|
112
|
+
variables: {
|
|
113
|
+
password,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
};
|
|
85
117
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
});
|
|
92
|
-
};
|
|
118
|
+
const onPressEnter = (e: React.KeyboardEvent) => {
|
|
119
|
+
if (e.key === 'Enter' && password) {
|
|
120
|
+
onConfirmPassword();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
93
123
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
266
|
+
return (
|
|
267
|
+
<ConfirmPasswordForm
|
|
268
|
+
{...rest}
|
|
269
|
+
setPasswordVerified={setPasswordVerified}
|
|
270
|
+
onPasswordVerified={setConfirmedPassword}
|
|
271
|
+
/>
|
|
272
|
+
);
|
|
221
273
|
}
|
|
222
274
|
|
|
223
|
-
|
|
224
|
-
|
|
275
|
+
const hasTwoInputs = inputs.length >= 2;
|
|
276
|
+
const hasValidInputs = !!(hasTwoInputs
|
|
277
|
+
? values[0]?.trim() && values[1]?.trim()
|
|
278
|
+
: values[0]?.trim());
|
|
225
279
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
280
|
+
const onPressEnter = (e: React.KeyboardEvent) => {
|
|
281
|
+
if (e.key === 'Enter' && hasValidInputs) {
|
|
282
|
+
onSubmit(values, confirmedPassword);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
231
285
|
|
|
232
|
-
return
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
+
}
|