- Remove onBack from stepOne
- Set step to 0 index
This commit is contained in:
1 parent
7a57d2734a
commit
76bfb7717a
1 file changed
+8
-8
@@ -29,7 +29,7 @@ const DEMO = import.meta.env.VITE_APP_DEMO;
|
|||||||
* @param {Function} props.onBack - Callback function to handle "Back" button click.
|
* @param {Function} props.onBack - Callback function to handle "Back" button click.
|
||||||
* @returns {JSX.Element}
|
* @returns {JSX.Element}
|
||||||
*/
|
*/
|
||||||
const StepOne = ({ form, errors, onSubmit, onChange, onBack }) => {
|
const StepOne = ({ form, errors, onSubmit, onChange }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const inputRef = useRef(null);
|
const inputRef = useRef(null);
|
||||||
|
|
||||||
@@ -271,7 +271,7 @@ const Login = () => {
|
|||||||
password: DEMO !== undefined ? "Demouser1!" : "",
|
password: DEMO !== undefined ? "Demouser1!" : "",
|
||||||
});
|
});
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
const [step, setStep] = useState(1);
|
const [step, setStep] = useState(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (authToken) {
|
if (authToken) {
|
||||||
@@ -311,7 +311,7 @@ const Login = () => {
|
|||||||
const handleSubmit = async (event) => {
|
const handleSubmit = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if (step === 1) {
|
if (step === 0) {
|
||||||
const { error } = credentials.validate(
|
const { error } = credentials.validate(
|
||||||
{ email: form.email },
|
{ email: form.email },
|
||||||
{ abortEarly: false }
|
{ abortEarly: false }
|
||||||
@@ -320,9 +320,9 @@ const Login = () => {
|
|||||||
setErrors((prev) => ({ ...prev, email: error.details[0].message }));
|
setErrors((prev) => ({ ...prev, email: error.details[0].message }));
|
||||||
createToast({ body: error.details[0].message });
|
createToast({ body: error.details[0].message });
|
||||||
} else {
|
} else {
|
||||||
setStep(2);
|
setStep(1);
|
||||||
}
|
}
|
||||||
} else if (step === 2) {
|
} else if (step === 1) {
|
||||||
const { error } = credentials.validate(form, { abortEarly: false });
|
const { error } = credentials.validate(form, { abortEarly: false });
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -420,7 +420,7 @@ const Login = () => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{step === 1 ? (
|
{step === 0 ? (
|
||||||
<StepOne
|
<StepOne
|
||||||
form={form}
|
form={form}
|
||||||
errors={errors}
|
errors={errors}
|
||||||
@@ -428,13 +428,13 @@ const Login = () => {
|
|||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
step === 2 && (
|
step === 1 && (
|
||||||
<StepTwo
|
<StepTwo
|
||||||
form={form}
|
form={form}
|
||||||
errors={errors}
|
errors={errors}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
onBack={() => setStep(1)}
|
onBack={() => setStep(0)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in new issue
Block a user