From 1b441bf19f5ec1abaf0a89bfb8dbaffe44f7fbc5 Mon Sep 17 00:00:00 2001 From: zx <67887489+tan-zx@users.noreply.github.com> Date: Thu, 14 Apr 2022 22:05:57 +0800 Subject: [PATCH] feat: improve validation for OtpForm and LoginForm --- src/client/components/LoginForm.tsx | 29 ++++++++++++++++------------- src/client/components/OtpForm.tsx | 16 +++++++++------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/client/components/LoginForm.tsx b/src/client/components/LoginForm.tsx index c92dd8d72..424c48879 100644 --- a/src/client/components/LoginForm.tsx +++ b/src/client/components/LoginForm.tsx @@ -71,35 +71,38 @@ export const LoginForm: FC = ({ email, onLogin }) => { ) } - const hasError = () => errors.email || auth.verifyOtp.isError + const hasError = (): boolean => !!errors.token || auth.verifyOtp.isError const getErrorMessage = (): string => { - const { otp } = errors - return otp && otp.type === 'required' + return errors && errors.token ? 'Please provide a valid OTP' - : getApiErrorMessage(auth.verifyOtp.error) + : auth.verifyOtp.isError + ? getApiErrorMessage(auth.verifyOtp.error) + : '' } return (
- - One time password + + + One time password + Please enter the OTP sent to {email}. - {hasError() && ( - {getErrorMessage()} - )} +