@jsb188/auth-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.
@@ -6,26 +6,32 @@ import SchemaForm from '@jsb188/react-web/modules/SchemaForm';
6
6
  import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
7
7
  import { FullWidthButton } from '@jsb188/react-web/ui/Button';
8
8
  import Markdown from '@jsb188/react-web/ui/Markdown';
9
- import { ModalErrorMessage, ModalSimpleContent } from '@jsb188/react-web/ui/ModalUI';
9
+ import {
10
+ ModalErrorMessage,
11
+ ModalSimpleContent,
12
+ } from '@jsb188/react-web/ui/ModalUI';
10
13
  import { AppContext } from '@jsb188/react/states';
11
14
  import { useContext, useMemo, useState } from 'react';
12
15
  import { AuthFormContainer } from './AuthFormUI';
13
- import { makeAssignPasswordSchema, makeRequestTokenizedEmailSchema } from './schemas';
16
+ import {
17
+ makeAssignPasswordSchema,
18
+ makeRequestTokenizedEmailSchema,
19
+ } from './schemas';
14
20
 
15
21
  /**
16
22
  * Types
17
23
  */
18
24
 
19
25
  interface FinishedResultObj {
20
- hasPassword: boolean;
21
- email: any;
22
- };
26
+ hasPassword: boolean;
27
+ email: any;
28
+ }
23
29
 
24
30
  interface RequiredAuthSwitchCaseProps {
25
- identifier: string;
26
- onFinish: () => void;
27
- finishedResult: FinishedResultObj;
28
- setFinishedResult: any;
31
+ identifier: string;
32
+ onFinish: () => void;
33
+ finishedResult: FinishedResultObj;
34
+ setFinishedResult: any;
29
35
  }
30
36
 
31
37
  /**
@@ -33,25 +39,25 @@ interface RequiredAuthSwitchCaseProps {
33
39
  */
34
40
 
35
41
  function AccountSecuredMessage(p: RequiredAuthSwitchCaseProps) {
36
- const { onFinish } = p;
37
-
38
- return <ModalSimpleContent
39
- // title='Finished!'
40
- iconName={COMMON_ICON_NAMES.verified}
41
- className='px_df pt_md'
42
- >
43
- <Markdown as='p'>
44
- {i18n.t('auth.required_auth_fin_msg')}
45
- </Markdown>
46
-
47
- <FullWidthButton
48
- preset='bg_primary'
49
- className='mt_md shadow'
50
- onClick={onFinish}
51
- >
52
- {i18n.t('auth.continue_to_app')}
53
- </FullWidthButton>
54
- </ModalSimpleContent>;
42
+ const { onFinish } = p;
43
+
44
+ return (
45
+ <ModalSimpleContent
46
+ // title='Finished!'
47
+ iconName={COMMON_ICON_NAMES.verified}
48
+ className="px_df pt_md"
49
+ >
50
+ <Markdown as="p">{i18n.t('auth.required_auth_fin_msg')}</Markdown>
51
+
52
+ <FullWidthButton
53
+ preset="bg_primary"
54
+ className="mt_md shadow"
55
+ onClick={onFinish}
56
+ >
57
+ {i18n.t('auth.continue_to_app')}
58
+ </FullWidthButton>
59
+ </ModalSimpleContent>
60
+ );
55
61
  }
56
62
 
57
63
  /**
@@ -59,53 +65,52 @@ function AccountSecuredMessage(p: RequiredAuthSwitchCaseProps) {
59
65
  */
60
66
 
