2021-10-22 09:35:32 +09:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2021-11-01 02:08:30 +09:00
|
|
|
import { useHistory } from 'react-router-dom';
|
2021-10-22 09:35:32 +09:00
|
|
|
import axios from 'axios';
|
2021-10-23 03:34:35 +09:00
|
|
|
import { CircularProgress } from '@material-ui/core';
|
2021-10-23 11:53:54 +09:00
|
|
|
import { LoadingButton } from '@material-ui/lab';
|
2021-10-24 18:32:17 +09:00
|
|
|
import IconButton from '@mui/material/IconButton';
|
|
|
|
import RemoveIcon from '@mui/icons-material/Remove';
|
2021-11-01 02:08:30 +09:00
|
|
|
import { ToastContainer, toast } from 'react-toastify';
|
|
|
|
import 'react-toastify/dist/ReactToastify.css';
|
2021-10-24 18:32:17 +09:00
|
|
|
|
|
|
|
import Alert from '../../component/alert';
|
|
|
|
|
2021-10-23 03:34:35 +09:00
|
|
|
|
2021-10-22 09:35:32 +09:00
|
|
|
const MeetingEdit = (props) => {
|
2021-11-01 02:08:30 +09:00
|
|
|
|
|
|
|
const history = useHistory();
|
2021-10-24 18:32:17 +09:00
|
|
|
|
2021-10-23 03:34:35 +09:00
|
|
|
const [title, setTitle] = useState('');
|
|
|
|
const [memo, setMemo] = useState('');
|
|
|
|
const [text, setText] = useState('');
|
2021-10-23 11:53:54 +09:00
|
|
|
const [pdf, setPdf] = useState('');
|
2021-10-24 18:32:17 +09:00
|
|
|
const [meeting_image, setMeetingImages] = useState([]);
|
2021-10-31 01:07:33 +09:00
|
|
|
const [approval_list, setApproval] = useState([]);
|
2021-11-03 17:47:21 +09:00
|
|
|
const [children_list, setChildren] = useState([]);
|
2021-10-23 03:34:35 +09:00
|
|
|
|
2021-11-01 02:08:30 +09:00
|
|
|
const [_422errors, set422Errors] = useState({title:'', text:'', memo:'', pdf:'', image:''})
|
2021-10-24 18:32:17 +09:00
|
|
|
const [_400error, set400Error] = useState('');
|
|
|
|
const [_success, setSuccess] = useState('');
|
2021-10-23 03:34:35 +09:00
|
|
|
|
2021-10-23 11:53:54 +09:00
|
|
|
const [loaded, setLoaded] = useState(false);
|
|
|
|
const [submit, setSubmit] = useState(false);
|
2021-10-23 03:34:35 +09:00
|
|
|
|
2021-11-03 17:47:21 +09:00
|
|
|
const [check_radio, setCheckRadio] = useState(null);
|
|
|
|
const [children_temp, setChildrenTemp] = useState([]);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(()=>{
|
|
|
|
if(!loaded) return; //if dont load data
|
|
|
|
var list = [];
|
|
|
|
if(check_radio=="false"){ //send all children
|
|
|
|
list = [...children_temp];
|
|
|
|
for(var i=0; i<list.length; i++)
|
|
|
|
list[i].checked = true;
|
|
|
|
}
|
|
|
|
else if(check_radio=="true"){ //send pickup
|
|
|
|
list = [...children_temp];
|
|
|
|
for(var i=0; i<list.length; i++){
|
|
|
|
if(approval_list.findIndex(ele=>ele.child_id == list[i].child_id) >= 0)
|
|
|
|
list[i].checked = true;
|
|
|
|
else list[i].checked = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setChildrenTemp(list);
|
|
|
|
},[check_radio])
|
2021-11-01 02:08:30 +09:00
|
|
|
|
|
|
|
|
2021-10-22 09:35:32 +09:00
|
|
|
useEffect(() => {
|
2021-10-23 03:34:35 +09:00
|
|
|
setLoaded(false);
|
2021-11-01 02:08:30 +09:00
|
|
|
axios.get(`/api/admin/meetings/detail/${props.match.params?.meeting_id}`)
|
|
|
|
.then(response => {
|
2021-10-23 03:34:35 +09:00
|
|
|
setLoaded(true);
|
|
|
|
if(response.data.status_code==200){
|
2021-11-01 02:08:30 +09:00
|
|
|
setTitle(response.data.params?.title);
|
|
|
|
setMemo(response.data.params?.memo);
|
|
|
|
setText(response.data.params?.text);
|
|
|
|
setMeetingImages(response.data.params?.meeting_image);
|
|
|
|
setApproval(response.data.params?.approval);
|
|
|
|
setPdf(response.data.params?.pdf);
|
2021-11-03 17:47:21 +09:00
|
|
|
setChildren(response.data.params?.children);
|
|
|
|
var list = [...response.data.params?.children];
|
2021-11-03 20:21:01 +09:00
|
|
|
var approval = [...response.data.params?.approval];
|
2021-11-03 17:47:21 +09:00
|
|
|
var arr = [];
|
|
|
|
for(var i=0; i<list.length; i++){
|
2021-11-03 20:21:01 +09:00
|
|
|
if(approval.findIndex(ele=>ele.child_id == list[i].child_id) >= 0)
|
|
|
|
arr.push({...list[i], checked: true});
|
|
|
|
else arr.push({...list[i], checked: false});
|
2021-11-03 17:47:21 +09:00
|
|
|
}
|
|
|
|
setChildrenTemp(arr);
|
2021-10-31 01:07:33 +09:00
|
|
|
}
|
2021-10-22 09:35:32 +09:00
|
|
|
});
|
2021-11-01 02:08:30 +09:00
|
|
|
}, []);
|
2021-10-23 11:53:54 +09:00
|
|
|
|
2021-10-24 18:32:17 +09:00
|
|
|
|
2021-11-01 02:08:30 +09:00
|
|
|
const handleSubmit = (e) => {
|
2021-10-24 18:32:17 +09:00
|
|
|
e.preventDefault();
|
2021-11-01 02:08:30 +09:00
|
|
|
set422Errors({title:'',memo:'',text:'',pdf:'',image:''});
|
2021-11-03 17:47:21 +09:00
|
|
|
|
|
|
|
var approval_registerIndexes = [];
|
|
|
|
var approval_deleteIndexes = [];
|
|
|
|
for(let i=0; i<children_temp.length; i++){
|
|
|
|
if(children_temp[i].checked){
|
|
|
|
if(approval_list.findIndex(ele=>ele.child_id == children_temp[i].child_id) < 0)
|
|
|
|
approval_registerIndexes.push(children_temp[i].child_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(let i=0; i<approval_list.length; i++){
|
|
|
|
if(children_temp.findIndex(ele=> ele.checked && ele.child_id == approval_list[i].child_id) < 0)
|
|
|
|
approval_deleteIndexes.push(approval_list[i].child_id);
|
|
|
|
}
|
|
|
|
console.log(approval_registerIndexes, approval_deleteIndexes);
|
|
|
|
|
|
|
|
const formdata = new FormData();
|
|
|
|
formdata.append('children', JSON.stringify(approval_registerIndexes));
|
|
|
|
axios.post('/api/admin/meeting/approvals/register',formdata, {params:{meeting_id: props.match.params.meeting_id}})
|
|
|
|
axios.delete('/api/admin/meeting/approvals/delete',{params:{children: approval_deleteIndexes, meeting_id: props.match.params.meeting_id}})
|
|
|
|
|
2021-10-22 09:35:32 +09:00
|
|
|
try {
|
2021-10-24 18:32:17 +09:00
|
|
|
const request = { title: title, text: text, memo: memo, pdf: pdf };
|
|
|
|
setSubmit(true);
|
2021-11-01 02:08:30 +09:00
|
|
|
axios.put(`/api/admin/meetings/update/${props.match.params?.meeting_id}`, request)
|
2021-10-24 18:32:17 +09:00
|
|
|
.then(response => {
|
|
|
|
setSubmit(false);
|
|
|
|
switch(response.data.status_code){
|
2021-11-01 02:08:30 +09:00
|
|
|
case 200: setSuccess("更新成功しました!"); break;
|
|
|
|
case 400: set400Error("更新失敗しました。"); break;
|
2021-10-24 18:32:17 +09:00
|
|
|
case 422: set422Errors(response.data.error_messages); break;
|
|
|
|
}
|
|
|
|
});
|
2021-10-22 09:35:32 +09:00
|
|
|
} catch (error) {
|
|
|
|
console.log('error', error);
|
|
|
|
}
|
2021-10-24 18:32:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleImageChange = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
let reader = new FileReader();
|
|
|
|
let _file = e.target.files[0];
|
2021-11-02 22:53:26 +09:00
|
|
|
if(!_file) return;
|
2021-10-24 18:32:17 +09:00
|
|
|
reader.readAsDataURL(_file);
|
|
|
|
reader.onloadend = () => {
|
2021-10-30 23:55:19 +09:00
|
|
|
const formdata = new FormData();
|
|
|
|
formdata.append('image', reader.result);
|
2021-10-31 01:07:33 +09:00
|
|
|
axios.post(`/api/admin/meeting/images/register`, formdata, {params:{meeting_id: props.match.params.meeting_id}})
|
2021-10-24 18:32:17 +09:00
|
|
|
.then(response => {
|
|
|
|
switch(response.data.status_code){
|
2021-11-01 02:08:30 +09:00
|
|
|
case 200: setMeetingImages(response.data.params); notify_save(); break;
|
2021-10-24 18:32:17 +09:00
|
|
|
case 400: set400Error(response.data.error_messages); break;
|
|
|
|
case 422: set422Errors(response.data.error_messages); break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
2021-10-23 03:34:35 +09:00
|
|
|
|
2021-11-01 02:08:30 +09:00
|
|
|
const handlePDFChange = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
let reader = new FileReader();
|
|
|
|
let _file = e.target.files[0];
|
2021-11-02 22:53:26 +09:00
|
|
|
if(!_file) return;
|
2021-11-01 02:08:30 +09:00
|
|
|
reader.readAsDataURL(_file);
|
|
|
|
reader.onloadend = () => {
|
|
|
|
setPdf(reader.result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleDeleteImage = (image_id) => {
|
|
|
|
axios.delete(`/api/admin/meeting/images/delete/${props.match.params?.meeting_id}`, {params:{image_id: image_id}})
|
2021-10-24 20:13:29 +09:00
|
|
|
.then(response=>{
|
|
|
|
switch(response.data.status_code){
|
2021-11-01 02:08:30 +09:00
|
|
|
case 200: setMeetingImages(response.data.params); notify_delete(); break;
|
|
|
|
case 400: set400Error("画像の削除に失敗しました。");
|
2021-10-24 20:13:29 +09:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-11-03 17:47:21 +09:00
|
|
|
const handleCheck = (e, index) => {
|
|
|
|
var list = [...children_temp];
|
|
|
|
list[index].checked = e.target.checked;
|
|
|
|
setChildrenTemp(list);
|
2021-11-01 02:08:30 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const notify_delete = () =>
|
|
|
|
toast.success("削除成功しました。", {
|
|
|
|
position: "top-right",
|
|
|
|
autoClose: 5000,
|
|
|
|
className:"bg-danger",
|
|
|
|
hideProgressBar: true,
|
|
|
|
closeOnClick: true,
|
|
|
|
pauseOnHover: true,
|
|
|
|
draggable: false,
|
|
|
|
progress: undefined,
|
|
|
|
style:{ color: '#ffffff'}
|
|
|
|
});
|
|
|
|
|
|
|
|
const notify_save = () =>
|
|
|
|
toast.success("更新が成功しました。", {
|
|
|
|
position: "top-right",
|
|
|
|
autoClose: 5000,
|
|
|
|
className:"bg-danger",
|
|
|
|
hideProgressBar: true,
|
|
|
|
closeOnClick: true,
|
|
|
|
pauseOnHover: true,
|
|
|
|
draggable: false,
|
|
|
|
progress: undefined,
|
|
|
|
style:{ color: '#ffffff'}
|
|
|
|
});
|
|
|
|
|
2021-10-23 03:34:35 +09:00
|
|
|
|
2021-10-22 09:35:32 +09:00
|
|
|
return (
|
|
|
|
<div className="l-content">
|
2021-10-23 03:34:35 +09:00
|
|
|
<div className="l-content-w560">
|
|
|
|
<div className="l-content__ttl">
|
|
|
|
<div className="l-content__ttl__left">
|
|
|
|
<h2>ミーティング編集</h2>
|
2021-10-22 09:35:32 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-23 03:34:35 +09:00
|
|
|
|
|
|
|
<div className="l-content-wrap">
|
|
|
|
<div className="p-article">
|
|
|
|
<div className="p-article-wrap position-relative" style={{ minHeight:'500px'}}>
|
|
|
|
{
|
|
|
|
!loaded &&
|
|
|
|
<CircularProgress color="secondary" style={{top:'150px', left:'calc(50% - 22px)', color:'green', position:'absolute'}}/>
|
|
|
|
}
|
|
|
|
{
|
|
|
|
loaded &&
|
|
|
|
<article className="p-article__body">
|
|
|
|
<div className="p-article__content">
|
|
|
|
<div className="p-article__context">
|
2021-10-23 11:53:54 +09:00
|
|
|
<form className="edit-form" onSubmit={handleSubmit}>
|
2021-10-23 03:34:35 +09:00
|
|
|
<div className="edit-set">
|
|
|
|
<label className="control-label" htmlFor="title">タイトル</label>
|
2021-10-23 11:53:54 +09:00
|
|
|
<input type="text" name="title" value={ title } onChange={e=>setTitle(e.target.value)} className={`input-default input-title input-h60 input-w480 ${ _422errors.title && 'is-invalid c-input__target'} `} id="title" />
|
|
|
|
{
|
|
|
|
_422errors.title &&
|
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
|
|
|
{_422errors.title}
|
|
|
|
</span>
|
|
|
|
}
|
2021-10-23 03:34:35 +09:00
|
|
|
</div>
|
|
|
|
<div className="edit-set">
|
|
|
|
<label className="control-label" htmlFor="meeting_textarea">本文</label>
|
2021-10-23 11:53:54 +09:00
|
|
|
<textarea value={ text } onChange={e=>setText(e.target.value)} rows="8" className={`textarea-default ${ _422errors.text && 'is-invalid c-input__target'} `} id="meeting_textarea" />
|
|
|
|
{
|
|
|
|
_422errors.text &&
|
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
|
|
|
{_422errors.text}
|
|
|
|
</span>
|
|
|
|
}
|
2021-10-23 03:34:35 +09:00
|
|
|
</div>
|
|
|
|
<div className="edit-set">
|
|
|
|
<label className="control-label" htmlFor="meeting_textarea">メモ</label>
|
2021-10-23 11:53:54 +09:00
|
|
|
<textarea value={ memo } onChange={e=>setMemo(e.target.value)} rows="8" className={`textarea-default ${ _422errors.memo && 'is-invalid c-input__target'} `} id="meeting_textarea" />
|
|
|
|
{
|
|
|
|
_422errors.memo &&
|
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
|
|
|
{_422errors.memo}
|
|
|
|
</span>
|
|
|
|
}
|
2021-10-23 03:34:35 +09:00
|
|
|
</div>
|
|
|
|
<div className="edit-set edit-set-mt15">
|
|
|
|
<label className="edit-set-file-label" htmlFor="file_pdf">
|
|
|
|
PDFアップロード
|
2021-11-01 02:08:30 +09:00
|
|
|
<input type="file" name="file_pdf" accept=".pdf" id="file_pdf" onChange={handlePDFChange} />
|
2021-10-23 03:34:35 +09:00
|
|
|
</label>
|
2021-10-23 11:53:54 +09:00
|
|
|
{
|
|
|
|
_422errors.pdf &&
|
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
|
|
|
{_422errors.pdf}
|
|
|
|
</span>
|
|
|
|
}
|
2021-10-23 03:34:35 +09:00
|
|
|
</div>
|
|
|
|
<div className="edit-set edit-set-mt15">
|
|
|
|
<label className="edit-set-file-label" htmlFor="file_image">
|
|
|
|
画像アップロード
|
2021-10-30 13:38:25 +09:00
|
|
|
<input type="file" name="file_image" accept=".png, .jpg, .jpeg" id="file_image" onChange={handleImageChange}/>
|
2021-10-23 03:34:35 +09:00
|
|
|
</label>
|
2021-11-01 02:08:30 +09:00
|
|
|
{
|
|
|
|
_422errors.image &&
|
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
|
|
|
{_422errors.image}
|
|
|
|
</span>
|
|
|
|
}
|
2021-10-23 03:34:35 +09:00
|
|
|
</div>
|
|
|
|
|
2021-10-30 13:38:25 +09:00
|
|
|
<div className="p-file-image justify-content-start">
|
2021-10-24 18:32:17 +09:00
|
|
|
{
|
|
|
|
meeting_image?.map((x, k)=>
|
|
|
|
<figure className="image-upload" key={k}>
|
|
|
|
<img src={x.image} alt={x.image} />
|
|
|
|
<IconButton
|
2021-11-01 02:08:30 +09:00
|
|
|
onClick={e=>handleDeleteImage(x.id)}
|
2021-10-24 18:32:17 +09:00
|
|
|
style={{position: 'absolute',
|
|
|
|
bottom: '-6px',
|
|
|
|
right: '-6px'}}>
|
|
|
|
<RemoveIcon
|
|
|
|
style={{width:'22px', height:'22px',
|
|
|
|
color: 'white',
|
|
|
|
background: '#dd0000',
|
|
|
|
borderRadius: '50%'}}/>
|
|
|
|
</IconButton>
|
|
|
|
</figure>
|
|
|
|
)
|
|
|
|
}
|
2021-11-01 12:04:37 +09:00
|
|
|
{
|
|
|
|
[...Array(10-meeting_image.length)]?.map((x, k)=>
|
|
|
|
<figure className="image-upload" key={k}></figure>
|
|
|
|
)
|
|
|
|
}
|
2021-10-23 03:34:35 +09:00
|
|
|
</div>
|
|
|
|
|
2021-11-03 20:21:01 +09:00
|
|
|
<div className="edit-set edit-set-send">
|
2021-10-23 03:34:35 +09:00
|
|
|
<label htmlFor="allmember_send">
|
2021-11-01 02:08:30 +09:00
|
|
|
<input className="boolean optional"
|
2021-11-02 00:23:43 +09:00
|
|
|
type="radio"
|
|
|
|
id="allmember_send"
|
|
|
|
name="check_radio"
|
|
|
|
value={false}
|
2021-11-02 01:36:41 +09:00
|
|
|
onClick={e=>setCheckRadio(e.target.value)}
|
2021-11-02 00:23:43 +09:00
|
|
|
/>
|
2021-11-01 02:08:30 +09:00
|
|
|
<span>全員に送信</span>
|
|
|
|
</label>
|
2021-10-23 03:34:35 +09:00
|
|
|
</div>
|
|
|
|
|
2021-11-03 20:21:01 +09:00
|
|
|
<div className="edit-set-mt5 edit-set-send">
|
2021-10-23 03:34:35 +09:00
|
|
|
<label htmlFor="pickup_send">
|
2021-11-01 02:08:30 +09:00
|
|
|
<input className="boolean optional"
|
2021-11-02 00:23:43 +09:00
|
|
|
type="radio"
|
|
|
|
id="pickup_send"
|
|
|
|
name="check_radio"
|
|
|
|
value={true}
|
2021-11-02 01:36:41 +09:00
|
|
|
onClick={e=>setCheckRadio(e.target.value)}
|
2021-11-02 00:23:43 +09:00
|
|
|
/>
|
2021-11-01 02:08:30 +09:00
|
|
|
<span>選んで送信</span>
|
|
|
|
</label>
|
2021-10-23 03:34:35 +09:00
|
|
|
</div>
|
2021-11-01 12:04:37 +09:00
|
|
|
|
2021-11-03 17:47:21 +09:00
|
|
|
<div className={`checkbox-wrap edit-bg ${check_radio!="true" && 'd-none'}`}>
|
2021-10-31 01:07:33 +09:00
|
|
|
{
|
2021-11-03 17:47:21 +09:00
|
|
|
children_list.length != 0 ?
|
|
|
|
children_temp?.map((item, k)=>
|
|
|
|
<div className="checkbox" key={k}>
|
|
|
|
<label htmlFor={`user_name${k}`}>
|
|
|
|
<input className="boolean optional"
|
|
|
|
type="checkbox"
|
|
|
|
id={`user_name${k}`}
|
|
|
|
checked = {item.checked}
|
|
|
|
onChange={e=>handleCheck(e, k)}/>
|
|
|
|
{`${item.first_name} ${item.last_name}`}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
: <p className="text-center">子はありません。</p>
|
2021-10-31 01:07:33 +09:00
|
|
|
}
|
2021-10-23 03:34:35 +09:00
|
|
|
</div>
|
2021-11-01 12:04:37 +09:00
|
|
|
|
2021-10-23 11:53:54 +09:00
|
|
|
<LoadingButton
|
2021-10-26 10:07:57 +09:00
|
|
|
type="submit" fullWidth
|
2021-10-23 11:53:54 +09:00
|
|
|
loading={submit}
|
2021-10-26 10:07:57 +09:00
|
|
|
className="btn-edit btn-default btn-h60 bg-yellow rounded-15">
|
|
|
|
<span className={`ft-20 font-weight-bold ${!submit && 'text-black'}`}>ミーティングを更新</span>
|
|
|
|
</LoadingButton>
|
2021-10-24 18:32:17 +09:00
|
|
|
{
|
|
|
|
_400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert>
|
|
|
|
}
|
|
|
|
{
|
2021-11-01 02:08:30 +09:00
|
|
|
_success &&
|
|
|
|
<Alert type="success"
|
|
|
|
hide={()=>
|
|
|
|
history.push({
|
|
|
|
pathname: `/admin/meeting/detail/${props.match.params?.meeting_id}`,
|
|
|
|
state: {}
|
|
|
|
})}>{_success}</Alert>
|
2021-10-24 18:32:17 +09:00
|
|
|
}
|
2021-10-23 03:34:35 +09:00
|
|
|
</form>
|
|
|
|
</div>
|
2021-10-22 09:35:32 +09:00
|
|
|
</div>
|
2021-10-23 03:34:35 +09:00
|
|
|
</article>
|
|
|
|
}
|
|
|
|
|
|
|
|
</div>
|
2021-10-22 09:35:32 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-01 02:08:30 +09:00
|
|
|
<ToastContainer />
|
2021-10-22 09:35:32 +09:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MeetingEdit;
|