@jsb188/auth-web 1.1.3 → 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.
@@ -0,0 +1,781 @@
1
+ import { APP_EMAILS } from '@jsb188/app/constants/app.ts';
2
+ import i18n from '@jsb188/app/i18n/index.ts';
3
+ import {
4
+ useCheckUsernameOrEmail,
5
+ useConfirmPhoneVerificationCode,
6
+ useRequestTokenizedEmail,
7
+ useSendPhoneVerificationCode,
8
+ useSignUpWithEmail,
9
+ } from '@jsb188/graphql/hooks/use-auth-mtn';
10
+ import { SMSCodeInput } from '@jsb188/react-web/modules/Form';
11
+ import SchemaForm from '@jsb188/react-web/modules/SchemaForm';
12
+ import { FullWidthButton } from '@jsb188/react-web/ui/Button';
13
+ import { FormBreak } from '@jsb188/react-web/ui/Form';
14
+ import Markdown, { TextWithLinks } from '@jsb188/react-web/ui/Markdown';
15
+ import {
16
+ ModalErrorMessage,
17
+ ModalSimpleContent,
18
+ } from '@jsb188/react-web/ui/ModalUI';
19
+ import { useMemo, useState } from 'react';
20
+ import { Link, useNavigate } from 'react-router';
21
+ import type { AuthPageName } from './_helpers';
22
+ import { getAuthRoute, persistSignInSession } from './_helpers';
23
+ import { SsoSignIn } from './AuthForms-SSO';
24
+ import {
25
+ ContinueWithGoogle,
26
+ ContinueWithMicrosoft,
27
+ ContinueWithPhone,
28
+ ContinueWithSso,
29
+ } from './OtherAuthButtons';
30
+ import {
31
+ makeRequestTokenizedEmailSchema,
32
+ makeSendPhoneVerificationSchema,
33
+ makeSignInSchema,
34
+ makeSignUpSchema,
35
+ } from './schemas';
36
+
37
+ /**
38
+ * Page meta tags
39
+ */
40
+
41
+ export const meta = [
42
+ {
43
+ title: i18n.t('app.route_', { text: i18n.t('app.route_auth') }),
44
+ },
45
+ ];
46
+
47
+ /**
48
+ * Sign in form (main screen)
49
+ */
50
+
51
+ interface AuthFormProps {
52
+ appNamespace: string;
53
+ initialError?: any;
54
+ initialFormData?: any;
55
+ authRoutesMap?: Record<AuthPageName, string>;
56
+ setAuthIface: (iface: SignInIface | null) => void;
57
+
58
+ // Check if needed still
59
+ onError?: (error: any) => void;
60
+ }
61
+
62
+ function SignInMain(p: AuthFormProps) {
63
+ const { authRoutesMap, initialError, initialFormData, setAuthIface } = p;
64
+ const navigate = useNavigate();
65
+ const [waitingForPostRequest, setWaitingForPostRequest] = useState(false);
66
+ const signInSchema = useMemo(makeSignInSchema, []);
67
+ const {
68
+ saving,
69
+ checkUsernameOrEmail,
70
+ dataForSchema,
71
+ setDataForSchema,
72
+ error,
73
+ setError,
74
+ resetErrors,
75
+ } = useCheckUsernameOrEmail({
76
+ initialError,
77
+ initialFormData,
78
+ });
79
+
80
+ const hidePassword = dataForSchema.hidePassword;
81
+ const onFormValuesChange = (
82
+ formValues: any,
83
+ _currentValues: any,
84
+ setFormValues: (val: any) => void,
85
+ ) => {
86
+ const hasInput = !!formValues.identifier?.trim();
87
+ if (
88
+ !hidePassword &&
89
+ formValues.identifier !== dataForSchema.lastIdentifier
90
+ ) {
91
+ setDataForSchema({
92
+ ...dataForSchema,
93
+ hasInput,
94
+ lastIdentifier: '',
95
+ hidePassword: true,
96
+ });
97
+
98
+ setFormValues({
99
+ ...formValues,
100
+ password: '',
101
+ });
102
+ } else if (hasInput !== dataForSchema.hasInput) {
103
+ setDataForSchema({
104
+ ...dataForSchema,
105
+ hasInput,
106
+ });
107
+ }
108
+ };
109
+
110
+ async function onSubmit(
111
+ formValues: any,
112
+ _currentValues: any,
113
+ setFormValues: any,
114
+ ) {
115
+ const identifier = formValues.identifier?.trim();
116
+ if (hidePassword) {
117
+ const { checkUsernameOrEmail: result } = await checkUsernameOrEmail({
118
+ variables: {
119
+ usernameOrEmail: identifier,
120
+ authCheck: true,
121
+ },
122
+ });
123
+
124
+ switch (result?.type) {
125
+ case 'PHONE':
126
+ {
127
+ if (!result.taken) {
128
+ setError({
129
+ message: i18n.t('auth.no_account_with_phone'),
130
+ });
131
+ return false;
132
+ } else if (result?.hasPassword === false) {
133
+ setAuthIface('VERIFY_PHONE');
134
+ return false;
135
+ }
136
+ // Do this if you want to redirect to sign up
137
+ // setScreen({
138
+ // name: 'sign_up',
139
+ // email: result.value,
140
+ // });
141
+ // return false;
142
+ }
143
+ break;
144
+ case 'EMAIL':
145
+ {
146
+ if (!result.taken) {
147
+ setError({
148
+ message: i18n.t('auth.no_account_with_email'),
149
+ });
150
+ // Do this if you want to redirect to sign up
151
+ // setScreen({
152
+ // name: 'sign_up',
153
+ // email: result.value,
154
+ // });
155
+ return false;
156
+ }
157
+ }
158
+ break;
159
+ default:
160
+ // This auth type is not supported
161
+ console.dev('Unknown auth type:', result);
162
+
163
+ if (result?.type) {
164
+ setError({
165
+ message: i18n.t('auth.not_valid_email_or_phone'),
166
+ });
167
+ }
168
+ return false;
169
+ }
170
+
171
+ setDataForSchema({
172
+ ...dataForSchema,
173
+ lastIdentifier: identifier || '',
174
+ hidePassword: !result?.taken,
175
+ });
176
+
177
+ setFormValues({
178
+ ...formValues,
179
+ identifier: identifier || '',
180
+ });
181
+ } else if (formValues.password && identifier) {
182
+ setWaitingForPostRequest(true);
183
+ return true; // "Do" post form
184
+ }
185
+
186
+ return false; // Do not post form
187
+ }
188
+
189
+ const showSignUpLink = hidePassword && !error;
190
+
191
+ const onFinishSignIn = async (
192
+ token: string,
193
+ sessionBootstrapToken?: string | null,
194
+ sessionPersisted?: boolean,
195
+ ) => {
196
+ const persisted =
197
+ sessionPersisted ||
198
+ (await persistSignInSession(token, sessionBootstrapToken));
199
+ if (!persisted) {
200
+ setError({
201
+ message: i18n.t('error.network_error'),
202
+ });
203
+ return false;
204
+ }
205
+ navigate(getAuthRoute('signin_success', authRoutesMap));
206
+ return true;
207
+ };
208
+
209
+ return (
210
+ <>
211
+ <ContinueWithGoogle onFinishSignIn={onFinishSignIn} />
212
+ <ContinueWithMicrosoft onFinishSignIn={onFinishSignIn} />
213
+ <ContinueWithSso onClickButton={() => setAuthIface('SSO')} />
214
+ <ContinueWithPhone onClickButton={() => setAuthIface('VERIFY_PHONE')} />
215
+
216
+ <FormBreak className="mt_md" colorClassName="strong_bf">
217
+ {i18n.t('form.or')}
218
+ </FormBreak>
219
+
220
+ <SchemaForm
221
+ doNotPostForm={(fv) => !fv.identifier || !fv.password}
222
+ httpMethod="post"
223
+ actionUrl={getAuthRoute('signin', authRoutesMap)}
224
+ className="py_df"
225
+ currentData={{ identifier: initialFormData?.identifier || '' }}
226
+ saving={saving || waitingForPostRequest}
227
+ schema={signInSchema}
228
+ dataForSchema={dataForSchema}
229
+ onSubmit={onSubmit}
230
+ onFormValuesChange={onFormValuesChange}
231
+ >
232
+ <input type="hidden" name="managedSessionVersion" value="1" />
233
+ {error && (
234
+ <ModalErrorMessage
235
+ error={error}
236
+ resetErrors={resetErrors}
237
+ // className='mt_sm'
238
+ />
239
+ )}
240
+ </SchemaForm>
241
+
242
+ <div className="a_c">
243
+ {showSignUpLink ? (
244
+ <Link
245
+ className="text ft_sm cl_md link"
246
+ to={getAuthRoute('signup', authRoutesMap)}
247
+ replace
248
+ >
249
+ {i18n.t('auth.signup_email')}
250
+ </Link>
251
+ ) : (
252
+ <button
253
+ className="text ft_sm cl_md link"
254
+ onClick={() => setAuthIface('REQUEST_PASSWORD_RESET')}
255
+ >
256
+ {i18n.t('auth.forgot_password_')}
257
+ </button>
258
+ )}
259
+ </div>
260
+ </>
261
+ );
262
+ }
263
+
264
+ /**
265
+ * Forgot password form
266
+ */
267
+
268
+ interface RequestTokenizedEmailProps extends AuthFormProps {
269
+ requestType: 'PASSWORD_RESET' | 'EMAIL_VERIFICATION';
270
+ }
271
+
272
+ function RequestTokenizedEmail(p: RequestTokenizedEmailProps) {
273
+ const { requestType, initialFormData, setAuthIface } = p;
274
+ const [error, setError] = useState<any>(null);
275
+ const initialEmailAddress = initialFormData?.identifier || '';
276
+ const onSuccess = (_emailAddress: string) => setAuthIface('EMAIL_SENT');
277
+
278
+ const tokenizedEmailSchema = useMemo(() => {
279
+ const schema = makeRequestTokenizedEmailSchema();
280
+ if (!initialEmailAddress) {
281
+ return schema;
282
+ }
283
+
284
+ return {
285
+ ...schema,
286
+ listData: schema.listData.map((obj) => {
287
+ if (obj.item.name === 'email') {
288
+ return {
289
+ ...obj,
290
+ item: {
291
+ ...obj.item,
292
+ placeholder: initialEmailAddress,
293
+ },
294
+ };
295
+ }
296
+
297
+ return obj;
298
+ }),
299
+ };
300
+ }, []);
301
+
302
+ // Data hook
303
+
304
+ const { requestTokenizedEmail, saving } = useRequestTokenizedEmail({
305
+ onCompleted: (data: any, _: any, variables: any) => {
306
+ const success = data?.requestTokenizedEmail;
307
+ if (success) {
308
+ onSuccess(variables.email);
309
+ }
310
+ },
311
+ onError: (err: any) => {
312
+ setError(err);
313
+ },
314
+ });
315
+
316
+ const onSubmit = (fv: any) => {
317
+ requestTokenizedEmail({
318
+ variables: {
319
+ ...fv,
320
+ requestType,
321
+ },
322
+ });
323
+ };
324
+
325
+ let instructionText;
326
+ switch (requestType) {
327
+ case 'PASSWORD_RESET':
328
+ instructionText = i18n.t('auth.request_reset_password_instr');
329
+ break;
330
+ case 'EMAIL_VERIFICATION':
331
+ instructionText = i18n.t('auth.resend_verification_instr');
332
+ break;
333
+ default:
334
+ }
335
+
336
+ return (
337
+ <SchemaForm
338
+ saving={saving}
339
+ schema={tokenizedEmailSchema}
340
+ currentData={{ email: initialEmailAddress || '' }}
341
+ onError={setError}
342
+ onSubmit={onSubmit}
343
+ buttonText={i18n.t('auth.resend_verification')}
344
+ >
345
+ {!error ? null : (
346
+ <ModalErrorMessage error={error} resetErrors={() => setError(null)} />
347
+ )}
348
+
349
+ <Markdown as="p" className={error ? 'py_xs a_c' : '-mt_5 pb_xs a_c'}>
350
+ {instructionText}
351
+ </Markdown>
352
+ </SchemaForm>
353
+ );
354
+ }
355
+
356
+ /**
357
+ * Request for password reset is completed
358
+ */
359
+
360
+ function ResetPasswordCompleted(p: AuthFormProps) {
361
+ const { initialFormData } = p;
362
+ const emailAddress = initialFormData?.identifier;
363
+ const supportEmail = APP_EMAILS.support;
364
+
365
+ // Because this screen is opened by a client-side fetch, emailAddress will not always be present;
366
+ // Only way to have the used email address here is if we used POST form request.
367
+
368
+ return (
369
+ <ModalSimpleContent
370
+ title={i18n.t('auth.email_sent')}
371
+ iconName="circle-check"
372
+ >
373
+ <TextWithLinks as="p">
374
+ {i18n.t(
375
+ emailAddress
376
+ ? 'auth.reset_password_requested_msg'
377
+ : 'auth.reset_password_requested_msg_no_email',
378
+ { emailAddress },
379
+ )}
380
+ </TextWithLinks>
381
+ <TextWithLinks as="p">
382
+ {i18n.t('auth.if_need_more_help_email', { emailAddress: supportEmail })}
383
+ </TextWithLinks>
384
+ </ModalSimpleContent>
385
+ );
386
+ }
387
+
388
+ /**
389
+ * Request phone verification
390
+ */
391
+
392
+ function SendPhoneVerification(p: AuthFormProps) {
393
+ const { setAuthIface } = p;
394
+ const sendPhoneVerificationSchema = useMemo(
395
+ () => makeSendPhoneVerificationSchema(),
396
+ [],
397
+ );
398
+
399
+ // Data hook
400
+
401
+ const { sendPhoneVerificationCode, saving, error, setError, resetErrors } =
402
+ useSendPhoneVerificationCode({
403
+ onCompleted: (data: any, _: any, variables: any) => {
404
+ const success = data?.sendPhoneVerificationCode;
405
+ if (success) {
406
+ setAuthIface(['VERIFY_PHONE_SENT', variables.phone]);
407
+ }
408
+ },
409
+ onError: (err: any) => {
410
+ setError(err);
411
+ },
412
+ });
413
+
414
+ const onSubmit = (fv: any) => {
415
+ sendPhoneVerificationCode({
416
+ variables: {
417
+ phone: fv.phone,
418
+ },
419
+ });
420
+ };
421
+
422
+ return (
423
+ <>
424
+ <SchemaForm
425
+ className="mb_df"
426
+ saving={saving}
427
+ schema={sendPhoneVerificationSchema}
428
+ onError={setError}
429
+ onSubmit={onSubmit}
430
+ buttonText={i18n.t('auth.send_verification_code')}
431
+ >
432
+ {!error ? null : (
433
+ <ModalErrorMessage error={error} resetErrors={resetErrors} />
434
+ )}
435
+
436
+ <p className={error ? 'py_xs a_c' : '-mt_5 pb_xs a_c'}>
437
+ {i18n.t('auth.send_verification_code_msg')}
438
+ </p>
439
+ </SchemaForm>
440
+
441
+ <div className="a_c h_center">
442
+ <button
443
+ disabled={saving}
444
+ onClick={() => setAuthIface(null)}
445
+ className="text ft_sm cl_md link"
446
+ >
447
+ {i18n.t('auth.sign_in_other_methods')}
448
+ </button>
449
+ </div>
450
+ </>
451
+ );
452
+ }
453
+
454
+ /**
455
+ * Confirm phone verification code (after it was sent)
456
+ */
457
+
458
+ interface ConfirmPhoneVerificationCodeProps extends AuthFormProps {
459
+ phoneNumber: string;
460
+ }
461
+
462
+ function ConfirmPhoneVerificationCode(p: ConfirmPhoneVerificationCodeProps) {
463
+ const { setAuthIface, phoneNumber, authRoutesMap } = p;
464
+ const [retryCount, setRetryCount] = useState(0);
465
+ const navigate = useNavigate();
466
+
467
+ // Data hook
468
+
469
+ const { confirmPhoneVerificationCode, saving, error, setError, resetErrors } =
470
+ useConfirmPhoneVerificationCode({
471
+ onCompleted: async (data: any, _: any) => {
472
+ const { success, token } = data?.confirmPhoneVerificationCode || {};
473
+
474
+ if (success && token) {
475
+ const persisted = await persistSignInSession(token);
476
+ if (!persisted) {
477
+ setError({
478
+ message: i18n.t('error.network_error'),
479
+ });
480
+ return;
481
+ }
482
+ navigate(getAuthRoute('signin_success', authRoutesMap));
483
+ } else {
484
+ setRetryCount(retryCount + 1);
485
+ setError({
486
+ message: i18n.t('auth.verification_code_wrong'),
487
+ });
488
+ }
489
+ },
490
+ });
491
+
492
+ const onSubmit = (code: string) => {
493
+ confirmPhoneVerificationCode({
494
+ variables: {
495
+ phone: phoneNumber,
496
+ code,
497
+ },
498
+ });
499
+ };
500
+
501
+ return (
502
+ <>
503
+ {!error ? null : (
504
+ <ModalErrorMessage error={error} resetErrors={resetErrors} />
505
+ )}
506
+ <SMSCodeInput
507
+ key={retryCount}
508
+ saving={saving}
509
+ error={error}
510
+ onSubmit={onSubmit}
511
+ />
512
+ <p className="a_c p_n mt_md mb_df rel">
513
+ {i18n.t('auth.confirm_verification_code_instr')}
514
+ </p>
515
+ <div className="a_c h_center">
516
+ <button
517
+ disabled={saving}
518
+ onClick={() => setAuthIface('VERIFY_PHONE')}
519
+ className="text ft_sm cl_md link"
520
+ >
521
+ {i18n.t('auth.resend_verification_code')}
522
+ </button>
523
+ </div>
524
+ </>
525
+ );
526
+ }
527
+
528
+ /**
529
+ * Sign in form
530
+ */
531
+
532
+ type SignInIface =
533
+ | 'REQUEST_PASSWORD_RESET'
534
+ | 'SSO'
535
+ | 'VERIFY_PHONE'
536
+ | 'VERIFY_EMAIL'
537
+ | 'EMAIL_SENT'
538
+ | 'VERIFY_PHONE_SENT'
539
+ | ['VERIFY_PHONE_SENT', string];
540
+
541
+ export function SignInForm(p: Omit<AuthFormProps, 'setAuthIface'>) {
542
+ const { initialError } = p;
543
+ const errCode = initialError?.errorCode;
544
+ const initialIface =
545
+ errCode === '20053'
546
+ ? 'VERIFY_PHONE'
547
+ : errCode === '20049'
548
+ ? 'VERIFY_EMAIL'
549
+ : null;
550
+ const [signInIface_, setAuthIface] = useState<SignInIface | null>(
551
+ initialIface,
552
+ );
553
+ const ifaceIsArray = Array.isArray(signInIface_);
554
+
555
+ switch (ifaceIsArray ? signInIface_[0] : signInIface_) {
556
+ case 'SSO':
557
+ // Email-first SSO sign in (org home realm discovery)
558
+ return <SsoSignIn {...p} setAuthIface={setAuthIface} />;
559
+ case 'VERIFY_PHONE':
560
+ // Attempted phone login but it was not verified
561
+ return <SendPhoneVerification {...p} setAuthIface={setAuthIface} />;
562
+ case 'VERIFY_PHONE_SENT':
563
+ // User requested phone verification code, and it was sent
564
+ return (
565
+ <ConfirmPhoneVerificationCode
566
+ {...p}
567
+ phoneNumber={ifaceIsArray ? signInIface_[1] : ''}
568
+ setAuthIface={setAuthIface}
569
+ />
570
+ );
571
+ case 'VERIFY_EMAIL':
572
+ // Attempted email login but it was not verified
573
+ return (
574
+ <RequestTokenizedEmail
575
+ {...p}
576
+ requestType="EMAIL_VERIFICATION"
577
+ setAuthIface={setAuthIface}
578
+ />
579
+ );
580
+ case 'REQUEST_PASSWORD_RESET':
581
+ return (
582
+ <RequestTokenizedEmail
583
+ {...p}
584
+ requestType="PASSWORD_RESET"
585
+ setAuthIface={setAuthIface}
586
+ />
587
+ );
588
+ case 'EMAIL_SENT':
589
+ return <ResetPasswordCompleted {...p} setAuthIface={setAuthIface} />;
590
+ default:
591
+ }
592
+
593
+ return <SignInMain {...p} setAuthIface={setAuthIface} />;
594
+ }
595
+
596
+ /**
597
+ * Sign up main form
598
+ */
599
+
600
+ interface SignUpMainProps extends Omit<AuthFormProps, 'setAuthIface'> {
601
+ setAuthIface: (iface: SignUpIface) => void;
602
+ setSignUpToken: (token: string | null) => void;
603
+ }
604
+
605
+ function SignUpMain(p: SignUpMainProps) {
606
+ const { authRoutesMap, initialError, setAuthIface, setSignUpToken } = p;
607
+ const navigate = useNavigate();
608
+ const signUpSchema = useMemo(makeSignUpSchema, []);
609
+
610
+ const { saving, signUpWithEmail, error, setError, resetErrors } =
611
+ useSignUpWithEmail({
612
+ initialError,
613
+ onCompleted: (data: any, _: any) => {
614
+ const signUpToken = data?.signUpWithEmail;
615
+
616
+ if (signUpToken) {
617
+ setSignUpToken(signUpToken);
618
+ }
619
+ },
620
+ onError: (err: any) => {
621
+ if (err?.errorCode === '20054') {
622
+ setAuthIface('INVITATION_REQUIRED');
623
+ }
624
+ },
625
+ });
626
+
627
+ const onSubmit = async (formValues: any) => {
628
+ signUpWithEmail({
629
+ variables: {
630
+ emailAddress: formValues.email,
631
+ password: formValues.password,
632
+ },
633
+ });
634
+ };
635
+
636
+ // SSO providers auto-create accounts, so they work as sign up too
637
+ const onFinishSignIn = async (
638
+ token: string,
639
+ sessionBootstrapToken?: string | null,
640
+ sessionPersisted?: boolean,
641
+ ) => {
642
+ const persisted =
643
+ sessionPersisted ||
644
+ (await persistSignInSession(token, sessionBootstrapToken));
645
+ if (!persisted) {
646
+ setError({
647
+ message: i18n.t('error.network_error'),
648
+ });
649
+ return false;
650
+ }
651
+ navigate(getAuthRoute('signin_success', authRoutesMap));
652
+ return true;
653
+ };
654
+
655
+ return (
656
+ <>
657
+ <ContinueWithGoogle onFinishSignIn={onFinishSignIn} />
658
+ <ContinueWithMicrosoft onFinishSignIn={onFinishSignIn} />
659
+
660
+ <FormBreak className="mt_md" colorClassName="strong_bf">
661
+ {i18n.t('form.or')}
662
+ </FormBreak>
663
+
664
+ <SchemaForm
665
+ className="py_df"
666
+ saving={saving}
667
+ schema={signUpSchema}
668
+ // currentData={{}}
669
+ onError={setError}
670
+ onSubmit={onSubmit}
671
+ buttonText={i18n.t('auth.agree_and_continue')}
672
+ FooterComponent={
673
+ <TextWithLinks
674
+ as="div"
675
+ className="ft_xs mt_sm cl_md"
676
+ linkClassName="u link cl_md"
677
+ >
678
+ {i18n.t('auth.sign_up_notice_msg')}
679
+ </TextWithLinks>
680
+ }
681
+ >
682
+ {!error ? null : (
683
+ <ModalErrorMessage
684
+ error={error}
685
+ resetErrors={resetErrors}
686
+ // className='mt_sm'
687
+ />
688
+ )}
689
+ </SchemaForm>
690
+
691
+ <div className="a_c h_center">
692
+ <Link
693
+ to={getAuthRoute('signin', authRoutesMap)}
694
+ replace
695
+ className="text ft_sm cl_md link"
696
+ >
697
+ {i18n.t('auth.sign_in_w_existing')}
698
+ </Link>
699
+ </div>
700
+ </>
701
+ );
702
+ }
703
+
704
+ /**
705
+ * Sign up; invitation required
706
+ */
707
+
708
+ function SignUpInviteRequired(p: Omit<AuthFormProps, 'setAuthIface'>) {
709
+ const supportEmail = APP_EMAILS.support;
710
+
711
+ return (
712
+ <ModalSimpleContent
713
+ title={i18n.t('auth.invite_required')}
714
+ iconName="mailbox-filled"
715
+ >
716
+ <TextWithLinks as="p">
717
+ {i18n.t('auth.invite_required_msg', { emailAddress: supportEmail })}
718
+ </TextWithLinks>
719
+ </ModalSimpleContent>
720
+ );
721
+ }
722
+
723
+ /**
724
+ * Sign up; success
725
+ */
726
+
727
+ interface SignUpSuccessProps extends Omit<AuthFormProps, 'setAuthIface'> {
728
+ signUpToken: string;
729
+ }
730
+
731
+ function SignUpSuccess(p: SignUpSuccessProps) {
732
+ const { authRoutesMap } = p;
733
+
734
+ return (
735
+ <ModalSimpleContent
736
+ title={i18n.t('auth.account_created')}
737
+ iconName="circle-check"
738
+ className="px_df pt_md"
739
+ >
740
+ <TextWithLinks as="p">{i18n.t('auth.account_created_msg')}</TextWithLinks>
741
+
742
+ <FullWidthButton
743
+ to={getAuthRoute('signin', authRoutesMap)}
744
+ preset="bg_primary"
745
+ className="mt_lg shadow"
746
+ replace
747
+ >
748
+ {i18n.t('auth.continue_to_login')}
749
+ </FullWidthButton>
750
+ </ModalSimpleContent>
751
+ );
752
+ }
753
+
754
+ /**
755
+ * Sign up form
756
+ */
757
+
758
+ type SignUpIface = 'INVITATION_REQUIRED' | null;
759
+
760
+ export function SignUpForm(p: Omit<AuthFormProps, 'setAuthIface'>) {
761
+ const [signUpToken, setSignUpToken] = useState<string | null>(null);
762
+ const [signUpIface, setAuthIface] = useState<SignUpIface>(null);
763
+
764
+ if (signUpToken) {
765
+ return <SignUpSuccess {...p} signUpToken={signUpToken} />;
766
+ }
767
+
768
+ switch (signUpIface) {
769
+ case 'INVITATION_REQUIRED':
770
+ return <SignUpInviteRequired {...p} />;
771
+ default:
772
+ }
773
+
774
+ return (
775
+ <SignUpMain
776
+ {...p}
777
+ setAuthIface={setAuthIface}
778
+ setSignUpToken={setSignUpToken}
779
+ />
780
+ );
781
+ }