61
67
  function SetPasswordForm(p: RequiredAuthSwitchCaseProps) {
62
-
63
- const { identifier, setFinishedResult } = p;
64
- const assignPasswordSchema = useMemo(makeAssignPasswordSchema, []);
65
-
66
- const { changeAccountPassword, saving, error, setError, resetErrors } = useChangeAccountPassword({
67
- doNotFinishForm: true,
68
- onCompleted: (passwordChanged: boolean) => {
69
- if (passwordChanged) {
70
- setFinishedResult((fr: FinishedResultObj) => ({
71
- ...fr,
72
- hasPassword: true
73
- }));
74
- }
75
- }
76
- });
77
-
78
- const onSubmit = (fv: any) => {
79
- changeAccountPassword({
80
- variables: {
81
- currentPassword: '',
82
- password: fv.password,
83
- }
84
- });
85
- };
86
-
87
- return <>
88
- <p className='a_c mx_df mb_df -mt_5 pb_xs'>
89
- {i18n.t('auth.add_password_sign_in_msg', { identifier })}
90
- </p>
91
-
92
- <SchemaForm
93
- className='pb_df fs'
94
- saving={saving}
95
- schema={assignPasswordSchema}
96
- // currentData={{}}
97
- onError={setError}
98
- onSubmit={onSubmit}
99
- buttonText={i18n.t('auth.add_password')}
100
- >
101
- {!error ? null : (
102
- <ModalErrorMessage
103
- error={error}
104
- resetErrors={resetErrors}
105
- />
106
- )}
107
- </SchemaForm>
108
- </>;
68
+ const { identifier, setFinishedResult } = p;
69
+ const assignPasswordSchema = useMemo(makeAssignPasswordSchema, []);
70
+
71
+ const { changeAccountPassword, saving, error, setError, resetErrors } =
72
+ useChangeAccountPassword({
73
+ doNotFinishForm: true,
74
+ onCompleted: (passwordChanged: boolean) => {
75
+ if (passwordChanged) {
76
+ setFinishedResult((fr: FinishedResultObj) => ({
77
+ ...fr,
78
+ hasPassword: true,
79
+ }));
80
+ }
81
+ },
82
+ });
83
+
84
+ const onSubmit = (fv: any) => {
85
+ changeAccountPassword({
86
+ variables: {
87
+ currentPassword: '',
88
+ password: fv.password,
89
+ },
90
+ });
91
+ };
92
+
93
+ return (
94
+ <>
95
+ <p className="a_c mx_df mb_df -mt_5 pb_xs">
96
+ {i18n.t('auth.add_password_sign_in_msg', { identifier })}
97
+ </p>
98
+
99
+ <SchemaForm
100
+ className="pb_df fs"
101
+ saving={saving}
102
+ schema={assignPasswordSchema}
103
+ // currentData={{}}
104
+ onError={setError}
105
+ onSubmit={onSubmit}
106
+ buttonText={i18n.t('auth.add_password')}
107
+ >
108
+ {!error ? null : (
109
+ <ModalErrorMessage error={error} resetErrors={resetErrors} />
110
+ )}
111
+ </SchemaForm>
112
+ </>
113
+ );
109
114
  }
110
115
 
111
116
  /**
@@ -113,58 +118,59 @@ function SetPasswordForm(p: RequiredAuthSwitchCaseProps) {
113
118
  */
114
119
 
