"use client"; import CalenderSelector from "@/app/components/CalenderSelector"; import Modal from "@/app/components/Modal"; import { useEffect, useRef, useState } from "react"; export default function Page() { const [isreqmodal, setIsreqmodal] = useState(false); const [chanellist, setChanellist] = useState([]); const [contentlist, setContentlist] = useState<{ id: string; email: string; pubDate: string; is_approved: boolean; is_certified: boolean; video_count: number; views: number; revenue: number; pendingRevenue: number; }[]>([]); const [channelList, setChannelList] = useState<{ id: string; handle: string; createtime: string; is_approved: boolean; icon: string; }[]>([]); const [registerCode, setRegisterCode] = useState(""); const handleInputRef = useRef(null); const formatNumberWithCommas = (number: number): string => { return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }; const get_code = async () => { if (handleInputRef.current && handleInputRef.current.value) { const inputValue = handleInputRef.current.value; if (confirm(`핸들 "${inputValue}" 의 등록 코드를 발급하시겠습니까?`)) { try { const response = await fetch(`/api/channel_code?handle=${inputValue}`); if (response.status === 409) { alert("이미 등록된 요청입니다. 기존 코드를 사용합니다."); const data = await response.json(); setRegisterCode(data.randomcode); return; } if (!response.ok) { throw new Error('서버 응답이 올바르지 않습니다.'); } const data = await response.json(); setRegisterCode(data.randomcode); } catch (error) { console.error('채널 코드 요청 중 오류 발생:', error); alert('채널 코드를 가져오는데 실패했습니다. 다시 시도해주세요.'); return; } return; } } else{ alert("채널 핸들을 입력해주세요"); } } const register_channel = async () => { if (handleInputRef.current && handleInputRef.current.value) { const inputValue = handleInputRef.current.value; try { const response = await fetch(`/api/register_channel?handle=${encodeURIComponent(inputValue)}`); const data = await response.json(); if (!response.ok) { alert(data?.error ?? '등록 요청 실패'); return; } alert('등록 요청을 전송했습니다.'); setIsreqmodal(false); } catch (error) { console.error('등록 요청 중 오류:', error); alert('등록 요청 실패'); } } else { alert("채널 핸들을 입력해주세요"); } } const fetchListChannel = async () => { try { const resp = await fetch('/api/list_channel', { cache: 'no-store' }); const data = await resp.json(); setChannelList(data.items); console.log('list_channel:', data); } catch (e) { console.error('list_channel 요청 에러:', e); } } useEffect(() => { // 세션 이메일 기준 채널 목록 조회 로그 fetchListChannel(); }, []); return (
{setIsreqmodal(true); setRegisterCode("")}} > 채널 등록
{ channelList.map((channel)=>{ return ( ) })}
채널 핸들 등록 날짜 승인여부 영상수 조회수 예상수익
channel icon
{channel.handle}
{channel.createtime.split("T")[0]} {channel.is_approved? "승인" : "미승인"} - - -
setIsreqmodal(false)}>
채널등록
setIsreqmodal(false)}>
핸들
get_code()}> 코드 발급
채널 등록 코드
{registerCode ? registerCode : "코드를 발급해주세요"}
{registerCode && (
{ navigator.clipboard.writeText(registerCode); }} >
)}
register_channel()}> 채널 등록
); }