diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index ed16d78..28ad448 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -37,7 +37,7 @@ const deck = JSON_APIS({ /* deck Creations: Upload a deck of cards */ // Todo : change to session createDeck: ({ createDeckDto }: { createDeckDto: CreateDeckDto }) => - client.public.post<{ deck_id: string }>('decks', createDeckDto), + client.public.post<{ result: { deck_id: string } }>('decks', createDeckDto), /* get Deck: Get card information by deck id */ // Todo : change to session getDeck: ({ id }: { id: string }) => client.public.get<{ result: Deck | null }>(`decks/id=${id}`), diff --git a/packages/service-frontend/app/complete/page.tsx b/packages/service-frontend/app/complete/page.tsx index f09faa3..5c93898 100644 --- a/packages/service-frontend/app/complete/page.tsx +++ b/packages/service-frontend/app/complete/page.tsx @@ -1,7 +1,7 @@ 'use client' import Lottie from 'lottie-react' -import { useRouter } from 'next/navigation' +import { useRouter, useSearchParams } from 'next/navigation' import { Button } from '@ppoba/ui' import addDeckLottie from '@/public/lottie/addDeckLottie.json' @@ -10,10 +10,11 @@ import { Header } from '../components/common' export default function DeckCreateCompletePage(): JSX.Element { const router = useRouter() - + const searchParams = useSearchParams() + const deckId = searchParams.get('deckId') + const handleClick = () => { - // TODO: 실제 덱 아이디를 받아서 이동하도록 수정 - router.push('/deck/1') + router.push(`/deck/${deckId}`) } return ( diff --git a/packages/service-frontend/app/confirm-detail/page.tsx b/packages/service-frontend/app/confirm-detail/page.tsx index bed9c56..e833939 100644 --- a/packages/service-frontend/app/confirm-detail/page.tsx +++ b/packages/service-frontend/app/confirm-detail/page.tsx @@ -1,10 +1,15 @@ 'use client' import { useState, type JSX, useCallback } from 'react' +import { useMutation } from '@tanstack/react-query' import { useRouter } from 'next/navigation' +import { useRecoilState } from 'recoil' +import { api } from '@ppoba/api' +import { DeckCategory } from '@ppoba/types/src/dto/createDeckDto' import { Icon, Button } from '@ppoba/ui' import { Header } from '@/app/components' +import { deckFormAtomState } from '@/store/deck' import GameKeywordBox from './GameKeywordBox' @@ -20,19 +25,46 @@ const INITIAL_KEYWORDS = [ ] export default function ConfirmDetailPage(): JSX.Element { - const [keywords, setKeywords] = useState(INITIAL_KEYWORDS) const [isAdultGame, setIsAdultGame] = useState(false) - const [selectedKeywords, setSelectedKeywords] = useState([]) - + const [deck, setDeck] = useRecoilState(deckFormAtomState); const router = useRouter() + const { mutate } = useMutation(api.deck.createDeck, { + onSuccess: (data) => { + const cardList = deck.cardList.filter((card) => card?.content !== undefined); + createCardMutate({ + createCardDto: { + deckId: data.result.deck_id, + cardList: cardList, + } + }) + }, + onError: (error) => { + console.log('error', error) + } + }); + const { mutate: createCardMutate } = useMutation(api.card.createCard, { + onSuccess: (_, variables) => { + const deckId = variables.createCardDto.deckId; + router.push(`/complete?deckId=${deckId}`) + }, + onError: (error) => { + console.log('error', error) + } + }); const handleClick = () => { - router.push('/complete') + mutate({ + createDeckDto: { + name: deck.name, + userId: "2931028309", // TODO: 실제 user id 넣기 + category: deck.category as DeckCategory[], + } + }); } const handleClickKeyword = useCallback( (keyword: string) => { - const nextSelectedKeywords = [...selectedKeywords] + const nextSelectedKeywords = [...deck.category] const targetIndex = nextSelectedKeywords.findIndex( item => item === keyword, ) @@ -40,12 +72,12 @@ export default function ConfirmDetailPage(): JSX.Element { if (targetIndex !== -1) { // 기존에 선택했던 키워드라면 제거한다. nextSelectedKeywords.splice(targetIndex, 1) - setSelectedKeywords(nextSelectedKeywords) + setDeck({ ...deck, category: nextSelectedKeywords }) } else { - setSelectedKeywords([...nextSelectedKeywords, keyword]) + setDeck({ ...deck, category: [...nextSelectedKeywords, keyword] }) } }, - [selectedKeywords], + [deck.category], ) return ( @@ -63,8 +95,8 @@ export default function ConfirmDetailPage(): JSX.Element { {/* 키워드 선택 */} setIsAdultGame(prev => !prev)} @@ -75,7 +107,7 @@ export default function ConfirmDetailPage(): JSX.Element { size="large" rightIcon="goWhite" className="transition-all" - disabled={selectedKeywords.length === 0 && !isAdultGame} + disabled={deck.category.length === 0 && !isAdultGame} onClick={handleClick} > 업로드 하자 diff --git a/packages/service-frontend/app/create-deck/page.tsx b/packages/service-frontend/app/create-deck/page.tsx index 8e915eb..54b4d12 100644 --- a/packages/service-frontend/app/create-deck/page.tsx +++ b/packages/service-frontend/app/create-deck/page.tsx @@ -2,6 +2,7 @@ import React, { useState, useRef } from 'react' import { useRouter } from 'next/navigation' +import { useRecoilState } from 'recoil' import { Scrollbar } from 'swiper' import { Swiper, SwiperSlide } from 'swiper/react' import { Button, Icon, SecondaryButton } from '@ppoba/ui' @@ -11,6 +12,7 @@ import 'swiper/css/scrollbar' import { Header } from '@/app/components' import { CardStyle } from '@/app/deck/[id]/play/constant' +import { deckFormAtomState } from '@/store/deck' // DUMMY DATA const DUMMY_DATA = ['1', '2', '3', '4', '5'] @@ -21,7 +23,7 @@ const bgColors: string[] = Object.values(CardStyle).map( ) export default function CreateDeck(): JSX.Element { - const [text, setText] = useState('') + const [deck, setDeck] = useRecoilState(deckFormAtomState); const router = useRouter() const handleClick = () => { @@ -59,10 +61,22 @@ export default function CreateDeck(): JSX.Element { }`} >