115
120
  function SetEmailForm(p: RequiredAuthSwitchCaseProps) {
116
-
117
- const { identifier } = p;
118
- const [waitingForVerification, setWaitingForVerification] = useState(false);
119
- const assignPasswordSchema = useMemo(makeRequestTokenizedEmailSchema, []);
120
-
121
- const { requestChangeEmail, error, setError, resetErrors, saving } = useRequestChangeEmail({
122
- onCompleted: (data: any) => {
123
- if (data.requestChangeEmail) {
124
- setWaitingForVerification(true);
125
- }
126
- }
127
- });
128
-
129
- const onSubmit = (fv: any) => {
130
- requestChangeEmail({
131
- variables: {
132
- emailAddress: fv.email,
133
- }
134
- });
135
- };
136
-
137
- if (waitingForVerification) {
138
- return <ModalSimpleContent
139
- className='px_df pt_md pb_25'
140
- iconName={COMMON_ICON_NAMES.email_address}
141
- title={i18n.t('auth.check_email')}
142
- message={i18n.t('auth.check_email_to_login_msg')}
143
- />;
144
- }
145
-
146
- return <>
147
- <p className='a_c mx_df mb_df -mt_5 pb_xs'>
148
- {i18n.t('auth.add_email_to_login_msg', { identifier })}
149
- </p>
150
-
151
- <SchemaForm
152
- className='pb_df fs'
153
- saving={saving}
154
- schema={assignPasswordSchema}
155
- // currentData={{}}
156
- onError={setError}
157
- onSubmit={onSubmit}
158
- buttonText={i18n.t('auth.add_email')}
159
- >
160
- {!error ? null : (
161
- <ModalErrorMessage
162
- error={error}
163
- resetErrors={resetErrors}
164
- />
165
- )}
166
- </SchemaForm>
167
- </>;
121
+ const { identifier } = p;
122
+ const [waitingForVerification, setWaitingForVerification] = useState(false);
123
+ const assignPasswordSchema = useMemo(makeRequestTokenizedEmailSchema, []);
124
+
125
+ const { requestChangeEmail, error, setError, resetErrors, saving } =
126
+ useRequestChangeEmail({
127
+ onCompleted: (data: any) => {
128
+ if (data.requestChangeEmail) {
129
+ setWaitingForVerification(true);
130
+ }
131
+ },
132
+ });
133
+
134
+ const onSubmit = (fv: any) => {
135
+ requestChangeEmail({
136
+ variables: {
137
+ emailAddress: fv.email,
138
+ },
139
+ });
140
+ };
141
+
142
+ if (waitingForVerification) {
143
+ return (
144
+ <ModalSimpleContent
145
+ className="px_df pt_md pb_25"
146
+ iconName={COMMON_ICON_NAMES.email_address}
147
+ title={i18n.t('auth.check_email')}
148
+ message={i18n.t('auth.check_email_to_login_msg')}
149
+ />
150
+ );
151
+ }
152
+
153
+ return (
154
+ <>
155
+ <p className="a_c mx_df mb_df -mt_5 pb_xs">
156
+ {i18n.t('auth.add_email_to_login_msg', { identifier })}
157
+ </p>
158
+
159
+ <SchemaForm
160
+ className="pb_df fs"
161
+ saving={saving}
162
+ schema={assignPasswordSchema}
163
+ // currentData={{}}
164
+ onError={setError}
165
+ onSubmit={onSubmit}
166
+ buttonText={i18n.t('auth.add_email')}
167
+ >
168
+ {!error ? null : (
169
+ <ModalErrorMessage error={error} resetErrors={resetErrors} />
170
+ )}
171
+ </SchemaForm>
172
+ </>
173
+ );
168
174
  }
169
175
 
170
176
  /**
@@ -172,16 +178,16 @@ function SetEmailForm(p: RequiredAuthSwitchCaseProps) {
172
178
  */
173
179
 
174
180
  function RequiredAuthSwitchCase(p: RequiredAuthSwitchCaseProps) {
175
- const { finishedResult } = p;
181
+ const { finishedResult } = p;
176
182
 
177
- if (!finishedResult.hasPassword) {
178
- return <SetPasswordForm {...p} />;
179
- } else if (!finishedResult.email) {
180
- // Keep email check last, becuase it has a verification step
181
- return <SetEmailForm {...p} />;
182
- }
183
+ if (!finishedResult.hasPassword) {
184
+ return <SetPasswordForm {...p} />;
185
+ } else if (!finishedResult.email) {
186
+ // Keep email check last, becuase it has a verification step
187
+ return <SetEmailForm {...p} />;
188
+ }
183
189
 
184
- return <AccountSecuredMessage {...p} />;
190
+ return <AccountSecuredMessage {...p} />;
185
191
  }
186
192
 
187
193
  /**
@@ -189,40 +195,46 @@ function RequiredAuthSwitchCase(p: RequiredAuthSwitchCaseProps) {
189
195
  */
190
196
 
