Select Git revision
createVote.js
createVote.js 1.19 KiB
import React from 'react';
import createVoteStyles from './createVote.module.css';
function CreateVote({ data, time }){
const createVote = async ()=>{
try{
const response = await fetch(`/api/recruits/${data.id}/times/save`,{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(time),
});
if (response.ok){
alert('투표가 등록되었습니다.');
window.location.reload();
}else{
throw new Error('Data loading error');
}
} catch(error){
console.log('Error during fetch:', error);
}
}
return (
<div>
<div>
{data.vote === 'Before' ?(
<button type='button' className={createVoteStyles.createVote} onClick={createVote}>투표 생성</button>
):(
<button type='button' className={createVoteStyles.endCreateVote} onClick={createVote} disabled>투표 생성</button>
)}
</div>
</div>
)
}
export default CreateVote;