add alert in p-meeting

このコミットが含まれているのは:
dragon1211 2021-11-16 05:19:56 -08:00
コミット 2a05a06976
5個のファイルの変更905行の追加498行の削除

ファイル差分が大きすぎるため省略します 差分を読み込み

ファイルの表示

@ -1,181 +1,385 @@
import React, { useEffect, useState } from 'react';
import Notification from '../../component/notification';
import { useHistory } from 'react-router-dom';
import axios from 'axios';
import { useHistory } from 'react-router-dom'
import { CircularProgress } from '@material-ui/core';
import { LoadingButton } from '@material-ui/lab';
import IconButton from '@mui/material/IconButton';
import RemoveIcon from '@mui/icons-material/Remove';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
const MeetingAdd = () => {
const [textColor, setTextColor] = useState(null);
const [showAlert, setShowAlert] = useState(false);
const [messageAlert, setMessageAlert] = useState(null);
const fatherId = document.getElementById('father_id').value;
const [images, setImages] = useState([]);
const [pdf, setPdf] = useState(null);
const [title, setTitle] = useState(null);
const [memo, setMemo] = useState(null);
const [text, setText] = useState(null);
const history = useHistory();
import Alert from '../../component/alert';
import Notification from '../notification';
const [errors, setErrors] = useState({
title:'',
memo:'',
text:'',
pdf:'',
images:''
})
async function handleClick() {
setErrors({
title:'',
memo:'',
text:'',
pdf:'',
images:''
const MeetingAdd = (props) => {
const history = useHistory();
const father_id = document.getElementById('father_id').value;
const meeting_id = props.match.params.meeting_id;
const [notice, setNotice] = useState(localStorage.getItem('notice'));
const [title, setTitle] = useState('');
const [memo, setMemo] = useState('');
const [text, setText] = useState('');
const [pdf, setPdf] = useState('');
const [meeting_image, setMeetingImages] = useState([]);
const [children_list, setChildrenList] = useState([]);
const [_422errors, set422Errors] = useState({title:'', text:'', memo:'', pdf:'', image:''})
const [_400error, set400Error] = useState('');
const [_success, setSuccess] = useState('');
const [loaded, setLoaded] = useState(false);
const [submit, setSubmit] = useState(false);
const [check_radio, setCheckRadio] = useState(null);
useEffect(()=>{
setLoaded(false);
axios.get('/api/fathers/children/listOfFather', {params:{father_id: father_id}})
.then(response=>{
setLoaded(true);
setNotice(response.data.notice);
console.log(response.data)
if(response.data.status_code == 200){
var list = response.data.params;
var arr = [];
for(var i in list){
arr.push({...list[i], checked: false})
}
setChildrenList(arr);
console.log(arr)
}
})
},[])
// useEffect(() => {
// setLoaded(false);
// axios.get(`/api/fathers/meetings/detail/${meeting_id}`, {params: { father_id: father_id}})
// .then(response => {
// setLoaded(true);
// setNotice(response.data.notice)
// if(response.data.status_code==200){
// 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);
// setChildren(response.data.params?.children);
// var list = [...response.data.params?.children];
// var approval = [...response.data.params?.approval];
// var arr = [];
// for(var i=0; i<list.length; i++){
// 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});
// }
// setChildrenList(arr);
// }
// });
// }, []);
//--------------------------------------------------------
useEffect(()=>{
if(!loaded) return; //if dont load data
var list = [...children_list];
for(var i in list){
if(check_radio == 'false')
list[i].checked = true;
else list[i].checked = false;
}
setChildrenList(list);
},[check_radio])
//----------------------------------------------------------------------
const handleSubmit = (e) => {
e.preventDefault();
set422Errors({title:'',memo:'',text:'',pdf:'',image:''});
const request = { title: title, text: text, memo: memo, pdf: pdf };
const formdata = new FormData();
formdata.append('father_id', father_id);
formdata.append('title', title);
formdata.append('text', text);
formdata.append('memo', memo);
formdata.append('pdf', pdf);
try {
setSubmit(true);
axios.post('/api/fathers/meetings/register', formdata)
.then(response => {
setNotice(response.data.notice);
setSubmit(false);
switch(response.data.status_code){
case 200: {
history.push({
pathname: `/p-account/meeting/detail/${props.match.params?.meeting_id}`,
state: "登録成功しました"});
break;
}
case 400: set400Error("更新失敗しました。"); break;
case 422: set422Errors(response.data.error_messages); break;
}
});
} catch (error) {
console.log('error', error);
}
}
const handleImageChange = (e) => {
e.preventDefault();
let reader = new FileReader();
let _file = e.target.files[0];
if(!_file) return;
reader.readAsDataURL(_file);
reader.onloadend = () => {
const formdata = new FormData();
formdata.append('image', reader.result);
axios.post(`/api/fathers/meeting/images/register`, formdata, {params:{meeting_id: meeting_id}})
.then(response => {
setNotice(response.data.notice);
switch(response.data.status_code){
case 200: setMeetingImages(response.data.params); notify_save(); break;
case 400: set400Error(response.data.error_messages); break;
case 422: set422Errors(response.data.error_messages); break;
}
});
};
};
const handlePDFChange = (e) => {
e.preventDefault();
let reader = new FileReader();
let _file = e.target.files[0];
if(!_file) return;
reader.readAsDataURL(_file);
reader.onloadend = () => {
setPdf(reader.result);
}
}
const handleDeleteImage = (image_id) => {
axios.delete(`/api/fathers/meeting/images/delete/${meeting_id}`, {params:{image_id: image_id}})
.then(response=>{
setNotice(response.data.notice);
switch(response.data.status_code){
case 200: setMeetingImages(response.data.params); notify_delete(); break;
case 400: set400Error("画像の削除に失敗しました。");
}
})
}
const handleCheck = (e, index) => {
var list = [...children_list];
list[index].checked = e.target.checked;
setChildrenList(list);
}
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'}
});
try {
const formdata = new FormData();
formdata.append('father_id', fatherId);
formdata.append('title', title);
formdata.append('memo', memo);
formdata.append('text', text);
formdata.append('pdf', pdf);
formdata.append('images', images);
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'}
});
axios.post('/api/meetings/register', formdata)
.then(response => {
if(response.data.status_code==200){
history.push({
pathname: "/p-account/meetings/detail/1",
state: {message : "ミーティングを作成しました!"}
});
} else {
setMessageAlert('error');
setShowAlert(true);
}
});
} catch (error) {
console.log('error', error);
}
}
const handleImageChange = (e) => {
e.preventDefault();
let reader = new FileReader();
let _file = e.target.files[0];
reader.readAsDataURL(_file);
reader.onloadend = () => {
setImages([...images, reader.result]);
};
// //upload image
// try {
// const formdata = new FormData();
// formdata.append('father_id', fatherId);
// formdata.append('image', _file);
// axios.put("/api/fathers/updateImage", formdata)
// .then(response => {
// if(response.data.status_code == 200){
// setMessageAlert(response.data.success_messages);
// setTextColor("black");
// } else {
// setMessageAlert(response.data.success_messages);
// }
// setShowAlert(true);
// });
// } catch (error) {
// console.log('error', error);
// }
};
const handlePdfChange = (e) => {
e.preventDefault();
let reader = new FileReader();
let _file = e.target.files[0];
reader.readAsDataURL(_file);
reader.onloadend = () => {
setPdf(reader.result);
};
};
async function handleCloseAlert() {
setShowAlert(false);
};
return (
<div className="l-content">
<div className="l-content-w560">
<div className="l-content__ttl">
<div className="l-content__ttl__left">
<h2>ミーティング作成</h2>
</div>
<Notification />
</div>
<div className="l-content-wrap">
<div className="p-article">
<div className="p-article-wrap">
<article className="p-article__body">
<div className="p-article__content">
<div className="p-article__context">
<form action="" className="edit-form">
<div className="edit-set">
<label className="control-label" htmlFor="title">タイトル</label>
<input type="text" name="title" value={ title } onChange={e=>setTitle(e.target.value)} className="input-default input-title input-h60 input-w480" id="title" />
</div>
<div className="edit-set">
<label className="control-label" htmlFor="meeting_textarea">本文</label>
<textarea value={ text } onChange={e=>setText(e.target.value)} rows="8" className="textarea-default" id="meeting_textarea" />
</div>
<div className="edit-set">
<label className="control-label" htmlFor="meeting_textarea">メモ</label>
<textarea value={ memo } onChange={e=>setMemo(e.target.value)} rows="8" className="textarea-default" id="meeting_textarea" />
</div>
<div className="edit-set edit-set-mt15">
<label className="edit-set-file-label" htmlFor="file_pdf">
PDFアップロード
<input type="file" name="file_pdf" accept=".pdf" id="file_pdf" onChange={(e) => handlePdfChange(e)} />
</label>
</div>
<div className="edit-set edit-set-mt15">
<label className="edit-set-file-label" htmlFor="file_image">
画像アップロード
<input type="file" name="file_image" accept=".png, .jpg, .jpeg" id="file_image" onChange={(e) => handleImageChange(e)} />
</label>
</div>
<div className="p-file-image">
{ images?.length > 0 && images.map((url,inx) => {
return (
<figure className="image-upload"><img src={url} alt="" /></figure>
);
})}
</div>
<div className="edit-set edit-set-send">
<label htmlFor="allmember_send">
<input className="boolean optional" type="checkbox" name="allmember_send" id="allmember_send" />全員に送信</label>
</div>
<div className="edit-set-mt5 edit-set-send">
<label htmlFor="pickup_send">
<input className="boolean optional" type="checkbox" name="pickup_send" id="pickup_send" />選んで送信</label>
</div>
<button
type="button"
onClick={e => {
e.preventDefault();
handleClick();
}}
className="btn-edit btn-default btn-h70 btn-r14 btn-yellow">ミーティングを作成</button>
</form>
</div>
<div className="l-content">
<div className="l-content-w560">
<div className="l-content__ttl">
<div className="l-content__ttl__left">
<h2>ミーティング作成</h2>
</div>
<Notification notice={notice}/>
</div>
<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">
<form className="edit-form" onSubmit={handleSubmit}>
<div className="edit-set">
<label className="control-label" htmlFor="title">タイトル</label>
<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>
}
</div>
<div className="edit-set">
<label className="control-label" htmlFor="meeting_textarea">本文</label>
<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>
}
</div>
<div className="edit-set">
<label className="control-label" htmlFor="meeting_textarea">メモ</label>
<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>
}
</div>
<div className="edit-set edit-set-mt15">
<label className="edit-set-file-label" htmlFor="file_pdf">
PDFアップロード
<input type="file" name="file_pdf" accept=".pdf" id="file_pdf" onChange={handlePDFChange} />
</label>
{
_422errors.pdf &&
<span className="l-alert__text--error ft-16 ft-md-14">
{_422errors.pdf}
</span>
}
</div>
<div className="edit-set edit-set-mt15">
<label className="edit-set-file-label" htmlFor="file_image">
画像アップロード
<input type="file" name="file_image" accept=".png, .jpg, .jpeg" id="file_image" onChange={handleImageChange}/>
</label>
{
_422errors.image &&
<span className="l-alert__text--error ft-16 ft-md-14">
{_422errors.image}
</span>
}
</div>
<div className="p-file-image justify-content-start">
{
meeting_image?.map((x, k)=>
<figure className="image-upload" key={k}>
<img src={x.image} alt={x.image} />
<IconButton
onClick={e=>handleDeleteImage(x.id)}
style={{position: 'absolute',
bottom: '-6px',
right: '-6px'}}>
<RemoveIcon
style={{width:'22px', height:'22px',
color: 'white',
background: '#dd0000',
borderRadius: '50%'}}/>
</IconButton>
</figure>
)
}
{
[...Array(10-meeting_image.length)]?.map((x, k)=>
<figure className="image-upload" key={k}></figure>
)
}
</div>
<div className="edit-set edit-set-send">
<label htmlFor="allmember_send">
<input className="boolean optional"
type="radio"
id="allmember_send"
name="check_radio"
value={false}
onClick={e=>setCheckRadio(e.target.value)}
/>
<span>全員に送信</span>
</label>
</div>
<div className="edit-set-mt5 edit-set-send">
<label htmlFor="pickup_send">
<input className="boolean optional"
type="radio"
id="pickup_send"
name="check_radio"
value={true}
onClick={e=>setCheckRadio(e.target.value)}
/>
<span>選んで送信</span>
</label>
</div>
<div className={`checkbox-wrap edit-bg ${check_radio!="true" && 'd-none'}`}>
{
children_list.length != 0 ?
children_list?.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>
}
</div>
<LoadingButton
type="submit" fullWidth
loading={submit}
className="btn-edit btn-default btn-h75 bg-yellow rounded-15">
<span className={`ft-20 ft-xs-16 font-weight-bold ${!submit && 'text-black'}`}>ミーティングを登録</span>
</LoadingButton>
{
_400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert>
}
</form>
</div>
</div>
</article>
}
</div>
</div>
</div>
</article>
</div>
</div>
</div>
</div>
</div>
<ToastContainer />
</div>
)
}

