import { useState } from "react"; import { useParams } from "react-router"; import roomApi from "../../apis/room.api"; const INIT_Channel = { id: "", channelName: "", number: "", }; const ChannelSettingChange = (props) => { const [Channel, setChannel] = useState(INIT_Channel); const [error, setError] = useState(""); const { roomId } = useParams(); //console.log(props.channel.[0].channelName) //각 채널의 채널이름. Channel.id = roomId; const updateinfo = (event) => { const { channelName, value } = event.target; setChannel({ ...Channel, channelName: value }); console.log(Channel.channelName); }; async function CreateChannel(e) { let count = 0; for (let a = 0; a < props.channel.length; a++) { if (Channel.channelName === props.channel[a].channelName) { count += 1; } } if (count == 1) { alert("이미 존재하는 채널 입니다. 다른 이름을 입력해 주십시오."); } else { Channel.number = props.channel.length; alert("채널이 성공적으로 생성되었습니다."); window.location.reload(); const data = await roomApi.makeChannel(Channel); } } async function DeleteChannel(e) { let count = 0; for (let a = 0; a < props.channel.length; a++) { if (Channel.channelName === props.channel[a].channelName) {//일치하면 count = count + 1; Channel.number = a; } } if (count === 1){ alert("채널이 성공적으로 삭제되었습니다."); window.location.reload(); const data = await roomApi.channelDelete(Channel); } else { alert( "입력한 채널명과 일치하는 채널이 존재하지 않습니다. 다시 확인해 주십시오." ); } }; return (
); }; export default ChannelSettingChange;