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

202 行
8.8 KiB
React
Raw 通常表示 履歴

2021-10-10 18:24:19 +09:00
import React, { useEffect, useState } from 'react';
2021-10-24 02:20:26 +09:00
import { useHistory, Link } from 'react-router-dom';
2021-10-10 18:24:19 +09:00
import axios from 'axios';
2021-10-24 02:20:26 +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-24 02:20:26 +09:00
import Alert from '../../component/alert';
2021-11-15 16:56:22 +09:00
import ModalConfirm from '../../component/modal_confirm';
2021-10-24 02:20:26 +09:00
const Transition = React.forwardRef(function Transition(props, ref) {
return <Slide direction="up" ref={ref} {...props} />;
});
const ParentDetail = (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-24 02:20:26 +09:00
const [loaded, setLoaded] = useState(false);
const [submit, setSubmit] = useState(false);
const [submit_image, setSubmitImage] = useState(false);
2021-10-24 02:20:26 +09:00
const [parent, setParent] = useState(null);
2021-11-18 11:04:35 +09:00
2021-10-24 02:20:26 +09:00
const [_400error, set400Error] = useState('');
const [_422errors, set422Errors] = useState({image: ''});
2021-11-18 11:04:35 +09:00
const [_success, setSuccess] = useState(props.history.location.state);
const [show_confirm_modal, setShowConfirmModal] = useState(false);
2021-10-10 18:24:19 +09:00
2021-11-15 17:50:40 +09:00
useEffect(() => {
setLoaded(false);
axios.get(`/api/admin/fathers/detail/${props.match.params?.father_id}`)
.then(response => {
setLoaded(true);
if(response.data.status_code==200){
setParent(response.data.params);
setImage(response.data.params.image);
}
2021-11-18 11:04:35 +09:00
else{
2021-11-18 17:33:59 +09:00
set400Error("失敗しました。");
2021-11-18 11:04:35 +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);
2021-10-24 04:08:44 +09:00
axios.put(`/api/admin/fathers/updateImage/${props.match.params?.father_id}`, {image: reader.result})
2021-10-24 02:20:26 +09:00
.then(response => {
setSubmitImage(false);
2021-10-24 02:20:26 +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 02:20:26 +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-24 02:20:26 +09:00
2021-11-15 16:56:22 +09:00
async function handleAcceptDelete() {
2021-11-18 11:04:35 +09:00
setSubmit(true);
axios.delete(`/api/admin/fathers/delete/${props.match.params?.father_id}`)
.then(response => {
setShowConfirmModal(false);
setSubmit(false);
if(response.data.status_code == 200){
history.push({
pathname: "/admin/parent",
state: '削除に成功しました!'});
} else {
set400Error("削除に失敗しました。");
}
});
2021-10-24 02:20:26 +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-24 02:20:26 +09:00
{
(!loaded || submit_image) &&
2021-11-18 11:04:35 +09:00
<CircularProgress className="css-loader"/>
2021-10-24 02:20:26 +09:00
}
{
2021-11-18 18:44:21 +09:00
loaded && parent &&
<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>
}
</div>
<p className="profile-name">{parent.company}</p>
<div className="profile-info">
2021-12-14 17:11:16 +09:00
<div className="profile-info__item">
<p className="profile-info__icon">
<img src="/assets/img/icon/people-gray.svg" alt="People"/>
</p>
<p className="txt">{`${parent.limit}`}</p>
</div>
2021-11-18 18:44:21 +09:00
<div className="profile-info__item">
<a href={`mailto:${parent.email}`}>
<p className="profile-info__icon">
<img src="/assets/img/icon/mail.svg" alt="メール"/>
</p>
<p className="txt">{parent.email}</p>
</a>
2021-10-24 02:20:26 +09:00
</div>
2021-11-18 18:44:21 +09:00
<div className="profile-info__item">
<a href={`tel:${parent.tel}`}>
<p className="profile-info__icon">
<img src="/assets/img/icon/phone.svg" alt="電話" />
</p>
<p className="txt">{parent.tel}</p>
2021-10-24 02:20:26 +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="txt">{parent.profile ? parent.profile: '未入力'}</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"
to = {`/admin/parent/edit/${props.match.params?.father_id}`}
>
<span className="ft-18 ft-xs-16">プロフィールを変更する</span>
</Link>
</div>
<div className="p-profile-btn">
<Link className="btn-default btn-yellow btn-password btn-r8 btn-h52"
to = {`/admin/parent/edit/password/${props.match.params?.father_id}`}
>
<span className="ft-18 ft-xs-16">パスワードを変更する</span>
</Link>
</div>
<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-24 02:20:26 +09:00
}
2021-10-10 18:24:19 +09:00
</div>
</section>
</div>
</div>
2021-11-15 16:56:22 +09:00
<ModalConfirm
2021-11-18 11:04:35 +09:00
show={show_confirm_modal}
2021-11-15 16:56:22 +09:00
message={"本当に削除しても\nよろしいでしょうか?"}
2021-11-18 11:04:35 +09:00
handleClose={()=>setShowConfirmModal(false)}
2021-11-15 16:56:22 +09:00
handleAccept={handleAcceptDelete}
loading={submit}
/>
2021-11-18 11:04:35 +09:00
{ _400error && <Alert type="fail" hide={()=>set400Error('')}> {_400error} </Alert> }
{ _success && <Alert type="success" hide={()=>setSuccess('')}> {_success} </Alert> }
2021-10-10 18:24:19 +09:00
</div>
)
}
export default ParentDetail;