2021-10-01 17:45:39 +09:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2021-10-06 14:25:48 +09:00
|
|
|
import ModalAlert from '../../component/modal_alert';
|
2021-10-01 17:45:39 +09:00
|
|
|
|
|
|
|
const ChildAdd = () => {
|
2021-10-05 00:35:47 +09:00
|
|
|
const [tel, setTel] = useState('');
|
2021-10-06 14:25:48 +09:00
|
|
|
const [textColor, setTextColor] = useState(null);
|
|
|
|
const [showAlert, setShowAlert] = useState(false);
|
|
|
|
const [messageAlert, setMessageAlert] = useState(null);
|
2021-10-07 14:54:28 +09:00
|
|
|
const fatherId = document.getElementById('father_id').value;
|
2021-10-05 00:35:47 +09:00
|
|
|
|
|
|
|
async function handleClick() {
|
|
|
|
try {
|
2021-10-06 14:25:48 +09:00
|
|
|
if(tel == '') {
|
|
|
|
return;
|
|
|
|
}
|
2021-10-05 00:35:47 +09:00
|
|
|
const formdata = new FormData();
|
|
|
|
formdata.append('tel', tel);
|
2021-10-06 14:25:48 +09:00
|
|
|
|
2021-10-05 00:35:47 +09:00
|
|
|
axios.post('/api/children/checkTel', formdata)
|
|
|
|
.then(response => {
|
2021-10-06 14:25:48 +09:00
|
|
|
if(response.data.status_code==201){
|
|
|
|
const formdata2 = new FormData();
|
2021-10-07 14:54:28 +09:00
|
|
|
formdata2.append('father_id ', fatherId);
|
2021-10-06 14:25:48 +09:00
|
|
|
axios.post('/api/children/registerTemporary', formdata2)
|
|
|
|
.then(response2 => {
|
|
|
|
if(response2.data.status_code==200){
|
|
|
|
const formdata3 = new FormData();
|
|
|
|
formdata3.append('send_id ', 1);
|
|
|
|
formdata3.append('receive_id', tel);
|
|
|
|
formdata3.append('message', "危機管理アプリに招待URLが届きました。1時間以内に、URLから本登録を行ってください。https://○○○.com/register/c-account/{token}'");
|
|
|
|
axios.post('/api/smss/register', formdata3)
|
|
|
|
.then(response3 => {
|
|
|
|
if(response3.data.status_code==200){
|
|
|
|
setMessageAlert(response.data.success_messages);
|
|
|
|
setTextColor("black");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if(response.data.status_code==200){
|
2021-10-07 14:54:28 +09:00
|
|
|
formdata.append('father_id', fatherId);
|
2021-10-06 14:25:48 +09:00
|
|
|
axios.post('/api//father-relations/register', formdata)
|
|
|
|
.then(response => {
|
|
|
|
if(response.data.status_code==200){
|
|
|
|
setMessageAlert(response.data.success_messages);
|
|
|
|
setTextColor("black");
|
|
|
|
} else {
|
|
|
|
setMessageAlert(response.data.success_messages);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-10-05 00:35:47 +09:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
console.log('error', error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 14:25:48 +09:00
|
|
|
async function handleCloseAlert() {
|
|
|
|
setShowAlert(false);
|
|
|
|
};
|
|
|
|
|
2021-10-01 17:45:39 +09:00
|
|
|
return (
|
2021-10-03 02:08:39 +09:00
|
|
|
<div className="l-content">
|
|
|
|
<div className="l-content-w560">
|
|
|
|
<div className="l-content__ttl">
|
|
|
|
<div className="l-content__ttl__left">
|
|
|
|
<h2>子追加</h2>
|
|
|
|
</div>
|
|
|
|
<div className="p-notification">
|
|
|
|
<div className="p-notification-icon">
|
|
|
|
<div className="p-notification-icon-wrap">
|
|
|
|
<div className="count">1</div>
|
|
|
|
<div className="p-notification-icon-bg"></div>
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22.742 19.855" className="icon svg-icon svg-fill svg-y50" ><g fill="none" stroke="#080808" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" data-name="Icon feather-alert-triangle" transform="translate(0.777 0.75)"><path d="M11.188,5.322,2.6,19.659A2.028,2.028,0,0,0,4.334,22.7H21.51a2.028,2.028,0,0,0,1.734-3.042L14.656,5.322a2.028,2.028,0,0,0-3.468,0Z" data-name="パス 3" transform="translate(-2.328 -4.346)"/><path d="M18,13.5v6.91" data-name="パス 4" transform="translate(-7.406 -8.547)"/><path d="M18,25.5h0" data-name="パス 5" transform="translate(-7.406 -11.2)"/></g></svg>
|
2021-10-01 17:45:39 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-03 02:08:39 +09:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="l-content-wrap">
|
|
|
|
<section className="edit-container">
|
|
|
|
<div className="edit-wrap">
|
|
|
|
<div className="edit-content">
|
|
|
|
|
|
|
|
<form action="" className="edit-form">
|
|
|
|
<div className="edit-set">
|
|
|
|
<label className="control-label" htmlFor="tel">追加する子の電話番号を入力</label>
|
2021-10-06 14:25:48 +09:00
|
|
|
<input type="tel" name="tel" onChange={e=>setTel(e.target.value)} value={tel} className="input-default input-tel input-h60 input-w480" id="tel" />
|
2021-10-01 17:45:39 +09:00
|
|
|
</div>
|
2021-10-05 00:35:47 +09:00
|
|
|
<button
|
|
|
|
onClick={e => {
|
|
|
|
e.preventDefault();
|
|
|
|
handleClick();
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
className="btn-edit btn-default btn-h70 btn-r14 btn-yellow">追加 or 招待</button>
|
2021-10-03 02:08:39 +09:00
|
|
|
</form>
|
|
|
|
|
2021-10-01 17:45:39 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-03 02:08:39 +09:00
|
|
|
</section>
|
2021-10-01 17:45:39 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-06 14:25:48 +09:00
|
|
|
<ModalAlert
|
|
|
|
show={showAlert}
|
|
|
|
message={messageAlert}
|
|
|
|
textColor={textColor}
|
|
|
|
handleClose={handleCloseAlert}
|
|
|
|
/>
|
2021-10-03 02:08:39 +09:00
|
|
|
</div>
|
2021-10-01 17:45:39 +09:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-10-03 02:08:39 +09:00
|
|
|
export default ChildAdd;
|