diff --git a/src/apis/createTales.ts b/src/apis/createTales.ts index 4fd63e5..7baf890 100644 --- a/src/apis/createTales.ts +++ b/src/apis/createTales.ts @@ -25,6 +25,7 @@ export const createKeyword = async (body: FormData): Promise => { alert( "이미지 화질이 안좋거나, 추출된 키워드가 없습니다. 다시 이미지를 업로드하세요!" ); + window.location.href = "/createTale"; throw error; } }; diff --git a/src/components/common/tabBar/TabBar.tsx b/src/components/common/tabBar/TabBar.tsx index e1d5843..9f76974 100644 --- a/src/components/common/tabBar/TabBar.tsx +++ b/src/components/common/tabBar/TabBar.tsx @@ -13,7 +13,7 @@ const TabBar = () => { label: "동화만들기", path: "/createTale", }, - { id: 3, icon: "/learnIcon.png", label: "학습하기", path: "/learning" }, + { id: 3, icon: "/learnIcon.png", label: "학습하기", path: "/learnTale" }, ]; const selectedTab = diff --git a/src/components/learn/CreateQuiz.tsx b/src/components/learn/CreateQuiz.tsx index e13abca..9d9b28d 100644 --- a/src/components/learn/CreateQuiz.tsx +++ b/src/components/learn/CreateQuiz.tsx @@ -6,17 +6,25 @@ import { useNavigate } from "react-router-dom"; interface CreateQuizProps { languageTaleId: number; learningLevel: string; + taleId: number; } const CreateQuiz = (props: CreateQuizProps) => { const navigate = useNavigate(); useEffect(() => { const createData = async () => { - const response = await createQuiz({ - languageTaleId: props.languageTaleId, - learningLevel: props.learningLevel, - }); - if (response.result === "SUCCESS") - navigate(`/learnTale/${props.languageTaleId}`); + try { + const response = await createQuiz({ + languageTaleId: props.languageTaleId, + learningLevel: props.learningLevel, + }); + if (response.result === "SUCCESS") + navigate(`/learnTale/quiz`, { state: props.languageTaleId }); + else throw new Error(); + } catch (error) { + alert("퀴즈 생성 중 에러가 발생했습니다. 다시 시도해주세요."); + const response = { taleId: props.taleId }; + navigate(`/readTale`, { state: { response } }); + } }; createData(); }, [props]); diff --git a/src/components/learn/PreLearningQuestion.tsx b/src/components/learn/PreLearningQuestion.tsx index 96493d8..0fa157b 100644 --- a/src/components/learn/PreLearningQuestion.tsx +++ b/src/components/learn/PreLearningQuestion.tsx @@ -67,7 +67,7 @@ const PreLearningQuestion = () => { if (userInfo?.learningLevel !== null) { setSelectedLevel(userInfo.learningLevel); if (userInfo.isLearned === "YES") { - navigate(`/learnTale/${userInfo.languageTaleId}`); + navigate(`/learnTale/quiz`, { state: userInfo.languageTaleId }); } else { setStep(2); } @@ -111,6 +111,7 @@ const PreLearningQuestion = () => { )} @@ -142,4 +143,4 @@ const Wrapper = styled.div` overflow: scroll; height: fit-content; padding-bottom: 2rem; -`; \ No newline at end of file +`; diff --git a/src/components/tales/createMain/SelectOption/InputImg.tsx b/src/components/tales/createMain/SelectOption/InputImg.tsx index 21b839d..8be7ed0 100644 --- a/src/components/tales/createMain/SelectOption/InputImg.tsx +++ b/src/components/tales/createMain/SelectOption/InputImg.tsx @@ -14,7 +14,7 @@ const InputImg = ({ setIsLoading }: InputImgProps) => { formData.append("file", file); if (setIsLoading) setIsLoading(true); const keywords: string[] = await createKeyword(formData); - navigate("/selectKeyword", { state: { keywords } }); + navigate("/createTale/keyword", { state: { keywords } }); } }; return ( diff --git a/src/components/tales/createMain/SelectOption/SelectOption.tsx b/src/components/tales/createMain/SelectOption/SelectOption.tsx index 8b45f8d..5e78877 100644 --- a/src/components/tales/createMain/SelectOption/SelectOption.tsx +++ b/src/components/tales/createMain/SelectOption/SelectOption.tsx @@ -24,7 +24,7 @@ const SelectOption = ({ text, imgURL, setIsLoading }: SelectOptionProps) => { { - navigate("/taleDetail"); + navigate("/createTale/details"); }} > diff --git a/src/components/tales/createTale/CreateTale.tsx b/src/components/tales/createTale/CreateTale.tsx index b33a86c..b32437c 100644 --- a/src/components/tales/createTale/CreateTale.tsx +++ b/src/components/tales/createTale/CreateTale.tsx @@ -11,8 +11,13 @@ const CreateTale = () => { useEffect(() => { const createData = async () => { - const response = await createTale(requestData); - navigate(`/readTale`, { state: { response } }); + try { + const response = await createTale(requestData); + navigate(`/readTale`, { state: { response } }); + } catch (error) { + alert("동화 생성 중 에러가 발생했습니다. 다시 시도해주세요."); + navigate(`/createTale`); + } }; createData(); }, [requestData]); diff --git a/src/components/tales/readTale/ReadTale.tsx b/src/components/tales/readTale/ReadTale.tsx index f1b08d2..49fc5dc 100644 --- a/src/components/tales/readTale/ReadTale.tsx +++ b/src/components/tales/readTale/ReadTale.tsx @@ -102,7 +102,7 @@ const ReadTale = () => { isActive={true} text="학습하기" handleBtn={() => { - navigate(`/learnTale`, { + navigate(`/learnTale/pre`, { state: { taleId: response.taleId }, }); }} diff --git a/src/components/tales/selectKeyword/SelectKeyword.tsx b/src/components/tales/selectKeyword/SelectKeyword.tsx index 5c7413a..ddf81f4 100644 --- a/src/components/tales/selectKeyword/SelectKeyword.tsx +++ b/src/components/tales/selectKeyword/SelectKeyword.tsx @@ -42,7 +42,7 @@ const SelectKeyword = () => { const selectKeywords = selectedKeywordIndices.map( (index) => keywords[index] ); - navigate("/taleDetail", { state: { selectKeywords } }); + navigate("/createTale/details", { state: { selectKeywords } }); }; return ( <> diff --git a/src/components/tales/taleDetail/TaleDetail.tsx b/src/components/tales/taleDetail/TaleDetail.tsx index 0eb6e65..0a65216 100644 --- a/src/components/tales/taleDetail/TaleDetail.tsx +++ b/src/components/tales/taleDetail/TaleDetail.tsx @@ -73,7 +73,7 @@ const TaleDetail = () => { : [getRandomElement(charElements).value], contents: contents || getRandomElement(contentElements).value, }; - navigate("/create", { state: { requestData } }); + navigate("/createTale/generate", { state: { requestData } }); }; return ( diff --git a/src/pages/TaleLearnPage.tsx b/src/pages/TaleLearnPage.tsx index 359aa09..6110c3a 100644 --- a/src/pages/TaleLearnPage.tsx +++ b/src/pages/TaleLearnPage.tsx @@ -1,12 +1,13 @@ import { useEffect, useState } from "react"; -import { useParams } from "react-router-dom"; +import { useLocation } from "react-router-dom"; import { getQuizAndAnswer } from "@apis/learning"; import TaleLearn from "@components/learn/TaleLearn"; import styled from "styled-components"; const TaleLearnPage = () => { const [quizData, setQuizData] = useState(); - const { id } = useParams(); + const location = useLocation(); + const id = location.state || {}; useEffect(() => { const getQuiz = async (taleId: number) => { @@ -22,7 +23,7 @@ const TaleLearnPage = () => { } }; - if (id) getQuiz(Number(id)); + if (id) getQuiz(id); }, [id]); return ( diff --git a/src/router.tsx b/src/router.tsx index 3530219..1aee51a 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -13,6 +13,7 @@ import CreateTalePage from "@pages/CreateTalePage"; import TaleLearnPage from "@pages/TaleLearnPage"; import PreLearningQuestionPage from "@pages/PreLearningQuestionPage"; import MoreRecentTales from "@components/home/homeRecentTales/MoreRecentTales"; +import PrivateRoute from "@utils/PrivateRoute"; const router = createBrowserRouter([ { @@ -23,53 +24,53 @@ const router = createBrowserRouter([ path: "/login", element: , }, + { + path: "/kakao", + element: , + }, { path: "/onboarding", - element: , + element: } />, }, { path: "/home", - element: , + element: } />, }, { path: "/more", - element: , - }, - { - path: "/createTale", - element: , + element: } />, }, { - path: "/kakao", - element: , + path: "/learnTale", + element: } />, }, { - path: "/learning", - element: , + path: "/createTale", + element: } />, }, { - path: "/selectKeyword", - element: , + path: "/createTale/keyword", + element: } />, }, { - path: "/taleDetail", - element: , + path: "/createTale/details", + element: } />, }, { - path: "/create", - element: , + path: "/createTale/generate", + element: } />, }, { path: "/readTale", - element: , + element: } />, }, { - path: "/learnTale", - element: , + path: "/learnTale/pre", + element: } />, }, { - path: "/learnTale/:id", - element: , + path: "/learnTale/quiz", + element: } />, }, ]); diff --git a/src/utils/defaultData.ts b/src/utils/defaultData.ts index c393419..f5ca6d5 100644 --- a/src/utils/defaultData.ts +++ b/src/utils/defaultData.ts @@ -1,12 +1,7 @@ import { DropdownElement } from "@type/dropdown"; import { ColorSet } from "@type/selectList"; -export const commonLanguageElements: DropdownElement[] = [ - { - imgURL: `/korea.png`, - text: "한국어", - value: 2, - }, +export const baseLanguageElements: DropdownElement[] = [ { imgURL: `/america.png`, text: "영어", @@ -23,13 +18,21 @@ export const commonLanguageElements: DropdownElement[] = [ value: 4, }, ]; +export const commonLanguageElements: DropdownElement[] = [ + { + imgURL: `/korea.png`, + text: "한국어", + value: 2, + }, + ...baseLanguageElements, +]; export const nationElements: DropdownElement[] = [ { text: "선택해주세요", value: null, }, - ...commonLanguageElements, + ...baseLanguageElements, ]; export const moodElements: DropdownElement[] = [