import React, { useEffect, useState } from 'react'; import axios from 'axios'; 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 Alert from '../../component/alert'; const MeetingEdit = (props) => { const [title, setTitle] = useState(''); const [memo, setMemo] = useState(''); const [text, setText] = useState(''); const [pdf, setPdf] = useState(''); const [meeting_image, setMeetingImages] = useState([]); const [imageUri, setImageUri] = useState(''); const [_422errors, set422Errors] = useState({title:'', text:'', memo:'', pdf:''}) const [_400error, set400Error] = useState(''); const [_success, setSuccess] = useState(''); const [loaded, setLoaded] = useState(false); const [submit, setSubmit] = useState(false); useEffect(() => { setLoaded(false); axios.get(`/api/admin/meetings/detail/${props.match.params?.meeting_id}`, {params: { father_id: 1 }}) .then((response) => { setLoaded(true); if(response.data.status_code==200){ console.log(response.data.params[0]); setTitle(response.data.params[0]?.title); setMemo(response.data.params[0]?.memo); setText(response.data.params[0]?.text); setMeetingImages(response.data.params[0]?.meeting_image); } else if(response.data.status_code==400){ //TODO } }); }, []); const handleSubmit = (e) => { e.preventDefault(); set422Errors({title:'',memo:'',text:'',pdf:'',images:''}); try { const request = { title: title, text: text, memo: memo, pdf: pdf }; setSubmit(true); axios.put(`/api/admin/meetings/update/${props.match.params?.meeting_id}`, request) .then(response => { setSubmit(false); switch(response.data.status_code){ case 200: setSuccess(response.data.success_messages); break; case 400: set400Error(response.data.error_messages); 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]; reader.readAsDataURL(_file); const formdata = new FormData(); formdata.append('image', reader.result); reader.onloadend = () => { axios.post(`/api/admin/meeting/images/register`, {params:{meeting_id: props.match.params.meeting_id}}) .then(response => { switch(response.data.status_code){ case 200: { setImageUri(reader.result); var [...list] = meeting_image; list.push({image: reader.result}); console.log(list); setMeetingImages(list); setSuccess(response.data.success_messages); break; } case 400: set400Error(response.data.error_messages); break; case 422: set422Errors(response.data.error_messages); break; } }); }; }; const handleDeleteImage = () => { console.log("delete"); axios.delete(`/api/admin/meetings/images/delete/${props.match.params.meeting_id}`) .then(response=>{ switch(response.data.status_code){ case 200: setSuccess("画像の削除に成功しました!"); case 400: set400Error("画像の削除に失敗しました。") } }) } return (

ミーティング編集

{ !loaded && } { loaded &&
setTitle(e.target.value)} className={`input-default input-title input-h60 input-w480 ${ _422errors.title && 'is-invalid c-input__target'} `} id="title" /> { _422errors.title && {_422errors.title} }