ファイルの表示

@ -20,8 +20,7 @@ const MeetingDetail = (props) => {
const [submit_delete, setSubmitDelete] = useState(false);
const [submit_notify, setSubmitNotify] = useState(false);
const [notice, setNotice] = useState(localStorage.getItem('notice'));
const [_success_delete, setSuccessDelete] = useState('');
const [_success_notify, setSuccessNotify] = useState('');
const [_success, setSuccess] = useState(props.history.location.state);
const [_400error, set400Error] = useState('');
const [showDelete, setShowDelete] = useState(false);
@ -64,7 +63,11 @@ const MeetingDetail = (props) => {
setSubmitDelete(false);
setShowDelete(false);
switch(response.data.status_code){
case 200: setSuccessDelete('ミーティングの削除に成功しました!'); break;
case 200: {
history.push({ pathname: "/p-account/meeting",
state: "ミーティングの削除に成功しました!" });
break;
}
case 400: set400Error('ミーティングの削除に失敗しました。'); break;
}
});
@ -106,7 +109,7 @@ const MeetingDetail = (props) => {
setSubmitNotify(false);
setShowNotify(false);
switch(response.data.status_code){
case 200: setSuccessNotify('SMSの送信に成功しました!'); break;
case 200: setSuccess('SMSの送信に成功しました!'); break;
case 400: set400Error('SMSの送信に失敗しました。'); break;
}
})
@ -258,16 +261,7 @@ const MeetingDetail = (props) => {
}
</div>
{ _400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert> }
{ _success_notify && <Alert type="success" hide={()=>setSuccessNotify('')}>{_success_notify}</Alert> }
{
_success_delete &&
<Alert type="success"
hide={()=>
history.push({
pathname: "/p-account/meeting",
state: {}
})}>{_success_delete}</Alert>
}
{ _success && <Alert type="success" hide={()=>setSuccess('')}>{_success}</Alert> }
</div>
)
}

