Skip to content

Commit

Permalink
Merge pull request #258 from FinalDoubleTen/FE-103--feat/Refactor/1st
Browse files Browse the repository at this point in the history
Fe 103  feat/refactor/1st
  • Loading branch information
seungjun222 authored Jan 24, 2024
2 parents 456e13e + 07a0db4 commit 435f9a4
Show file tree
Hide file tree
Showing 22 changed files with 134 additions and 114 deletions.
1 change: 1 addition & 0 deletions src/@types/detail.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
interface tourDetail {
id: number;
contentTypeId: number;
title: string;
liked: boolean;
fullAddress: string;
Expand Down
28 changes: 22 additions & 6 deletions src/@types/review.types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
interface ReviewRequest {
tourItemId: number;
rating: number;
keywords: Keyword[];
export interface Keyword {
keywordId: number;
content: string;
type: string;
}

interface Keyword {
keywordId: number;
export interface CommentItemProps {
commentId: number;
authorNickname: string;
authorProfileImageUrl: string;
createdTime: string;
content: string;
onClick?: () => void;
isAuthor: boolean;
}

export interface MyReviewContent {
reviewId: number;
authorNickname: string;
authorProfileImageUrl: string;
rating: number;
createdTime: string;
content: string;
keywords: Keyword[];
commentCount: number;
isAuthor?: boolean;
}
22 changes: 22 additions & 0 deletions src/@types/tours.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,25 @@ export interface LikedListType {
preferTotalCount: number;
notPreferTotalCount: number;
}

export interface ReviewInfoItemProps {
reviewId: number;
authorNickname: string;
authorProfileImageUrl: string;
rating: number;
createdTime: string;
content: string;
keywords: Keyword[]; // keywordId, content, type
commentCount: number;
onClick?: () => void;
tourItemId?: number;
contentTypeId?: number;
canTextOverflow: boolean;
isAuthor?: boolean;
}

interface Keyword {
keywordId: number;
content: string;
type: string;
}
10 changes: 10 additions & 0 deletions src/@types/trips.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ interface AuthorityType {
tripId: string;
};
}
interface TripSurveySetMemberInfo {
memberId: number;
nickname: string;
thumbnail: string;
}

interface TripMemeberInfo {
nickname: string;
profileImageUrl: string;
}
2 changes: 1 addition & 1 deletion src/api/review.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from './client';
import authClient from './authClient';

import { ReviewRequest } from '@recoil/review';
// 리뷰 관련 API

// 리뷰수정
Expand Down
53 changes: 28 additions & 25 deletions src/components/DetailSectionBottom/DetailReviews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import ToastPopUp from '@components/common/toastpopup/ToastPopUp';
import EditDelete from '@components/common/modal/children/EditDelete';
import MyAlert from '@components/common/modal/children/MyAlert';
import { alertTypeState } from '@recoil/modal';
import { ReviewInfoItemProps } from '@/@types/tours.types';

interface reviewProps {
reviewData: any;
}

export default function DetailReviews({ reviewData }: reviewProps) {
export default function DetailReviews({
reviewData,
}: {
reviewData: tourDetail;
}) {
const [reviewDataLength, setReviewDataLength] = useState<number>(0);
const { title, contentTypeId } = reviewData;
const params = useParams();
Expand Down Expand Up @@ -73,7 +74,7 @@ export default function DetailReviews({ reviewData }: reviewProps) {
return <div>데이터를 불러오는 중 오류가 발생했습니다.</div>;
}

const handleReviewClick = (item: any) => {
const handleReviewClick = (item: ReviewInfoItemProps) => {
const reviewId = item.reviewId;
navigate(`/reviewComment/${reviewId}`, { state: { item, tourItemId } });
};
Expand Down Expand Up @@ -155,24 +156,26 @@ export default function DetailReviews({ reviewData }: reviewProps) {
{
return (
<React.Fragment key={index}>
{group?.data.data.reviewInfos.content.map((item: any) => (
<ReviewItem
key={item.reviewId}
reviewId={item.reviewId}
authorNickname={item.authorNickname}
authorProfileImageUrl={item.authorProfileImageUrl}
rating={item.rating}
createdTime={item.createdTime}
content={item.content}
keywords={item.keywords}
commentCount={item.commentCount}
onClick={() => handleReviewClick(item)}
tourItemId={tourItemId}
contentTypeId={contentTypeId}
canTextOverflow={true}
isAuthor={item.isAuthor}
/>
))}
{group?.data.data.reviewInfos.content.map(
(item: ReviewInfoItemProps) => (
<ReviewItem
key={item.reviewId}
reviewId={item.reviewId}
authorNickname={item.authorNickname}
authorProfileImageUrl={item.authorProfileImageUrl}
rating={item.rating}
createdTime={item.createdTime}
content={item.content}
keywords={item.keywords}
commentCount={item.commentCount}
onClick={() => handleReviewClick(item)}
tourItemId={tourItemId}
contentTypeId={contentTypeId}
canTextOverflow={true}
isAuthor={item.isAuthor}
/>
),
)}
</React.Fragment>
);
}
Expand All @@ -187,7 +190,7 @@ export default function DetailReviews({ reviewData }: reviewProps) {
{modalChildren === 'MyAlert' && alertType === 'LoginReview' && (
<MyAlert
title="로그인"
content="리뷰 쓰기 시 로그인이 필요해요. 로그인하시겠어요?"
content="리뷰를 쓰려면 로그인이 필요해요. 로그인하러 가볼까요?"
/>
)}
</Modal>
Expand Down
25 changes: 2 additions & 23 deletions src/components/DetailSectionBottom/ReviewItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,9 @@ import {
import { MouseEvent, useState } from 'react';
import { getEmoji } from '@utils/utils';
import { getStarFill } from '@utils/getStarFill';
import { ReviewInfoItemProps } from '@/@types/tours.types';

interface Keyword {
keywordId: number;
content: string;
type: string;
}

interface ItemProps {
reviewId: number;
authorNickname: string;
authorProfileImageUrl: string;
rating: number;
createdTime: any;
content: string;
keywords: Keyword[]; // keywordId, content, type
commentCount: number;
onClick?: () => void;
tourItemId?: number;
contentTypeId?: number;
canTextOverflow: boolean;
isAuthor?: boolean;
}

const Item: React.FC<ItemProps> = (props: ItemProps) => {
const Item: React.FC<ReviewInfoItemProps> = (props: ReviewInfoItemProps) => {
const {
reviewId,
authorNickname,
Expand Down
10 changes: 5 additions & 5 deletions src/components/DetailSectionTop/DetailToursButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { useNavigate, useParams } from 'react-router-dom';
import { useSetRecoilState } from 'recoil';
import { getMember } from '@api/member';

interface reviewProps {
reviewData: any;
}

export default function DetailTourButtons({ reviewData }: reviewProps) {
export default function DetailTourButtons({
reviewData,
}: {
reviewData: tourDetail;
}) {
const { title, contentTypeId } = reviewData;
const params = useParams();
const tourItemId = Number(params.id);
Expand Down
12 changes: 2 additions & 10 deletions src/components/Review/CommentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@ import {
} from '@recoil/modal';
import { commentState, targetCommentIdState } from '@recoil/review';
import { useRecoilState, useSetRecoilState } from 'recoil';
interface ItemProps {
commentId: number;
authorNickname: string;
authorProfileImageUrl: string;
createdTime: any;
content: string;
onClick?: () => void;
isAuthor: boolean;
}
import { CommentItemProps } from '@/@types/review.types';

const CommentItem: React.FC<ItemProps> = (props: ItemProps) => {
const CommentItem: React.FC<CommentItemProps> = (props: CommentItemProps) => {
const {
commentId,
authorNickname,
Expand Down
7 changes: 4 additions & 3 deletions src/components/Review/MyReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import MyAlert from '@components/common/modal/children/MyAlert';
import { alertTypeState } from '@recoil/modal';
import { PenIcon } from '@components/common/icons/Icons';
import ScrollTopButton from '@components/Plan/ScrollTopButton';
import { MyReviewContent } from '@/@types/review.types';

export default function MyReview() {
const [reviewDataLength, setReviewDataLength] = useState<number>(0);
Expand Down Expand Up @@ -60,7 +61,7 @@ export default function MyReview() {
return <div>데이터를 불러오는 중 오류가 발생했습니다.</div>;
}

const handleReviewClick = (item: any) => {
const handleReviewClick = (item: MyReviewContent) => {
const reviewId = item.reviewId;
navigate(`/reviewComment/${reviewId}`, { state: { item } });
};
Expand Down Expand Up @@ -113,7 +114,7 @@ export default function MyReview() {
<PenIcon size={50} color="#D7D7D7" />
</div>
<div className="text-md mb-2 flex justify-center font-bold text-gray4">
작성한 리뷰가 없습니다
내가 쓴 리뷰가 없어요
</div>
<div className="flex justify-center text-sm text-gray4">
다녀온 여행지의 리뷰를 남겨보세요!
Expand All @@ -134,7 +135,7 @@ export default function MyReview() {
{
return (
<React.Fragment key={index}>
{group?.data.data.content.map((item: any) => {
{group?.data.data.content.map((item: MyReviewContent) => {
item.isAuthor = true;
return (
<ReviewItem
Expand Down
4 changes: 2 additions & 2 deletions src/components/Review/Review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { isModalOpenState } from '@recoil/modal';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import { useParams, useNavigate } from 'react-router-dom';
import { useMutation, useQueryClient } from '@tanstack/react-query';

import { ReviewRequest } from '@recoil/review';
interface EditReviewMutationParams {
reviewData: any;
reviewData: ReviewRequest;
targetReviewId: number;
}

Expand Down
6 changes: 1 addition & 5 deletions src/components/Review/ReviewButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { ratingState } from '@recoil/review';
import { useEffect, useState } from 'react';
import { useRecoilValue } from 'recoil';

interface ButtonProps {
onClick: () => void;
}

const ReviewButton = (props: ButtonProps) => {
const ReviewButton = (props: { onClick: () => void }) => {
const { onClick } = props;
const rating = useRecoilValue(ratingState);
const [isRatingValid, setIsRatingValid] = useState(false);
Expand Down
29 changes: 16 additions & 13 deletions src/components/Review/ReviewComments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import MyAlert from '@components/common/modal/children/MyAlert';
import { commentState, toastPopUpState } from '@recoil/review';
import { alertTypeState } from '@recoil/modal';
import ToastPopUp from '@components/common/toastpopup/ToastPopUp';
import { CommentItemProps } from '@/@types/review.types';

export default function ReviewComments() {
const params = useParams();
Expand Down Expand Up @@ -88,8 +89,8 @@ export default function ReviewComments() {
<div className="h-[8px] bg-gray1"></div>
<div className="flex flex-col">
{commentDataLength == 0 && (
<div className="mb-4 flex flex-col items-center justify-center text-sm text-gray4">
<div>댓글이 없습니다. </div>
<div className="mt-10 flex flex-col items-center justify-center text-sm text-gray4">
<div>아직 댓글이 없어요. </div>
<div>첫 댓글을 작성해보세요!</div>
</div>
)}
Expand All @@ -107,17 +108,19 @@ export default function ReviewComments() {
{
return (
<React.Fragment key={index}>
{group?.data.data.comments.content.map((item: any) => (
<CommentItem
key={item.commentId}
commentId={item.commentId}
authorNickname={item.authorNickname}
authorProfileImageUrl={item.authorProfileImageUrl}
createdTime={item.createdTime}
content={item.content}
isAuthor={item.isAuthor}
/>
))}
{group?.data.data.comments.content.map(
(item: CommentItemProps) => (
<CommentItem
key={item.commentId}
commentId={item.commentId}
authorNickname={item.authorNickname}
authorProfileImageUrl={item.authorProfileImageUrl}
createdTime={item.createdTime}
content={item.content}
isAuthor={item.isAuthor}
/>
),
)}
</React.Fragment>
);
}
Expand Down
8 changes: 2 additions & 6 deletions src/components/Review/ReviewKeyword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { getReviewKeywords } from '@api/review';
import { useQuery } from '@tanstack/react-query';
import { useRecoilState } from 'recoil';
import { keywordsState } from '@recoil/review';

interface Keyword {
keywordId: number;
content: string;
}
import { Keyword } from '@/@types/review.types';

export default function ReviewKeyword() {
const location = useLocation();
Expand Down Expand Up @@ -59,7 +55,7 @@ export default function ReviewKeyword() {
<div className="mb-5 text-lg font-bold">어떤 점이 좋았나요? </div>
<div className="text-md mb-10 grid grid-cols-2 gap-2 font-bold">
{reviewKeywords?.data?.data?.keywords?.map(
(keyword: any, index: number) => {
(keyword: Keyword, index: number) => {
const row = Math.floor(index / columns) + 1;
const col = (index % columns) + 1;

Expand Down
2 changes: 1 addition & 1 deletion src/components/Review/ReviewRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ReviewRating = () => {

const handleStarClick = (index: number) => {
const newRating = index + 1;
setRating((prevRating: any) => {
setRating((prevRating: number) => {
const updatedIsHalfClicked =
prevRating === newRating ? !isHalfClicked : false;
setIsHalfClicked(updatedIsHalfClicked);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Trip/TripInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ShareList = () => {
<>
<hr className="my-3 border-solid border-gray2" />
<div className="max-h-[115px] overflow-y-auto">
{members.map((member: any, index: number) => {
{members.map((member: TripMemeberInfo, index: number) => {
return (
<div
className={`mb-2 flex cursor-pointer items-center text-gray5`}
Expand Down Expand Up @@ -89,7 +89,7 @@ const TripInfo = () => {
<div className="my-5">
<div className="flex items-center justify-between">
<div className="flex space-x-[-17.5px]">
{members?.map((member: any, index: number) => (
{members?.map((member: TripMemeberInfo, index: number) => (
<div key={index}>
{member.profileImageUrl &&
member.profileImageUrl !== 'http://asiduheimage.jpg' ? (
Expand Down
Loading

0 comments on commit 435f9a4

Please sign in to comment.