import React, { useState } from "react"; import Form from "react-bootstrap/Form"; import Button from "react-bootstrap/Button"; import { useSelector, useDispatch } from "react-redux"; import { errorOccured, loadingStarted } from "../features/user/userSlice"; import { signInUser } from "../backend/backend"; const Login = (props) => { const { onClickForgottenPswd } = props; const [state, setState] = useState({ email: "", password: "" }); // onChange function const handleChange = (e) => { const newState = { ...state }; newState[e.target.name] = e.target.value; setState(newState); dispatch(errorOccured("")); }; const errorMsg = useSelector((state) => state.user.error); const dispatch = useDispatch(); // Submit function (Create account) const handleSubmit = (e) => { e.preventDefault(); e.stopPropagation(); if (state.email === "") { dispatch(errorOccured("Email is required.")); return; } else if (state.password === "") { dispatch(errorOccured("Password is required.")); return; } dispatch(loadingStarted()); signInUser(state); }; return ( <>