From 453e5bae43b8a72513a4f309944c1552760337b2 Mon Sep 17 00:00:00 2001 From: ryanbae94 Date: Tue, 21 May 2024 23:19:50 +0900 Subject: [PATCH] =?UTF-8?q?[feat/#482]=20:sparkles:=20feat:=20=EA=B8=B0?= =?UTF-8?q?=EC=A1=B4=20=ED=80=B4=EC=A6=88=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/app/(game)/_components/AuthCheck.tsx | 4 + .../_components/DropBox/DropBox.tsx | 53 +++++++----- .../create-room/_components/FileUploadBox.tsx | 2 +- chatty-fe/src/app/(game)/create-room/page.tsx | 80 ++++++++++++++++--- chatty-fe/src/app/_api/createRoom.ts | 30 +++++-- 5 files changed, 134 insertions(+), 35 deletions(-) diff --git a/chatty-fe/src/app/(game)/_components/AuthCheck.tsx b/chatty-fe/src/app/(game)/_components/AuthCheck.tsx index c2c34b0d7..2aee71ddb 100644 --- a/chatty-fe/src/app/(game)/_components/AuthCheck.tsx +++ b/chatty-fe/src/app/(game)/_components/AuthCheck.tsx @@ -58,5 +58,9 @@ export default function AuthCheck({ children }: AuthCheckProps) { } }, [accessToken, id]); + useEffect(() => { + console.log('set token:', accessToken); + }, [accessToken]); + return <>{children}; } diff --git a/chatty-fe/src/app/(game)/create-room/_components/DropBox/DropBox.tsx b/chatty-fe/src/app/(game)/create-room/_components/DropBox/DropBox.tsx index 00131d05a..a040587bf 100644 --- a/chatty-fe/src/app/(game)/create-room/_components/DropBox/DropBox.tsx +++ b/chatty-fe/src/app/(game)/create-room/_components/DropBox/DropBox.tsx @@ -1,27 +1,42 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import * as styles from './DropBox.css'; import Image from 'next/image'; +type ExistQuiz = { + quizDocId: string; + description: string; + numberOfQuiz: number; +}; -const List = [ - { id: 1, name: '1번 문제 리스트' }, - { id: 2, name: '2번 문제 리스트' }, - { id: 3, name: '3번 문제 리스트' }, - { id: 4, name: '4번 문제 리스트' }, - { id: 5, name: '5번 문제 리스트' }, - { id: 6, name: '6번 문제 리스트' }, - { id: 7, name: '7번 문제 리스트' }, - { id: 8, name: '8번 문제 리스트' }, -]; - -export default function DropBox() { +type DropBoxProps = { + List: ExistQuiz[]; + setNumberOfProblems: (numberOfProblems: number) => void; + selectedList: string | null; + setSelectedList: (selectedList: string | null) => void; +}; +export default function DropBox({ + List, + setNumberOfProblems, + selectedList, + setSelectedList, +}: DropBoxProps) { const [isOpen, setIsOpen] = useState(false); - const [selected, setSelected] = useState(''); + const [quizList, setQuizList] = useState([]); + useEffect(() => { + setQuizList(List); + }, []); + useEffect(() => { + console.log('quizList:', quizList); + }, [quizList]); + const handleSelected = (selected: string, numberOfProblems: number) => { + setSelectedList(selected); + setNumberOfProblems(numberOfProblems); + }; return (
setIsOpen(!isOpen)}> - - {selected || '문제를 선택해주세요.'} + + {selectedList || '문제를 선택해주세요.'}
@@ -164,7 +221,12 @@ export default function CreateRoom() { setQuestionType={setQuestionType} /> {qustionType === 'list' ? ( - + ) : ( )} diff --git a/chatty-fe/src/app/_api/createRoom.ts b/chatty-fe/src/app/_api/createRoom.ts index d7b2d087e..095b828d9 100644 --- a/chatty-fe/src/app/_api/createRoom.ts +++ b/chatty-fe/src/app/_api/createRoom.ts @@ -7,15 +7,17 @@ export const postRoom = async ( description: string, numOfQuiz: number, playerLimitNum: number, - files: File[], + files?: File[] | null, + existDocId?: string | null, ) => { try { - const formData: any = new FormData(); + const formData = new FormData(); formData.append('name', name); formData.append('description', description); formData.append('numOfQuiz', String(numOfQuiz)); formData.append('playerLimitNum', String(playerLimitNum)); - formData.append('files', files[0], files[0].name); + if (files) formData.append('files', files[0], files[0].name); + if (existDocId) formData.append('existQuizDocId', existDocId); const response = await client.post('/rooms', formData, { headers: { @@ -24,18 +26,34 @@ export const postRoom = async ( }, }); + if (!response || !response.data) { + throw new Error('응답이 유효하지 않습니다.'); + } + console.log(response.data); return response.data; } catch (error: any) { - if (error.response.data.exceptionCode > 1000) + console.error('API 호출 중 오류 발생:', error); + if ( + error.response && + error.response.data && + error.response.data.exceptionCode > 1000 + ) { throw new Error(error.response.data.message); - else throw new Error('오류가 발생했습니다.'); + } else { + throw new Error('오류가 발생했습니다.'); + } } }; export const getExistQuiz = async () => { try { - const response = await client.get('/rooms/existQuiz'); + const response = await client.get('/rooms/existQuiz', { + headers: { + Authorization: `Bearer ${useAuthStore.getState().accessToken} `, + }, + }); + console.log(response); console.log(response.data); return response.data; } catch (error: any) {