From bc2ccf671e0dd04d633f3d7b43840633b080c434 Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Wed, 17 Jul 2024 11:08:01 +0800 Subject: [PATCH] refactor(console): use button loading in experience flow if possible (#6234) --- .../Providers/LoadingLayerProvider/index.tsx | 6 +- .../components/LoadingLayer/index.module.scss | 7 --- .../src/components/LoadingLayer/index.tsx | 6 +- .../components/LoadingMask/index.module.scss | 8 +++ .../src/components/LoadingMask/index.tsx | 13 +++++ .../src/containers/SetPassword/Lite.tsx | 15 +++-- .../containers/SetPassword/SetPassword.tsx | 15 +++-- .../src/containers/SetPassword/index.tsx | 2 +- .../TotpCodeVerification/index.module.scss | 4 ++ .../containers/TotpCodeVerification/index.tsx | 57 ++++++++++++++----- .../use-totp-code-verification.ts | 4 +- .../VerificationCode/index.module.scss | 3 +- .../src/containers/VerificationCode/index.tsx | 53 +++++++++++++---- .../experience/src/pages/Consent/index.tsx | 6 +- .../Continue/IdentifierProfileForm/index.tsx | 6 +- .../ForgotPasswordForm/index.tsx | 7 ++- .../MfaBinding/BackupCodeBinding/index.tsx | 9 ++- .../MfaBinding/WebAuthnBinding/index.tsx | 9 ++- .../BackupCodeVerification/index.tsx | 10 +++- .../WebAuthnVerification/index.tsx | 9 ++- .../Register/IdentifierRegisterForm/index.tsx | 3 +- .../SignIn/IdentifierSignInForm/index.tsx | 3 +- .../pages/SignIn/PasswordSignInForm/index.tsx | 3 +- .../SignInPassword/PasswordForm/index.tsx | 4 +- .../src/pages/SingleSignOnEmail/index.tsx | 9 ++- 25 files changed, 194 insertions(+), 77 deletions(-) create mode 100644 packages/experience/src/components/LoadingMask/index.module.scss create mode 100644 packages/experience/src/components/LoadingMask/index.tsx diff --git a/packages/experience/src/Providers/LoadingLayerProvider/index.tsx b/packages/experience/src/Providers/LoadingLayerProvider/index.tsx index eccc54c9b..2c3601ee0 100644 --- a/packages/experience/src/Providers/LoadingLayerProvider/index.tsx +++ b/packages/experience/src/Providers/LoadingLayerProvider/index.tsx @@ -1,18 +1,16 @@ import { useContext } from 'react'; import { Outlet } from 'react-router-dom'; -import { useDebouncedLoader } from 'use-debounced-loader'; import PageContext from '@/Providers/PageContextProvider/PageContext'; -import LoadingLayer from '@/components/LoadingLayer'; +import LoadingMask from '@/components/LoadingMask'; const LoadingLayerProvider = () => { const { loading } = useContext(PageContext); - const debouncedLoading = useDebouncedLoader(loading, 500); return ( <> - {debouncedLoading && } + {loading && } ); }; diff --git a/packages/experience/src/components/LoadingLayer/index.module.scss b/packages/experience/src/components/LoadingLayer/index.module.scss index 4f24e5e8b..115c477e4 100644 --- a/packages/experience/src/components/LoadingLayer/index.module.scss +++ b/packages/experience/src/components/LoadingLayer/index.module.scss @@ -1,12 +1,5 @@ @use '@/scss/underscore' as _; -.overlay { - position: fixed; - inset: 0; - @include _.flex-column; - z-index: 300; -} - .loadingIcon { color: var(--color-type-primary); animation: rotating 1s steps(12, end) infinite; diff --git a/packages/experience/src/components/LoadingLayer/index.tsx b/packages/experience/src/components/LoadingLayer/index.tsx index 4db64f3a1..52b43e236 100644 --- a/packages/experience/src/components/LoadingLayer/index.tsx +++ b/packages/experience/src/components/LoadingLayer/index.tsx @@ -1,14 +1,16 @@ +import LoadingMask from '../LoadingMask'; + import LoadingIcon from './LoadingIcon'; import * as styles from './index.module.scss'; export { default as LoadingIcon } from './LoadingIcon'; const LoadingLayer = () => ( -
+
-
+
); export default LoadingLayer; diff --git a/packages/experience/src/components/LoadingMask/index.module.scss b/packages/experience/src/components/LoadingMask/index.module.scss new file mode 100644 index 000000000..30e65e818 --- /dev/null +++ b/packages/experience/src/components/LoadingMask/index.module.scss @@ -0,0 +1,8 @@ +@use '@/scss/underscore' as _; + +.overlay { + position: fixed; + inset: 0; + @include _.flex-column; + z-index: 300; +} diff --git a/packages/experience/src/components/LoadingMask/index.tsx b/packages/experience/src/components/LoadingMask/index.tsx new file mode 100644 index 000000000..b77e44351 --- /dev/null +++ b/packages/experience/src/components/LoadingMask/index.tsx @@ -0,0 +1,13 @@ +import { type ReactNode } from 'react'; + +import * as styles from './index.module.scss'; + +type Props = { + readonly children?: ReactNode; +}; + +const LoadingMask = ({ children }: Props) => { + return
{children}
; +}; + +export default LoadingMask; diff --git a/packages/experience/src/containers/SetPassword/Lite.tsx b/packages/experience/src/containers/SetPassword/Lite.tsx index aa1abd3b8..e3c831d76 100644 --- a/packages/experience/src/containers/SetPassword/Lite.tsx +++ b/packages/experience/src/containers/SetPassword/Lite.tsx @@ -14,7 +14,7 @@ type Props = { readonly className?: string; // eslint-disable-next-line react/boolean-prop-naming readonly autoFocus?: boolean; - readonly onSubmit: (password: string) => void; + readonly onSubmit: (password: string) => Promise; readonly errorMessage?: string; readonly clearErrorMessage?: () => void; }; @@ -29,7 +29,7 @@ const Lite = ({ className, autoFocus, onSubmit, errorMessage, clearErrorMessage const { register, handleSubmit, - formState: { errors, isValid }, + formState: { errors, isValid, isSubmitting }, } = useForm({ reValidateMode: 'onBlur', defaultValues: { newPassword: '' }, @@ -45,8 +45,8 @@ const Lite = ({ className, autoFocus, onSubmit, errorMessage, clearErrorMessage (event?: React.FormEvent) => { clearErrorMessage?.(); - void handleSubmit((data, event) => { - onSubmit(data.newPassword); + void handleSubmit(async (data) => { + await onSubmit(data.newPassword); })(event); }, [clearErrorMessage, handleSubmit, onSubmit] @@ -70,7 +70,12 @@ const Lite = ({ className, autoFocus, onSubmit, errorMessage, clearErrorMessage {errorMessage && {errorMessage}} -