From b2e16cdac5d1a606e646cf949abd9086f76622a9 Mon Sep 17 00:00:00 2001 From: 2paperstar Date: Fri, 16 Feb 2024 06:17:33 +0900 Subject: [PATCH] feat: upload review --- src/pages/ReviewRegistration.tsx | 93 +++++++++++++++++++------------- 1 file changed, 57 insertions(+), 36 deletions(-) diff --git a/src/pages/ReviewRegistration.tsx b/src/pages/ReviewRegistration.tsx index 46dc181..35ac15f 100644 --- a/src/pages/ReviewRegistration.tsx +++ b/src/pages/ReviewRegistration.tsx @@ -1,44 +1,38 @@ -import React, { useState } from 'react'; -import Header from './component/Header'; +import { useQuery } from '@tanstack/react-query'; +import { useState } from 'react'; +import { createPortal } from 'react-dom'; import { FaLocationArrow } from 'react-icons/fa'; -import { Link } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; +import api from '../api'; import GStar from '../assets/GStar.png'; import YStar from '../assets/YStar.png'; -import Input from './component/Input'; import Btn from './component/Btn'; -import { createPortal } from 'react-dom'; -import { useQuery } from '@tanstack/react-query'; +import Header from './component/Header'; +import Input from './component/Input'; + +const withs = ['혼자', '가족', '연인', '친구', '부모님', '모임']; +const tags = [ + '맛집', + '디저트', + '데이트코스', + '교육적인', + '추억만들기', + '대전의 명물', + '감성적인', + '가족적인', + '혼자서도 좋아요', + '과학', + '여가', +]; export default function ReviewRegistration() { + const navigate = useNavigate(); const [star, setStar] = useState(1); const [selectedCategories, setSelectedCategories] = useState([ '맛집', '혼자', ]); - const [category, setCategory] = useState([ - '혼자', - '가족', - '연인', - '친구', - '부모님', - '모임', - ]); - const [category2, setCategory2] = useState([ - '맛집', - '디저트', - '데이트코스', - '교육적인', - '추억만들기', - '대전의 명물', - '감성적인', - '가족적인', - '혼자서도 좋아요', - '과학', - '여가', - ]); - const handleStarClick = (number: number) => { - setStar(number); - }; + const handleCategoryClick = (category: string) => { if (selectedCategories.includes(category)) { setSelectedCategories( @@ -56,6 +50,23 @@ export default function ReviewRegistration() { enabled: !!search, }); const [place, setPlace] = useState<{ id: string; placeName: string }>(); + const [file, setFile] = useState(); + const [content, setContent] = useState(''); + + const submit = async () => { + const fd = new FormData(); + fd.append('file', file as Blob); + const uploadRes = await api.post<{ token: string }>('/files/videos', fd); + const result = await api.post('/reviews', { + placeId: place?.id, + videoToken: uploadRes.data.token, + stars: star, + with: selectedCategories.filter((cat) => withs.includes(cat)), + tags: selectedCategories.filter((cat) => tags.includes(cat)), + content, + }); + navigate(`/review/${result.data.id}`); + }; return (
@@ -93,6 +104,7 @@ export default function ReviewRegistration() { {searchData?.data.documents.map((place: any) => (
  • -

    4.0

    +

    {star.toFixed(1)}

  • @@ -170,7 +188,7 @@ export default function ReviewRegistration() {

    누구와 방문하면 좋을 것 같나요?

    - {category.map((e, index) => ( + {withs.map((e, index) => (
    - 등록하기 + + 등록하기 +
    );