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

108 行
4.4 KiB
React
Raw 通常表示 履歴

2021-10-01 17:45:39 +09:00
import React, { useEffect, useState } from 'react';
2021-11-17 19:32:05 +09:00
import { LoadingButton } from '@material-ui/lab';
2021-11-17 20:34:29 +09:00
import axios from 'axios';
2021-11-16 02:31:44 +09:00
import Alert from '../../component/alert';
2021-11-17 19:32:05 +09:00
import Notification from '../notification';
2021-11-24 16:42:56 +09:00
import copy from 'clipboard-copy';
2021-11-16 02:31:44 +09:00
2021-10-01 17:45:39 +09:00
const ChildAdd = () => {
2021-11-17 19:32:05 +09:00
const [notice, setNotice] = useState(localStorage.getItem('notice'));
2021-10-09 01:16:45 +09:00
const [identity, setIdentity] = useState('');
2021-10-05 00:35:47 +09:00
2021-11-17 19:32:05 +09:00
const [_success, setSuccess] = useState('');
const [_400error, set400Error] = useState('');
const [_422errors, set422Errors] = useState({identity: ''});
const [submit, setSubmit] = useState(false);
const father_id = document.getElementById('father_id').value;
const handleSubmit = (e) => {
e.preventDefault();
2021-11-17 19:47:05 +09:00
set422Errors({identity: ''});
2021-10-05 00:35:47 +09:00
const formdata = new FormData();
2021-10-09 01:16:45 +09:00
formdata.append('identity', identity);
2021-11-17 19:32:05 +09:00
formdata.append('father_id', father_id);
setSubmit(true);
axios.post('/api/fathers/relations/register', formdata)
.then(response => {
setSubmit(false);
setNotice(response.data.notice);
switch(response.data.status_code){
case 200: setSuccess(response.data.success_messages); break;
case 400: set400Error(response.data.error_messages); break;
2021-12-14 17:11:16 +09:00
case 401: set400Error(response.data.error_messages); break;
2021-11-17 19:32:05 +09:00
case 422: set422Errors(response.data.error_messages); break;
}
});
}
2021-11-17 19:32:05 +09:00
const copyInviteURL = () => {
2021-11-25 13:07:07 +09:00
const inviteText = "https://kikikan.xyz/c-account/register-temporary";
2021-11-24 16:42:56 +09:00
copy(inviteText);
setSuccess('招待用URLをコピーしました。');
2021-10-05 00:35:47 +09:00
}
2021-11-17 19:32:05 +09:00
const copyLineText = () => {
2021-12-15 09:49:19 +09:00
const lineText = "「KIKI」の招待が届いています。%0Aまずは以下より仮登録を行ってください。%0Ahttps%3A%2F%2Fkikikan.xyz%2Fc-account%2Fregister-temporary%0A%0A▼公式サイトはこちら%0Ahttps%3A%2F%2Fkikikan.xyz";
2021-11-24 16:42:56 +09:00
copy(lineText);
setSuccess('招待用URLをLINEで追信しました。');
2021-11-26 20:31:57 +09:00
window.open('http://line.me/R/msg/text/?'+lineText);
2021-11-17 19:32:05 +09:00
}
2021-10-01 17:45:39 +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>
2021-11-17 19:32:05 +09:00
<Notification notice={notice}/>
</div>
<div className="l-content-wrap">
<section className="edit-container">
<div className="edit-wrap">
<div className="edit-content">
2021-11-17 19:32:05 +09:00
<form className="edit-form" onSubmit={handleSubmit}>
<div className="edit-set">
2021-11-17 19:32:05 +09:00
<label className="control-label" htmlFor="identify">追加する子のIDを入力</label>
<input type="text"
name="identity"
id="identity"
value={identity}
onChange={e=>setIdentity(e.target.value)}
className={`input-default input-title input-h60 input-w480 ${ _422errors.identity && 'is-invalid c-input__target'} `} />
{
_422errors.identity &&
<span className="l-alert__text--error ft-16 ft-md-14">
{_422errors.identity}
</span>
}
2021-10-01 17:45:39 +09:00
</div>
2021-11-17 19:32:05 +09:00
<LoadingButton
type="submit" fullWidth
loading={submit}
className="btn-edit btn-default btn-h75 bg-yellow rounded-20"
style={{marginTop:'50px'}}>
2021-11-25 21:29:01 +09:00
<span className={`ft-18 ft-xs-16 font-weight-bold ${!submit && 'text-black'}`}>追加</span>
2021-11-17 19:32:05 +09:00
</LoadingButton>
</form>
2021-11-17 19:32:05 +09:00
<div style={{color:"#49A3FC",display:"flex", justifyContent:"center", alignItems:"center", paddingTop:40}} >
<a onClick={copyInviteURL}>招待用URLをコピーする</a>
2021-10-09 01:16:45 +09:00
</div>
2021-11-17 19:32:05 +09:00
<div style={{color:"#49A3FC",display:"flex", justifyContent:"center", alignItems:"center", paddingTop:20}}>
<a onClick={copyLineText}>招待用URLをLINEで追信</a>
2021-10-09 01:16:45 +09:00
</div>
2021-10-01 17:45:39 +09:00
</div>
</div>
</section>
2021-10-01 17:45:39 +09:00
</div>
</div>
2021-11-17 19:32:05 +09:00
{ _success && <Alert type="success" hide={()=>setSuccess('')}>{_success}</Alert> }
{ _400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert> }
</div>
2021-10-01 17:45:39 +09:00
)
}
export default ChildAdd;