import React, { useState, useRef, useEffect } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { LoadingButton } from '@material-ui/lab'; import { useCookies } from 'react-cookie'; import Alert from '../../../component/alert'; const ChildLogin = () => { const location = useLocation(); const [cookies, setCookie] = useCookies(['auth']); const [submit, setSubmit] = useState(false); const [tel, setTel] = useState(''); const [password, setPassword] = useState(''); const [remember_token, setRememberToken] = useState(false); const [_422errors, set422Errors] = useState({tel: '', password: ''}); const [_400error, set400Error] = useState(''); const isMountedRef = useRef(true); useEffect(() => { isMountedRef.current = false; axios.post('/api/children/checkSession').then(response => { if (isMountedRef.current) return; switch (response.data.status_code) { case 200: { if(location.search == '') window.location.href = "/c-account/meeting"; else window.location.href = location.search.replace('?redirect_to=', ''); break; } default: break; } }); return () => { isMountedRef.current = true; } }, []) const loginOK = (id = 0, expires) =>{ let token = { type: 'c-account', id: id, notice: 0, from_login: true, expires: expires }; // setCookie('token', token, {expires: new Date(expires).toUTCString(), path: '/c-account'}); localStorage.setItem('c-account_token', JSON.stringify(token)); localStorage.setItem('child_id', id); if(location.search == '') window.location.href = "/c-account/meeting"; else window.location.href = location.search.replace('?redirect_to=', ''); } const handleSubmit = (e) => { e.preventDefault(); setSubmit(true); set422Errors({tel:'', password:''}); const formdata = new FormData(); formdata.append('tel', tel); formdata.append('password', password); formdata.append('remember_token', remember_token); axios.post('/api/children/login/', formdata) .then(response => { if(isMountedRef.current) return; setSubmit(false) switch(response.data.status_code){ case 200:{ loginOK(response.data.params.id, response.data.params.expire); break; } case 400: set400Error(response.data.error_message); break; case 422: { window.scrollTo(0, 0); set422Errors(response.data.error_messages); break; } } if(response.data.status_code != 200){ setPassword(''); } }) } return (

ログイン

setTel(e.target.value)} autoFocus/> { _422errors.tel && { _422errors.tel } }
setPassword(e.target.value)}/> { _422errors.password && { _422errors.password } }
ログイン
パスワード紛失の方はコチラ
{ _400error && set400Error(null)}>{_400error} }
) } export default ChildLogin;