191
197
  export function AssignRequiredAuth(p: {
192
- hasPassword: boolean;
193
- hasEmail: boolean;
198
+ hasPassword: boolean;
199
+ hasEmail: boolean;
194
200
  }) {
195
- const { dispatchApp, appState: { hasPassword, account } } = useContext(AppContext);
196
- const identifier = account?.email?.address || account?.phone?.number || account?.id;
197
-
198
- const [finishedResult, setFinishedResult] = useState({
199
- hasPassword,
200
- email: account?.email?.address ? account?.email : null,
201
- });
202
-
203
- const onFinish = () => {
204
- if (!hasPassword) {
205
- dispatchApp({
206
- __type: 'APP_EDIT_AUTH',
207
- data: {
208
- id: account?.id,
209
- ...finishedResult
210
- }
211
- });
212
- }
213
- };
214
-
215
- return <FullPageLayout className='pattern_dot active_bf bg_fade'>
216
- <AuthFormContainer
217
- title={i18n.t('auth.one_last_step_')}
218
- className='bd_5 bd_main'
219
- >
220
- <RequiredAuthSwitchCase
221
- identifier={identifier!}
222
- finishedResult={finishedResult}
223
- setFinishedResult={setFinishedResult}
224
- onFinish={onFinish}
225
- />
226
- </AuthFormContainer>
227
- </FullPageLayout>;
201
+ const {
202
+ dispatchApp,
203
+ appState: { hasPassword, account },
204
+ } = useContext(AppContext);
205
+ const identifier =
206
+ account?.email?.address || account?.phone?.number || account?.id;
207
+
208
+ const [finishedResult, setFinishedResult] = useState({
209
+ hasPassword,
210
+ email: account?.email?.address ? account?.email : null,
211
+ });
212
+
213
+ const onFinish = () => {
214
+ if (!hasPassword) {
215
+ dispatchApp({
216
+ __type: 'APP_EDIT_AUTH',
217
+ data: {
218
+ id: account?.id,
219
+ ...finishedResult,
220
+ },
221
+ });
222
+ }
223
+ };
224
+
225
+ return (
226
+ <FullPageLayout className="pattern_dot active_bf bg_fade">
227
+ <AuthFormContainer
228
+ title={i18n.t('auth.one_last_step_')}
229
+ className="bd_5 bd_main"
230
+ >
231
+ <RequiredAuthSwitchCase
232
+ identifier={identifier!}
233
+ finishedResult={finishedResult}
234
+ setFinishedResult={setFinishedResult}
235
+ onFinish={onFinish}
236
+ />
237
+ </AuthFormContainer>
238
+ </FullPageLayout>
239
+ );
228
240
  }
@@ -8,38 +8,38 @@ import { memo } from 'react';
8
8
  */
9
9
 
10
10
  interface AuthFormContainerProps {
11
- title?: string;
12
- className?: string;
13
- backHref?: string | null;
14
- children: React.ReactNode;
11
+ title?: string;
12
+ className?: string;
13
+ backHref?: string | null;
14
+ children: React.ReactNode;
15
15
  }
16
16
 
17
17
  export const AuthFormContainer = memo((p: AuthFormContainerProps) => {
18
- const { title, className, backHref, children } = p;
19
- const goBackLabel = backHref ? i18n.t('form.go_back') : '';
18
+ const { title, className, backHref, children } = p;
19
+ const goBackLabel = backHref ? i18n.t('form.go_back') : '';
20
20
 
21
- return (
22
- <div className='cw xs'>
23
- {!!backHref && (
24
- <a
25
- href={backHref}
26
- aria-label={goBackLabel}
27
- title={goBackLabel}
28
- className='abs_tl_df av av_df r h_center bg cl_df bg_active_hv shadow_line z2 link'
29
- >
30
- <Icon name='arrow-left' />
31
- </a>
32
- )}
33
- <div className='a_c -mb_5 anim_lift_scale_center on_mount spd_4'>
34
- <h1 className='ft_lg ft_bold ls_1 lh_1 p_n cl_secondary op_50 visible'>
35
- {title}
36
- </h1>
37
- </div>
38
- <div className={cn('bg px_md py_lg r_dfw rel z2', className)}>
39
- {children}
40
- </div>
41
- </div>
42
- );
21
+ return (
22
+ <div className="cw xs">
23
+ {!!backHref && (
24
+ <a
25
+ href={backHref}
26
+ aria-label={goBackLabel}
27
+ title={goBackLabel}
28
+ className="abs_tl_df av av_df r h_center bg cl_df bg_active_hv shadow_line z2 link"
29
+ >
30
+ <Icon name="arrow-left" />
31
+ </a>
32
+ )}
33
+ <div className="a_c -mb_5 anim_lift_scale_center on_mount spd_4">
34
+ <h1 className="ft_lg ft_bold ls_1 lh_1 p_n cl_secondary op_50 visible">
35
+ {title}
36
+ </h1>
37
+ </div>
38
+ <div className={cn('bg px_md py_lg r_dfw rel z2', className)}>
39
+ {children}
40
+ </div>
41
+ </div>
42
+ );
43
43
  });
44
44
 
45
45
  AuthFormContainer.displayName = 'AuthFormContainer';