From 18a11448118d9e0a9d9c4cedf36d94dab2358c6c Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 8 Mar 2024 16:42:17 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EB=A6=AC=EB=B7=B0=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20?= =?UTF-8?q?=EB=82=98=EC=98=A4=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=98=84?= =?UTF-8?q?=EC=83=81=20(#107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ji Hyeong Lee <115636461+Jihyeong00@users.noreply.github.com> --- .../review/review-modal/MyReviewModal.tsx | 24 ++++++----- .../review-modal/ReviewRegisterModal.tsx | 43 +++++++++++-------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/app/_components/review/review-modal/MyReviewModal.tsx b/src/app/_components/review/review-modal/MyReviewModal.tsx index 0e52d4c0..2a7bf1d2 100644 --- a/src/app/_components/review/review-modal/MyReviewModal.tsx +++ b/src/app/_components/review/review-modal/MyReviewModal.tsx @@ -9,13 +9,14 @@ import { useEffect } from 'react'; import NotSearched from '@/app/service/community/_components/NotSearched'; import ReviewModalSkeleton from './ReviwModalSkeleton'; import OneReview from './OneReview'; +import ReviewRegisterModal from './ReviewRegisterModal'; /** * @description 지도 위에 띄위기 위해서 Modal로 구현을 합니다. * @param position 어느 방향에서 모달이 열릴지 결정합니다. */ function MyReviewModal({ openPosition }: ReviewProps) { - const { isOpen, reset, state } = useReviewStore(state => state); + const { isOpen, reset } = useReviewStore(state => state); const { data, mutate, size, setSize, isLoading, isValidating } = useReviewApi.useGetMyReviews(); @@ -60,14 +61,15 @@ function MyReviewModal({ openPosition }: ReviewProps) { } return ( -
-
- - 내가 작성한 리뷰 -
- {state === 'mypage' && ( + <> + +
+
+ + 내가 작성한 리뷰 +
{reviews[0].data.data.cursor !== -2 ? ( reviews @@ -79,8 +81,8 @@ function MyReviewModal({ openPosition }: ReviewProps) { )}
- )} -
+
+ ); } diff --git a/src/app/_components/review/review-modal/ReviewRegisterModal.tsx b/src/app/_components/review/review-modal/ReviewRegisterModal.tsx index 095ce83d..963ee1bd 100644 --- a/src/app/_components/review/review-modal/ReviewRegisterModal.tsx +++ b/src/app/_components/review/review-modal/ReviewRegisterModal.tsx @@ -1,6 +1,6 @@ 'use client'; -import React, { useEffect, useMemo, useState } from 'react'; +import React, { ChangeEvent, useEffect, useMemo, useState } from 'react'; import { zodResolver } from '@hookform/resolvers/zod'; import { useForm } from 'react-hook-form'; import { Button } from '@/app/_components/ui/button'; @@ -12,7 +12,7 @@ import * as F from '@/app/_components/ui/form'; import { X } from 'lucide-react'; import useReviewStore from '@/store/review/reviewStore'; import { aBeeZee } from '@/styles/fonts'; -import { Rating, Skeleton } from '@mui/material'; +import { Rating } from '@mui/material'; import { getFormData } from '@/utils/getFormData'; import reviewApi from '@/apis/review/apis/review'; import { cn } from '@/lib/utils'; @@ -31,9 +31,8 @@ function ReviewRegisterModal({ gym_name, mutate }: ReviewRegisterProps) { fixId: -1, }; const [images, setImages] = useState([]); - const [registerValue, setRegisterValue] = useState( - () => initialValue, - ); + const [registerValue, setRegisterValue] = + useState(initialValue); const { newContent, newScore, fixId } = registerValue; @@ -68,11 +67,14 @@ function ReviewRegisterModal({ gym_name, mutate }: ReviewRegisterProps) { } }, [state]); - const onSubmit = async (d: ReviewSchemaType) => { - if (reviewId === null) return; + const onChange = (e: ChangeEvent) => { + setRegisterValue(prev => ({ ...prev, newContent: e.target.value })); + }; + + const onSubmit = async () => { let data: SubmitReviewType = { score: newScore, - content: d.content || '', + content: newContent, }; switch (state) { @@ -86,16 +88,22 @@ function ReviewRegisterModal({ gym_name, mutate }: ReviewRegisterProps) { break; } case 'create': { + if (!reviewId) return; + data = { ...data, gym_id: reviewId, }; + const formData = getFormData({ jsonData: JSON.stringify(data), images, }); + await reviewApi.postReview(formData); + mutate(); + break; } default: @@ -104,23 +112,26 @@ function ReviewRegisterModal({ gym_name, mutate }: ReviewRegisterProps) { closeMode(); }; - const RegisterContent = useMemo(() => { + const registerContent = useMemo(() => { switch (state) { case 'create': { return { header: '리뷰 작성', + title: gym_name ?? '', submit: '작성 완료', }; } case 'fix': { return { - header: '리뷰 작성', + header: '리뷰 수정', + title: gym_name ?? '나의 리뷰 수정', submit: '작성 완료', }; } default: { return { header: null, + title: null, submit: null, }; } @@ -133,16 +144,12 @@ function ReviewRegisterModal({ gym_name, mutate }: ReviewRegisterProps) { - {RegisterContent.header} + {registerContent.header}
- {typeof gym_name !== 'undefined' ? ( - `${gym_name}` - ) : ( - - )} + {registerContent.title}
@@ -192,7 +199,7 @@ function ReviewRegisterModal({ gym_name, mutate }: ReviewRegisterProps) {