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

262 行
11 KiB
React
Raw 通常表示 履歴

2021-10-10 18:24:19 +09:00
import React, { useEffect, useState } from 'react';
2021-10-23 19:00:14 +09:00
import { useHistory, Link } from 'react-router-dom';
2021-10-10 18:24:19 +09:00
import axios from 'axios';
2021-10-23 19:00:14 +09:00
import { LoadingButton } from '@material-ui/lab';
import { CircularProgress } from '@material-ui/core';
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
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import Slide from '@mui/material/Slide';
2021-10-24 01:19:37 +09:00
import Alert from '../../component/alert';
2021-10-23 19:00:14 +09:00
const Transition = React.forwardRef(function Transition(props, ref) {
return <Slide direction="up" ref={ref} {...props} />;
});
const ChildDetail = (props) => {
2021-10-10 18:24:19 +09:00
const history = useHistory();
2021-10-29 20:27:22 +09:00
const [image, setImage] = useState('');
2021-10-23 19:00:14 +09:00
const [open, setOpen] = useState(false);
const [loaded, setLoaded] = useState(false);
const [submit, setSubmit] = useState(false);
const [child, setChild] = useState(null);
const [_400error, set400Error] = useState('');
2021-10-24 02:20:26 +09:00
const [_422errors, set422Errors] = useState({ image: '' });
2021-10-29 20:27:22 +09:00
const [_success_delete, setSuccessDelete] = useState('');
const [_success_update_image, setSuccessUpdateImage] = useState('');
2021-10-10 18:24:19 +09:00
useEffect(
() => {
2021-10-23 19:00:14 +09:00
setLoaded(false);
axios.get(`/api/admin/children/detail/${props.match.params?.child_id}`)
.then(response => {
setLoaded(true);
2021-10-24 01:19:37 +09:00
if(response.data.status_code==200){
2021-10-29 17:37:38 +09:00
setChild(response.data.params);
2021-10-29 20:27:22 +09:00
setImage(response.data.params.image);
2021-10-23 19:00:14 +09:00
}
})
.catch(err=>console.log(err))
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 = () => {
2021-10-24 00:13:32 +09:00
2021-10-24 04:08:44 +09:00
axios.put(`/api/admin/children/updateImage/${props.match.params?.child_id}`, {image: reader.result})
2021-10-24 00:13:32 +09:00
.then(response => {
switch(response.data.status_code){
case 200: {
setImage(reader.result);
2021-10-29 20:27:22 +09:00
setSuccessUpdateImage(response.data.success_messages);
2021-10-24 00:13:32 +09:00
break;
}
case 400: set400Error(response.data.error_messages); break;
case 422: set422Errors(response.data.error_messages); break;
}
});
2021-10-10 18:24:19 +09:00
};
};
2021-10-23 19:00:14 +09:00
async function openModal() {
setOpen(true);
};
async function closeModal() {
setOpen(false);
};
2021-10-29 20:27:22 +09:00
async function handleDelete() {
2021-10-23 19:00:14 +09:00
try {
setSubmit(true);
axios.delete(`/api/admin/children/delete/${props.match.params?.child_id}`)
.then(response => {
closeModal();
setSubmit(false);
if(response.data.status_code == 200){
2021-10-29 20:27:22 +09:00
setSuccessDelete('削除に成功しました!');
2021-10-23 19:00:14 +09:00
} else {
set400Error("削除に失敗しました。");
}
});
} catch (error) {
console.log('error', error);
}
};
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-10-23 19:00:14 +09:00
<div className="profile-wrap position-relative" style={{ minHeight:'500px'}}>
{
!loaded &&
<CircularProgress color="secondary" style={{top:'30%', left:'calc(50% - 22px)', color:'green', position:'absolute'}}/>
}
{
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'>
2021-10-28 13:38:45 +09:00
<IconButton color="primary" aria-label="upload picture" component="span" className="bg-yellow shadow-sm w-50-px h-50-px">
2021-10-24 18:42:54 +09:00
<PhotoCameraOutlinedIcon style={{width:'25px', height:'25px', color:'black'}}/>
{/* <img src="/assets/img/icon/camera.svg" width="20" height="20"/> */}
2021-10-23 19:00:14 +09:00
</IconButton>
2021-10-24 00:13:32 +09:00
</label>
2021-11-01 21:59:30 +09:00
<img src={image} className="avatar-img" alt="avatar-img"/>
2021-10-23 19:00:14 +09:00
</div>
2021-10-24 00:13:32 +09:00
{
_422errors.image &&
<span className="l-alert__text--error ft-16 ft-md-14">
{_422errors.image}
</span>
}
2021-10-10 18:24:19 +09:00
</div>
2021-10-23 19:00:14 +09:00
<p className="profile-name ft-xs-14">{`${child.first_name} ${child.last_name}`}</p>
<div className="profile-info ft-xs-14">
<div className="profile-info__item">
2021-10-10 18:24:19 +09:00
<p className="profile-info__icon">
2021-10-23 19:00:14 +09:00
<img src="/assets/img/icon/person-pin.svg" alt="Person"/>
2021-10-10 18:24:19 +09:00
</p>
2021-10-29 21:49:12 +09:00
<p className="txt">{child.identity}</p>
2021-10-23 19:00:14 +09:00
</div>
<div className="profile-info__item">
<a href={`mailto:${child.email}`}>
<p className="profile-info__icon">
<img src="/assets/img/icon/mail.svg" alt="メール"/>
</p>
<p className="txt">{child.email}</p>
</a>
</div>
<div className="profile-info__item">
<a href={`tel:${child.tel}`}>
<p className="profile-info__icon">
<img src="/assets/img/icon/phone.svg" alt="電話" />
</p>
<p className="txt">{child.tel}</p>
</a>
</div>
<div className="profile-info__item">
2021-10-10 18:24:19 +09:00
<p className="profile-info__icon">
2021-10-23 19:00:14 +09:00
<img src="/assets/img/icon/building.svg" alt="会社名"/>
2021-10-10 18:24:19 +09:00
</p>
2021-10-23 19:00:14 +09:00
<p className="txt">{child.company}</p>
</div>
2021-10-10 18:24:19 +09:00
</div>
2021-10-23 19:00:14 +09:00
<div className="p-profile-btn">
<Link className="btn-default btn-yellow btn-profile btn-r8 btn-h52 h-xs-45-px"
to = {`/admin/child/edit/${props.match.params?.child_id}`}
>
<span className="ft-18 ft-xs-14">プロフィールを変更する</span>
</Link>
</div>
<div className="p-profile-btn">
<Link className="btn-default btn-yellow btn-password btn-r8 btn-h52 h-xs-45-px"
to = {`/admin/child/edit/password/${props.match.params?.child_id}`}
>
<span className="ft-18 ft-xs-14">パスワードを変更する</span>
</Link>
</div>
<div className="p-profile-txtLink">
<a className="btn-default btn-password btn-r8 btn-h52 h-xs-45-px"
onClick={openModal}
>
<span className="ft-xs-14">削除する</span>
</a>
2021-10-10 18:24:19 +09:00
</div>
</div>
2021-10-23 19:00:14 +09:00
: <p className="text-center py-5">データが存在していません</p>
)
}
2021-10-10 18:24:19 +09:00
</div>
</section>
</div>
</div>
2021-10-23 19:00:14 +09:00
<Dialog
open={open}
TransitionComponent={Transition}
keepMounted
aria-describedby="alert-dialog-slide-description"
>
<DialogContent style={{width:'290px', padding:'25px 25px 10px'}}>
<DialogContentText id="alert-dialog-slide-description" style={{fontSize:'20px', textAlign:'center'}}>
本当に削除してもよろしいでしょうか
</DialogContentText>
</DialogContent>
<DialogActions style={{justifyContent:'space-evenly', padding:'0 20px 20px 20px'}}>
2021-10-26 10:25:58 +09:00
<Button onClick={closeModal} size="small">
2021-10-26 09:44:31 +09:00
<span className="ft-20 text-black">いいえ</span>
</Button>
2021-10-26 10:25:58 +09:00
<LoadingButton variant="text"
2021-10-29 20:27:22 +09:00
onClick={handleDelete}
2021-10-26 10:25:58 +09:00
loading={submit}
size="small">
2021-10-26 09:44:31 +09:00
<span className={`ft-20 ${!submit && 'text-black'}`}>はい</span>
</LoadingButton>
2021-10-23 19:00:14 +09:00
</DialogActions>
</Dialog>
{
2021-10-24 00:13:32 +09:00
_400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert>
2021-10-23 19:00:14 +09:00
}
{
2021-10-29 20:27:22 +09:00
_success_delete &&
2021-10-23 19:00:14 +09:00
<Alert type="success"
2021-10-29 20:27:22 +09:00
hide={()=>
history.push({
pathname: "/admin/child",
state: {}
})}>{_success_delete}</Alert>
}
{ _success_update_image &&
<Alert type="success" hide={()=>setSuccessUpdateImage('')}>
{_success_update_image}
</Alert>
2021-10-23 19:00:14 +09:00
}
2021-10-10 18:24:19 +09:00
</div>
)
}
export default ChildDetail;