ファイルの表示

@ -25,7 +25,7 @@ const MeetingEdit = (props) => {
const [pdf, setPdf] = useState('');
const [meeting_image, setMeetingImages] = useState([]);
const [approval_list, setApproval] = useState([]);
const [children_list, setChildren] = useState([]);
const [children_list, setChildrenList] = useState([]);
const [_422errors, set422Errors] = useState({title:'', text:'', memo:'', pdf:'', image:''})
const [_400error, set400Error] = useState('');
@ -35,7 +35,6 @@ const MeetingEdit = (props) => {
const [submit, setSubmit] = useState(false);
const [check_radio, setCheckRadio] = useState(null);
const [children_temp, setChildrenTemp] = useState([]);
useEffect(() => {
@ -51,7 +50,7 @@ const MeetingEdit = (props) => {
setMeetingImages(response.data.params?.meeting_image);
setApproval(response.data.params?.approval);
setPdf(response.data.params?.pdf);
setChildren(response.data.params?.children);
var list = [...response.data.params?.children];
var approval = [...response.data.params?.approval];
var arr = [];
@ -60,7 +59,7 @@ const MeetingEdit = (props) => {
arr.push({...list[i], checked: true});
else arr.push({...list[i], checked: false});
}
setChildrenTemp(arr);
setChildrenList(arr);
}
});
}, []);
@ -71,19 +70,19 @@ const MeetingEdit = (props) => {
if(!loaded) return; //if dont load data
var list = [];
if(check_radio=="false"){ //send all children
list = [...children_temp];
list = [...children_list];
for(var i=0; i<list.length; i++)
list[i].checked = true;
}
else if(check_radio=="true"){ //send pickup
list = [...children_temp];
list = [...children_list];
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);
setChildrenList(list);
},[check_radio])
//----------------------------------------------------------------------
@ -93,14 +92,14 @@ const MeetingEdit = (props) => {
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<children_list.length; i++){
if(children_list[i].checked){
if(approval_list.findIndex(ele=>ele.child_id == children_list[i].child_id) < 0)
approval_registerIndexes.push(children_list[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)
if(children_list.findIndex(ele=> ele.checked && ele.child_id == approval_list[i].child_id) < 0)
approval_deleteIndexes.push(approval_list[i].child_id);
}
@ -117,7 +116,13 @@ const MeetingEdit = (props) => {
setNotice(response.data.notice);
setSubmit(false);
switch(response.data.status_code){
case 200: setSuccess("更新成功しました!"); break;
case 200: {
history.push({
pathname: `/p-account/meeting/detail/${props.match.params?.meeting_id}`,
state: "更新成功しました!"
});
break;
}
case 400: set400Error("更新失敗しました。"); break;
case 422: set422Errors(response.data.error_messages); break;
}
@ -173,9 +178,9 @@ const MeetingEdit = (props) => {
}
const handleCheck = (e, index) => {
var list = [...children_temp];
var list = [...children_list];
list[index].checked = e.target.checked;
setChildrenTemp(list);
setChildrenList(list);
}
@ -339,7 +344,7 @@ const MeetingEdit = (props) => {
<div className={`checkbox-wrap edit-bg ${check_radio!="true" && 'd-none'}`}>
{
children_list.length != 0 ?
children_temp?.map((item, k)=>
children_list?.map((item, k)=>
<div className="checkbox" key={k}>
<label htmlFor={`user_name${k}`}>
<input className="boolean optional"
@ -364,15 +369,6 @@ const MeetingEdit = (props) => {
{
_400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert>
}
{
_success &&
<Alert type="success"
hide={()=>
history.push({
pathname: `/p-account/meeting/detail/${props.match.params?.meeting_id}`,
state: {}
})}>{_success}</Alert>
}
</form>
</div>
</div>

ファイルの表示

@ -12,7 +12,7 @@ import InfiniteScroll from "react-infinite-scroll-component";
const INFINITE = 5;
const SCROLL_DELAY_TIME = 1500;
const Meeting = () => {
const Meeting = (props) => {
const [notice, setNotice] = useState(localStorage.getItem('notice'));
const [tab_status, setTabStatus] = useState(false);
@ -23,7 +23,7 @@ const Meeting = () => {
const [meeting_list_complete, setMeetingListComplete] = useState([]);
const [fetch_meeting_list_incomplete, setFetchMeetingListIncomplete] = useState([]);
const [fetch_meeting_list_complete, setFetchMeetingListComplete] = useState([]);
const [_success, setSuccess] = useState('');
const [_success, setSuccess] = useState(props.history.location.state);
useEffect(()=>{
if(localStorage.getItem("from_login")){
@ -323,7 +323,7 @@ const Meeting = () => {
}
</section>
</div>
{ _success && <Alert type="success">{_success}</Alert> }
{ _success && <Alert type="success" hide={()=>setSuccess('')}>{_success}</Alert> }
</div>
)