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

185 行
9.0 KiB
React
Raw 通常表示 履歴

2021-11-09 16:53:39 +09:00
import React, { useEffect, useState } from 'react';
import { useHistory, Link } from 'react-router-dom';
import IconButton from "@material-ui/core/IconButton";
import axios from 'axios';
import { CircularProgress } from '@material-ui/core';
import PhotoCameraOutlinedIcon from '@mui/icons-material/PhotoCameraOutlined';
import Alert from '../../component/alert';
2021-11-10 21:51:53 +09:00
import Notification from '../notification';
2021-11-09 16:53:39 +09:00
2021-11-18 12:14:22 +09:00
const Profile = (props) => {
2021-11-09 16:53:39 +09:00
2021-11-14 21:41:33 +09:00
const [notice, setNotice] = useState(localStorage.getItem('notice'));
2021-11-11 14:33:17 +09:00
2021-11-09 16:53:39 +09:00
const [image, setImage] = useState('');
2021-11-18 18:44:21 +09:00
const [profile, setProfile] = useState(null)
2021-11-09 16:53:39 +09:00
const [loaded, setLoaded] = useState(false);
const [_400error, set400Error] = useState('');
const [_422errors, set422Errors] = useState({ image: '' });
2021-11-18 12:14:22 +09:00
const [_success, setSuccess] = useState(props.history.location.state);
2021-11-09 16:53:39 +09:00
2021-11-11 14:33:17 +09:00
2021-11-09 16:53:39 +09:00
useEffect(() => {
setLoaded(false);
let child_id = document.getElementById('child_id').value;
axios.get('/api/children/detail/'+child_id)
.then(response => {
setLoaded(true);
2021-11-14 21:41:33 +09:00
setNotice(response.data.notice);
2021-11-09 16:53:39 +09:00
if(response.data.status_code==200){
setProfile(response.data.params);
setImage(response.data.params.image);
}
2021-11-18 18:44:21 +09:00
else {
set400Error("失敗しました。");
}
2021-11-09 16:53:39 +09:00
})
},[]);
2021-11-18 07:07:18 +09:00
useEffect(() => {
if(localStorage.getItem('image_upload_success')){
setSuccess(localStorage.getItem('image_upload_success'));
localStorage.removeItem('image_upload_success');
}
})
2021-11-09 16:53:39 +09:00
const handleLogout = () => {
axios.get('/c-account/logout')
.then(() => location.href = '/c-account/login')
}
const handleImageChange = (e) => {
e.preventDefault();
set422Errors({image: ''});
let reader = new FileReader();
let _file = e.target.files[0];
reader.readAsDataURL(_file);
reader.onloadend = () => {
axios.put(`/api/children/updateImage/${document.getElementById('child_id').value}`, {image: reader.result})
.then(response => {
2021-11-14 21:41:33 +09:00
setNotice(response.data.notice);
2021-11-09 16:53:39 +09:00
switch(response.data.status_code){
case 200: {
2021-11-18 07:07:18 +09:00
localStorage.setItem('image_upload_success', response.data.success_messages);
2021-11-12 18:10:44 +09:00
window.location.reload(true);
2021-11-09 16:53:39 +09:00
break;
}
case 400: set400Error(response.data.error_messages); break;
case 422: set422Errors(response.data.error_messages); break;
}
});
};
};
return (
<div className="l-content">
<div className="l-content-w560">
<div className="l-content__ttl">
<div className="l-content__ttl__left">
<h2>プロフィール</h2>
</div>
2021-11-11 14:33:17 +09:00
<Notification notice={notice}/>
2021-11-09 16:53:39 +09:00
</div>
<div className="l-content-wrap">
<section className="profile-container">
{
!loaded &&
2021-11-17 08:13:17 +09:00
<CircularProgress className="css-loader"/>
2021-11-09 16:53:39 +09:00
}
{
2021-11-18 18:44:21 +09:00
loaded && profile &&
2021-11-09 16:53:39 +09:00
<div className="profile-wrap">
<div className="profile-content">
<div>
<input type="file" id="avatar" name="avatar" className="d-none" accept=".png, .jpg, .jpeg" onChange={(e) => handleImageChange(e)}/>
<div className="avatar-wrapper">
<label htmlFor="avatar" className='avatar-label'>
<IconButton color="primary" aria-label="upload picture" component="span" className="bg-yellow shadow-sm w-50-px h-50-px">
<PhotoCameraOutlinedIcon style={{width:'25px', height:'25px', color:'black'}}/>
</IconButton>
</label>
<img src={image} className="avatar-img" alt="avatar-img"/>
</div>
{
_422errors.image &&
<span className="l-alert__text--error ft-16 ft-md-14">
{_422errors.image}
</span>
}
</div>
2021-11-18 12:14:22 +09:00
<p className="profile-name">{`${profile.first_name} ${profile.last_name}`}</p>
<div className="profile-info">
2021-11-09 16:53:39 +09:00
<div className="profile-info__item">
<p className="profile-info__icon">
<img src="/assets/img/icon/person-pin.svg" alt="person"/>
</p>
<p className="txt">{profile.identity}</p>
</div>
<div className="profile-info__item">
<a href={`mailto:${profile.email}`}>
<p className="profile-info__icon">
<img src="/assets/img/icon/mail.svg" alt="メール"/>
</p>
<p className="txt">{profile.email}</p>
</a>
</div>
<div className="profile-info__item">
<a href={`tel:${profile.tel}`}>
<p className="profile-info__icon">
<img src="/assets/img/icon/phone.svg" alt="電話" />
</p>
<p className="txt">{profile.tel}</p>
</a>
</div>
<div className="profile-info__item">
<p className="profile-info__icon">
<img src="/assets/img/icon/building.svg" alt="会社名"/>
</p>
2021-11-17 23:56:11 +09:00
<p className="txt">{profile.company ? profile.company: '未入力'}</p>
2021-11-09 16:53:39 +09:00
</div>
</div>
<div className="p-profile-btn">
<Link to={`/c-account/profile/edit/${document.getElementById('child_id').value}`}
2021-11-18 12:51:24 +09:00
className="btn-default btn-yellow btn-profile btn-r8 btn-h52">
2021-11-09 16:53:39 +09:00
<span className="ft-xs-16">プロフィールを変更する</span>
</Link>
</div>
<div className="p-profile-btn">
<Link to={`/c-account/profile/password-edit/${document.getElementById('child_id').value}`}
2021-11-18 12:51:24 +09:00
className="btn-default btn-yellow btn-password btn-r8 btn-h52">
2021-11-09 16:53:39 +09:00
<span className="ft-xs-16">パスワードを変更する</span>
</Link>
</div>
<div className="p-profile-txtLink">
2021-11-18 16:38:41 +09:00
<a className="btn-default btn-password btn-r8 btn-h30"
onClick={handleLogout}
>
2021-11-09 16:53:39 +09:00
<span className="ft-xs-16">ログアウト</span>
</a>
</div>
<div className="p-profile-txtLink">
2021-11-18 16:38:41 +09:00
<Link to="/c-account/profile/withdrawal"
className="btn-default btn-password btn-r8 btn-h30"
>
2021-11-09 16:53:39 +09:00
<span className="ft-xs-16">退会する</span>
</Link>
</div>
</div>
</div>
}
2021-11-18 07:07:18 +09:00
{ _400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert> }
{ _success && <Alert type="success" hide={()=>setSuccess('')}>{_success}</Alert> }
2021-11-09 16:53:39 +09:00
</section>
</div>
</div>
</div>
)
}
export default Profile;