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

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

2021-12-18 16:05:52 +09:00
import React, { useRef, useEffect, useState } from 'react';
2022-01-05 02:47:36 +09:00
import { useNavigate, Link, useLocation, useParams } from 'react-router-dom';
2021-10-10 18:24:19 +09:00
2021-10-23 19:00:14 +09:00
import IconButton from "@material-ui/core/IconButton";
2021-10-24 18:42:54 +09:00
import PhotoCameraOutlinedIcon from '@mui/icons-material/PhotoCameraOutlined';
2021-10-23 19:00:14 +09:00
2021-10-24 01:19:37 +09:00
import Alert from '../../component/alert';
2021-12-22 05:32:06 +09:00
import PageLoader from '../../component/page_loader';
2021-11-15 16:56:22 +09:00
import ModalConfirm from '../../component/modal_confirm';
2021-10-23 19:00:14 +09:00
2022-01-05 02:47:36 +09:00
const AdminChildDetail = () => {
2021-10-10 18:24:19 +09:00
2022-01-04 15:58:52 +09:00
const navigator = useNavigate();
2022-01-04 17:44:38 +09:00
const location = useLocation();
2022-01-05 02:47:36 +09:00
const params = useParams();
2021-10-10 18:24:19 +09:00
const [image, setImage] = useState('');
2021-10-23 19:00:14 +09:00
const [loaded, setLoaded] = useState(false);
const [submit, setSubmit] = useState(false);
const [submit_image, setSubmitImage] = useState(false);
2021-10-23 19:00:14 +09:00
const [child, setChild] = useState(null);
2021-10-23 19:00:14 +09:00
const [_400error, set400Error] = useState('');
2021-10-24 02:20:26 +09:00
const [_422errors, set422Errors] = useState({ image: '' });
2022-01-04 17:44:38 +09:00
const [_success, setSuccess] = useState(location.state);
2021-11-18 11:04:35 +09:00
const [show_confirm_modal, setShowConfirmModal] = useState(false);
2021-12-18 16:05:52 +09:00
const isMountedRef = useRef(true);
2021-12-30 13:57:05 +09:00
useEffect(async () => {
2021-12-18 16:05:52 +09:00
isMountedRef.current = false;
2021-11-15 17:50:40 +09:00
setLoaded(false);
2021-12-30 13:57:05 +09:00
2022-01-05 02:47:36 +09:00
await axios.get(`/api/admin/children/detail/${params?.child_id}`)
2021-12-30 13:57:05 +09:00
.then(response => {
setLoaded(true);
switch(response.data.status_code){
case 200:{
setChild(response.data.params);
setImage(response.data.params.image);
break;
}
case 400: set400Error('失敗しました。'); break;
2021-11-18 11:04:35 +09:00
}
2021-12-30 13:57:05 +09:00
})
2021-11-15 17:50:40 +09:00
},[]);
2021-10-10 18:24:19 +09:00
const handleImageChange = (e) => {
e.preventDefault();
let reader = new FileReader();
let _file = e.target.files[0];
reader.readAsDataURL(_file);
reader.onloadend = () => {
set422Errors({image: ''});
setSubmitImage(true);
2022-01-05 02:47:36 +09:00
axios.put(`/api/admin/children/updateImage/${params?.child_id}`, {image: reader.result})
2021-10-24 00:13:32 +09:00
.then(response => {
setSubmitImage(false);
2021-10-24 00:13:32 +09:00
switch(response.data.status_code){
case 200: {
setImage(reader.result);
2021-11-18 11:04:35 +09:00
setSuccess(response.data.success_messages);
2021-10-24 00:13:32 +09:00
break;
}
case 400: set400Error(response.data.error_messages); break;
case 422: window.scrollTo(0, 0); set422Errors(response.data.error_messages); break;
}
2021-10-24 00:13:32 +09:00
});
2021-10-10 18:24:19 +09:00
};
};
2021-10-23 19:00:14 +09:00
2021-11-15 16:56:22 +09:00
async function handleAcceptDelete() {
2021-11-18 11:04:35 +09:00
setSubmit(true);
2022-01-05 02:47:36 +09:00
axios.delete(`/api/admin/children/delete/${params?.child_id}`)
2021-11-18 11:04:35 +09:00
.then(response => {
setShowConfirmModal(false);
setSubmit(false);
switch(response.data.status_code){
case 200:{
2022-01-04 15:58:52 +09:00
navigator("/admin/child", {state: "削除に成功しました!"});
2021-11-18 11:04:35 +09:00
break;
2021-10-23 19:00:14 +09:00
}
2021-11-18 11:04:35 +09:00
case 400: set400Error("削除に失敗しました。"); break;
}
});
2021-10-23 19:00:14 +09:00
};
2021-10-10 18:24:19 +09:00
return (
<div className="l-content">
<div className="l-content-w560">
<div className="l-content__ttl">
<div className="l-content__ttl__left">
<h2>子詳細</h2>
</div>
</div>
<div className="l-content-wrap">
<section className="profile-container">
2021-11-18 12:14:22 +09:00
<div className="profile-wrap" style={{ minHeight:'500px'}}>
2021-10-23 19:00:14 +09:00
{
(!loaded || submit_image) &&
2021-12-22 05:32:06 +09:00
<PageLoader />
2021-10-23 19:00:14 +09:00
}
{
2021-11-18 18:44:21 +09:00
loaded && child &&
<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"/>
2021-10-10 18:24:19 +09:00
</div>
2021-11-18 18:44:21 +09:00
{
_422errors.image &&
<span className="l-alert__text--error ft-16 ft-md-14">
{_422errors.image}
</span>
2021-11-18 18:44:21 +09:00
}
</div>
<p className="profile-name">{`${child.last_name} ${child.first_name}`}</p>
2021-11-18 18:44:21 +09:00
<div className="profile-info">
<div className="profile-info__item">
<p className="profile-info__icon">
2021-12-25 12:06:05 +09:00
<img src="/assets/img/icon/ID.svg" alt="ID"/>
2021-11-18 18:44:21 +09:00
</p>
<p className="txt">{child.identity}</p>
</div>
<div className="profile-info__item">
<a href={`mailto:${child.email}`}>
2021-10-10 18:24:19 +09:00
<p className="profile-info__icon">
2021-11-18 18:44:21 +09:00
<img src="/assets/img/icon/mail.svg" alt="メール"/>
2021-10-10 18:24:19 +09:00
</p>
2021-11-18 18:44:21 +09:00
<p className="txt">{child.email}</p>
</a>
</div>
<div className="profile-info__item">
<a href={`tel:${child.tel}`}>
2021-10-10 18:24:19 +09:00
<p className="profile-info__icon">
2021-11-18 18:44:21 +09:00
<img src="/assets/img/icon/phone.svg" alt="電話" />
2021-10-10 18:24:19 +09:00
</p>
2021-11-18 18:44:21 +09:00
<p className="txt">{child.tel}</p>
2021-10-23 19:00:14 +09:00
</a>
2021-10-10 18:24:19 +09:00
</div>
2021-11-18 18:44:21 +09:00
<div className="profile-info__item">
<p className="profile-info__icon">
<img src="/assets/img/icon/building.svg" alt="会社名"/>
</p>
<p className="txt">{child.company ? child.company: '未入力'}</p>
2021-11-18 18:44:21 +09:00
</div>
2021-10-10 18:24:19 +09:00
</div>
2021-11-18 18:44:21 +09:00
<div className="p-profile-btn">
<Link className="btn-default btn-yellow btn-profile btn-r8 btn-h52"
2022-01-05 02:47:36 +09:00
to = {`/admin/child/edit/${params?.child_id}`}
2021-11-18 18:44:21 +09:00
>
<span className="ft-18 ft-xs-16">プロフィールを変更する</span>
</Link>
</div>
2021-11-18 18:44:21 +09:00
<div className="p-profile-btn">
<Link className="btn-default btn-yellow btn-password btn-r8 btn-h52"
2022-01-05 02:47:36 +09:00
to = {`/admin/child/edit/password/${params?.child_id}`}
2021-11-18 18:44:21 +09:00
>
<span className="ft-18 ft-xs-16">パスワードを変更する</span>
</Link>
</div>
2021-11-18 18:44:21 +09:00
<div className="p-profile-txtLink">
<a className="btn-default btn-password btn-r8 btn-h52"
onClick={()=>setShowConfirmModal(true)}
>
<span className="ft-xs-16">削除する</span>
</a>
</div>
</div>
2021-10-23 19:00:14 +09:00
}
2021-10-10 18:24:19 +09:00
</div>
</section>
2021-10-10 18:24:19 +09:00
</div>
</div>
<ModalConfirm
show={show_confirm_modal}
message={"本当に削除しても\nよろしいでしょうか?"}
handleClose={()=>setShowConfirmModal(false)}
handleAccept={handleAcceptDelete}
loading={submit}
2021-11-15 16:56:22 +09:00
/>
{ _400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert> }
2021-11-18 12:14:22 +09:00
{ _success && <Alert type="success" hide={()=>setSuccess('')}>{_success}</Alert> }
</div>
2021-10-10 18:24:19 +09:00
)
}
2021-10-31 12:26:19 +09:00
export default AdminChildDetail;