このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
kikikan/backend/resources/js/admin/login/index.jsx

102 行
4.2 KiB
React
Raw 通常表示 履歴

2021-10-07 04:52:20 +09:00
import React, { useState } from 'react';
2021-10-09 05:15:18 +09:00
import ReactDOM from 'react-dom';
2021-10-07 04:52:20 +09:00
import { Button } from '@material-ui/core';
import axios from 'axios';
import { CircularProgress } from '@material-ui/core';
2021-10-09 05:15:18 +09:00
const AdminLogin = () => {
2021-10-07 04:52:20 +09:00
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [loading, setLoading] = useState(false);
const [_422errors, set422Errors] = useState({ email:'', password:'' })
const [_400error, set400Error] = useState('');
const handleSubmit = (e) => {
e.preventDefault();
setLoading(true); //show progressbar
const formdata = new FormData();
formdata.append('email', email);
formdata.append('password', password);
axios.post('/api/admin/login', formdata)
.then(response => {
if(response.data.status_code == 200){
window.location.href = '';
}
else if(response.data.status_code == 422){
set422Errors(response.data.error_messages);
}
else if(response.data.status_code == 400){
set400Error(response.data.error_messages);
}
setLoading(false)
})
.catch(err=>console.log(err))
}
return (
2021-10-18 18:15:53 +09:00
<main className="l-single-main">
<div className="l-centeringbox">
<div className="l-centeringbox-wrap">
<div className="l-single-container">
<div className="l-single-inner">
<form onSubmit={handleSubmit} noValidate>
<h1 className="text-center font-weight-bold ft-25 pb-40-px">管理者ログイン</h1>
{
_400error.length != 0 &&
<span className="l-alert__text--error ft-16 ft-md-14">{_400error}</span>
}
<div className="edit-set">
<label htmlFor="email" className="control-label ft-md-12">メールアドレス</label>
<input type="email" name="email" id="email" className={`input-default ${ _422errors.email && "is-invalid c-input__target" } `} value={email} onChange={e=>setEmail(e.target.value)} autoFocus/>
{
_422errors.email &&
<span className="l-alert__text--error ft-16 ft-md-14">
{_422errors.email}
</span>
}
</div>
2021-10-07 04:52:20 +09:00
2021-10-18 18:15:53 +09:00
<div className="edit-set">
<label htmlFor="password" className="control-label ft-14 ft-md-12"> パスワード </label>
<input type="password" name="password" id="password" className={`input-default ${ _422errors.password && "is-invalid c-input__target" }`} value={password} onChange={e=>setPassword(e.target.value)} autoFocus/>
{
_422errors.password &&
<span className="l-alert__text--error ft-16 ft-md-14">
{_422errors.password}
</span>
}
</div>
2021-10-07 04:52:20 +09:00
2021-10-18 18:15:53 +09:00
<div className="mt-5">
<Button type="submit" fullWidth className="p-4 rounded-20 ft-15 font-weight-bold text-black bg-color-2"> ログイン </Button>
</div>
2021-10-07 04:52:20 +09:00
2021-10-18 18:15:53 +09:00
{
loading && <div style={{position: 'fixed', left: 'calc( 50% - 20px)', top:'45%'}}> <CircularProgress /></div>
}
</form>
</div>
</div>
</div>
</div>
</main>
2021-10-07 04:52:20 +09:00
)
}
2021-10-09 05:15:18 +09:00
// ----------------------------------------------------------------------
if(document.getElementById('admin-login')){
ReactDOM.render(
<AdminLogin />,
document.getElementById('admin-login')
)
}