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

245 行
10 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';
import moment from 'moment';
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";
import Alert from '../../component/alert';
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';
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-23 19:00:14 +09:00
const [image, setImage] = useState('/assets/img/avatar/avatar-sample03@2x.png');
const [open, setOpen] = useState(false);
const [loaded, setLoaded] = useState(false);
const [submit, setSubmit] = useState(false);
const [child, setChild] = useState(null);
const [_400error, set400Error] = useState('');
const [_success, setSuccess] = 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);
if(response.data.status_code==200)
{
setChild(response.data.params[0]);
console.log(response.data.params[0]);
}
})
.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 = () => {
setImage(reader.result);
};
};
2021-10-23 19:00:14 +09:00
async function openModal() {
setOpen(true);
};
async function closeModal() {
setOpen(false);
};
async function handleAccept() {
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){
setSuccess('削除に成功しました!');
} 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'>
<IconButton color="primary" aria-label="upload picture" component="span" className="bg-color-2 shadow-sm w-40-px h-40-px">
<img src="/assets/img/icon/camera.svg" width="20" height="20"/>
</IconButton>
</label>
{
image &&
<img src={image} alt="" width ="100%" height="100%" style={{borderRadius:'50%'}}/>
}
</div>
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-23 19:00:14 +09:00
<p className="txt">
{/* {child.username} */}
Chankan77
</p>
</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'}}>
<Button
onClick={closeModal}
size="large"
style={{fontSize:'20px'}}>いいえ</Button>
<LoadingButton
variant="text"
onClick={handleAccept}
loading={submit}
size="large"
style={{fontSize:'20px'}}>はい</LoadingButton>
</DialogActions>
</Dialog>
{
_400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert>
}
{
_success &&
<Alert type="success"
hide={()=>
history.push({
pathname: "/admin/child",
state: {}
})}>{_success}</Alert>
}
2021-10-10 18:24:19 +09:00
</div>
)
}
export default ChildDetail;