fix(auth): reset signInUp state when email change (#9990)
When you use a prefilled email the web app checks the db to know if the user exists. If not the web app enter in signUp mode. If you changed your email after, the signup mode was not reset. This PR fixes that. Fix the error with the message "Invalid sign in up params".
This commit is contained in:
@ -3,6 +3,7 @@ import { Controller, useFormContext } from 'react-hook-form';
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { Form } from '@/auth/sign-in-up/hooks/useSignInUpForm';
|
import { Form } from '@/auth/sign-in-up/hooks/useSignInUpForm';
|
||||||
|
import { isDefined } from 'twenty-shared';
|
||||||
|
|
||||||
const StyledFullWidthMotionDiv = styled(motion.div)`
|
const StyledFullWidthMotionDiv = styled(motion.div)`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -12,7 +13,13 @@ const StyledInputContainer = styled.div`
|
|||||||
margin-bottom: ${({ theme }) => theme.spacing(3)};
|
margin-bottom: ${({ theme }) => theme.spacing(3)};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const SignInUpEmailField = ({ showErrors }: { showErrors: boolean }) => {
|
export const SignInUpEmailField = ({
|
||||||
|
showErrors,
|
||||||
|
onInputChange,
|
||||||
|
}: {
|
||||||
|
showErrors: boolean;
|
||||||
|
onInputChange?: (value: string) => void;
|
||||||
|
}) => {
|
||||||
const form = useFormContext<Form>();
|
const form = useFormContext<Form>();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -38,7 +45,10 @@ export const SignInUpEmailField = ({ showErrors }: { showErrors: boolean }) => {
|
|||||||
value={value}
|
value={value}
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
onChange={onChange}
|
onChange={(email: string) => {
|
||||||
|
if (isDefined(onInputChange)) onInputChange(email);
|
||||||
|
onChange(email);
|
||||||
|
}}
|
||||||
error={showErrors ? error?.message : undefined}
|
error={showErrors ? error?.message : undefined}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -105,6 +105,12 @@ export const SignInUpGlobalScopeForm = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onEmailChange = (email: string) => {
|
||||||
|
if (email !== form.getValues('email')) {
|
||||||
|
setSignInUpStep(SignInUpStep.Email);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<StyledContentContainer>
|
<StyledContentContainer>
|
||||||
@ -116,7 +122,10 @@ export const SignInUpGlobalScopeForm = () => {
|
|||||||
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
|
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
|
||||||
<FormProvider {...form}>
|
<FormProvider {...form}>
|
||||||
<StyledForm onSubmit={form.handleSubmit(handleSubmit)}>
|
<StyledForm onSubmit={form.handleSubmit(handleSubmit)}>
|
||||||
<SignInUpEmailField showErrors={showErrors} />
|
<SignInUpEmailField
|
||||||
|
showErrors={showErrors}
|
||||||
|
onInputChange={onEmailChange}
|
||||||
|
/>
|
||||||
{signInUpStep === SignInUpStep.Password && (
|
{signInUpStep === SignInUpStep.Password && (
|
||||||
<SignInUpPasswordField
|
<SignInUpPasswordField
|
||||||
showErrors={showErrors}
|
showErrors={showErrors}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import styled from '@emotion/styled';
|
|||||||
import { useLingui } from '@lingui/react/macro';
|
import { useLingui } from '@lingui/react/macro';
|
||||||
import { useMemo, useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
import { useFormContext } from 'react-hook-form';
|
import { useFormContext } from 'react-hook-form';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||||
import { isDefined } from 'twenty-shared';
|
import { isDefined } from 'twenty-shared';
|
||||||
import { Loader, MainButton } from 'twenty-ui';
|
import { Loader, MainButton } from 'twenty-ui';
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ export const SignInUpWithCredentials = () => {
|
|||||||
const { t } = useLingui();
|
const { t } = useLingui();
|
||||||
const form = useFormContext<Form>();
|
const form = useFormContext<Form>();
|
||||||
|
|
||||||
const signInUpStep = useRecoilValue(signInUpStepState);
|
const [signInUpStep, setSignInUpStep] = useRecoilState(signInUpStepState);
|
||||||
const [showErrors, setShowErrors] = useState(false);
|
const [showErrors, setShowErrors] = useState(false);
|
||||||
const captcha = useRecoilValue(captchaState);
|
const captcha = useRecoilValue(captchaState);
|
||||||
const isRequestingCaptchaToken = useRecoilValue(
|
const isRequestingCaptchaToken = useRecoilValue(
|
||||||
@ -64,6 +64,12 @@ export const SignInUpWithCredentials = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onEmailChange = (email: string) => {
|
||||||
|
if (email !== form.getValues('email')) {
|
||||||
|
setSignInUpStep(SignInUpStep.Email);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const buttonTitle = useMemo(() => {
|
const buttonTitle = useMemo(() => {
|
||||||
if (signInUpStep === SignInUpStep.Init) {
|
if (signInUpStep === SignInUpStep.Init) {
|
||||||
return t`Continue with Email`;
|
return t`Continue with Email`;
|
||||||
@ -114,7 +120,10 @@ export const SignInUpWithCredentials = () => {
|
|||||||
signInUpStep === SignInUpStep.Init) && (
|
signInUpStep === SignInUpStep.Init) && (
|
||||||
<StyledForm onSubmit={handleSubmit}>
|
<StyledForm onSubmit={handleSubmit}>
|
||||||
{signInUpStep !== SignInUpStep.Init && (
|
{signInUpStep !== SignInUpStep.Init && (
|
||||||
<SignInUpEmailField showErrors={showErrors} />
|
<SignInUpEmailField
|
||||||
|
showErrors={showErrors}
|
||||||
|
onInputChange={onEmailChange}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{signInUpStep === SignInUpStep.Password && (
|
{signInUpStep === SignInUpStep.Password && (
|
||||||
<SignInUpPasswordField
|
<SignInUpPasswordField
|
||||||
|
|||||||
Reference in New Issue
Block a user