Skip to content

Commit

Permalink
Refactor: any 타입 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
seungjun222 committed Jan 24, 2024
1 parent 456e13e commit a1793b4
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 98 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
51 changes: 27 additions & 24 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 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
5 changes: 3 additions & 2 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 @@ -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
25 changes: 14 additions & 11 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 @@ -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
6 changes: 4 additions & 2 deletions src/components/Trip/TripParticipant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ interface ParticipantStatusProps {
status: string;
}

const ParticipantList: React.FC<{ infos: any[] }> = ({ infos }) => (
const ParticipantList: React.FC<{ infos: TripSurveySetMemberInfo[] }> = ({
infos,
}) => (
<div className="grid grid-cols-2 gap-3.5">
{infos.map((info: any) => (
{infos.map((info: TripSurveySetMemberInfo) => (
<div
key={info.memberId}
className={`flex h-[40px] cursor-pointer items-center text-gray5`}>
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import React, { ReactNode } from 'react';
import Modal from 'react-modal';
import { modalChildrenState } from '@recoil/modal';
import { useRecoilValue } from 'recoil';

interface ModalProps {
isOpen: boolean;
closeModal: () => void;
children: any;
children: ReactNode;
}

const ModalComponent: React.FC<ModalProps> = ({
Expand Down
2 changes: 1 addition & 1 deletion src/recoil/review.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { atom } from 'recoil';

interface ReviewRequest {
export interface ReviewRequest {
tourItemId: number;
rating: number;
keywords: Keyword[];
Expand Down

0 comments on commit a1793b4

Please sign in to comment.