import React, { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { useSelector, useDispatch } from "react-redux"; import { userConstants, configConstants, alertConstants, } from "../../../_constants"; import { alertActions } from "../../../_actions"; // import SocialLogin from "../../../_components/SocialLogin"; import { Alert } from "../../../_components/Alert"; // import from "../../../_components/Input"; import "./Login.scss"; import InputText from "../../../_components/Auth/InputText"; import { isEmail } from "../../../_helpers/validateEmail"; import GoogleLogin from "react-google-login"; // import FacebookLogin from "react-facebook-login/dist/facebook-login-render-props"; import AppleLogin from "react-apple-login"; import { apiCaller, history } from "../../../_helpers"; import classNames from "classnames"; import SocialLogin from "../../../_components/Auth/SocialLogin"; import { PopUpYesNo } from "../../../_components/Popup"; function Login(props) { const alert = useSelector((state) => state.alert); const dispatch = useDispatch(); const [dataResetEmail, setDataResetEmail] = useState({ loading: false, msg: "Gửi lại email kích hoạt khác", }); const [savePassword, setSavePassword] = useState( localStorage.getItem("save_pw") === "true" ); // fb const [isProcessingFb, setIsProcessingFb] = useState(false); const registerStatus = useSelector( (state) => state.authenticationTeacherZalo.registerStatus ); const { email, setEmail, password, setPassword, emailError, setEmailError, pwError, setPwError, handleSubmit, // onLoginFacebookSuccess, onLoginGoogleSuccess, onLoginAppleSuccess, validateParam, } = props; useEffect(() => { dispatch({ type: userConstants.RESET_REGISTER_STATUS }); dispatch({ type: userConstants.RESET_LOGIN_WHEN_NOT_VERIFY }); }, []); const changeEmail = (value) => { if (alert.message && alert.screen === userConstants.SCREEN_LOGIN) { dispatch(alertActions.clear()); } if (emailError) { if (isEmail(value)) { setEmailError(""); } } setEmail(value.trim()); }; const changePassword = (value) => { setPwError(""); if (alert.message && alert.screen === userConstants.SCREEN_LOGIN) { dispatch(alertActions.clear()); } if (pwError) { if (value.length >= 6) { setPwError(""); } } setPassword(value); }; const onBlurField = (type) => { switch (type) { case "email": { if (email && !emailError && !isEmail(email)) { setEmailError("Định dạng email không đúng"); } return; } default: { if (password.trim() === "" && !pwError) { setPwError( "Mật khẩu cần tối thiểu 6 kí tự và không gồm toàn dấu cách" ); } if (password && !pwError && password.length < 6) { setPwError("Mật khẩu phải có từ 6 ký tự trở lên"); } return; } } }; const renderEmailIcon = () => { return ( ); }; const renderPasswordIcon = () => { return ( ); }; const resentEmail = () => { if (!dataResetEmail.loading) { setDataResetEmail({ loading: true, msg: "Đang gửi...", }); apiCaller(`/api_register/resend_active_email?email=${email}`) .then((res) => { if (res.status) { setDataResetEmail({ loading: true, msg: "Gửi email xác nhận thành công", }); setTimeout(() => { dispatch(alertActions.clear()); setDataResetEmail({ loading: false, msg: "Gửi lại email kích hoạt khác", }); }, 5000); } else { setDataResetEmail({ loading: true, msg: "Gửi email xác nhận thất bại", }); setTimeout(() => { setDataResetEmail({ loading: false, msg: "Gửi lại email kích hoạt khác", }); }, 3000); } }) .catch((e) => { setDataResetEmail({ loading: true, msg: "Gửi email xác nhận thất bại", }); setTimeout(() => { setDataResetEmail({ loading: false, msg: "Gửi lại email kích hoạt khác", }); }, 3000); }); } }; const rememberPassword = (e) => { const checked = e.target.checked; setSavePassword(checked); localStorage.setItem("save_pw", checked); }; function setNodeRef(provider, node) { if (node) { // nodes[provider] = node; } } const handleToVerify = () => { const data = { phone: "", email: email, }; dispatch({ type: userConstants.LOGIN_WHEN_NOT_VERIFY }); history.push(`/register/authentication`, { data: data }); dispatch({ type: userConstants.RESET_REGISTER_STATUS }); }; return (
Đăng ký tài khoản