Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/#338/myreview #341

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 11 additions & 94 deletions src/app/(user-menu)/mypage/reviews/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
"use client";

import { useState } from "react";
import Image from "next/image";
import { cn } from "@/lib/utils";
import { Tooltip } from "@radix-ui/themes";
import { useQueryClient, useSuspenseQuery } from "@tanstack/react-query";
import changeReviewStatus from "@/services/review/changeReviewStatus";
import { useSuspenseQuery } from "@tanstack/react-query";
import getMyReviews from "@/services/review/getMyReviews";
import Icon from "@/components/_common/Icon";
import { SingleSelector } from "@/components/_common/Selector";
import { CardTooltip } from "@/constants/cardTooltip";
import { subBoxStyles, subMyPageTextStyles } from "@/constants/commonStyle";
import MyCardReview from "@/components/containers/myReviews/MyCardReview";
import MyCommentReview from "@/components/containers/myReviews/MyCommentReview";
import { MyReviewKey } from "@/constants/queryKeys";

const MyReviewsPage = () => {
Expand All @@ -19,96 +12,20 @@ const MyReviewsPage = () => {
queryFn: () => getMyReviews(),
staleTime: 10000,
});
const [selectedId, setSelectedId] = useState<string | null>(null);
const queryClient = useQueryClient();

const selectedReviews = myReviewData.reviews.find(
(review) => review.steadyId === Number(selectedId),
);

const handlePublicReview = async (reviewId: number) => {
await changeReviewStatus(reviewId.toString());
queryClient.invalidateQueries({ queryKey: MyReviewKey });
};

return (
<div className="flex h-full flex-col gap-50 max-sm:w-400 sm:w-500 md:w-400 lg:w-600 xl:w-750">
<div className="font-bold max-sm:text-22 sm:text-22 md:text-25 lg:text-28 xl:text-30">
내가 받은 리뷰
</div>
<div className={cn("flex flex-col gap-30")}>
<div className={cn(subMyPageTextStyles.title)}>받은 카드</div>
<div className={cn(subBoxStyles, "justify-evenly")}>
{myReviewData.userCards.map((card, index) => (
<div
key={card.cardId}
className={cn(
subMyPageTextStyles.content,
"flex h-full flex-col items-center justify-center gap-5",
)}
>
<Tooltip content={CardTooltip[index]}>
<Image
src={card.imageUrl}
alt="카드 이미지"
width={40}
height={80}
/>
</Tooltip>

<div className={cn(subMyPageTextStyles.content)}>
{`( ${card.count} )`}
</div>
</div>
))}
</div>
</div>
<div className={cn("flex w-full flex-col gap-30")}>
<div className={cn(subMyPageTextStyles.title)}>한 줄 평</div>
<SingleSelector
items={myReviewData.reviews.map((review) => ({
value: review.steadyId.toString(),
label: review.steadyName,
}))}
initialLabel="전체"
onSelectedChange={(value) => setSelectedId(value)}
className="h-60"
/>
<div
className={`${
selectedReviews
? "border-2 border-st-gray-100"
: "items-center justify-center"
} flex h-230 flex-col gap-20 overflow-auto px-10 py-5`}
>
{selectedReviews &&
selectedReviews.reviews.map((review) => (
<div
key={review.reviewId}
className="flex items-center justify-between"
>
<div className="text-ellipsis text-15 font-bold">
{review.comment}
</div>
<button onClick={() => handlePublicReview(review.reviewId)}>
{review.isPublic ? (
<Icon
name="eye"
size={25}
color="text-black"
/>
) : (
<Icon
name="eye-none"
size={25}
color="text-black"
/>
)}
</button>
</div>
))}
</div>
</div>
<MyCardReview
title={"받은 카드"}
myReviewData={myReviewData}
/>
<MyCommentReview
title={"한 줄 평"}
myReviewData={myReviewData}
/>
</div>
);
};
Expand Down
46 changes: 46 additions & 0 deletions src/components/containers/myReviews/MyCardReview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Image from "next/image";
import { cn } from "@/lib/utils";
import { Tooltip } from "@radix-ui/themes";
import type { MyReviewsType } from "@/services/types";
import { CardTooltip } from "@/constants/cardTooltip";
import { subBoxStyles, subMyPageTextStyles } from "@/constants/commonStyle";

const MyCardReview = ({
myReviewData,
title,
}: {
myReviewData: MyReviewsType;
title: string;
}) => {
return (
<div className={cn("flex flex-col gap-30")}>
<div className={cn(subMyPageTextStyles.title)}>{title}</div>
<div className={cn(subBoxStyles, "justify-evenly")}>
{myReviewData.userCards.map((card, index) => (
<div
key={card.cardId}
className={cn(
subMyPageTextStyles.content,
"flex h-full flex-col items-center justify-center gap-5",
)}
>
<Tooltip content={CardTooltip[index]}>
<Image
src={card.imageUrl}
alt="카드 이미지"
width={40}
height={80}
/>
</Tooltip>

<div className={cn(subMyPageTextStyles.content)}>
{`( ${card.count} )`}
</div>
</div>
))}
</div>
</div>
);
};

export default MyCardReview;
80 changes: 80 additions & 0 deletions src/components/containers/myReviews/MyCommentReview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useState } from "react";
import { cn } from "@/lib/utils";
import { useQueryClient } from "@tanstack/react-query";
import changeReviewStatus from "@/services/review/changeReviewStatus";
import type { MyReviewsType } from "@/services/types";
import Icon from "@/components/_common/Icon";
import { SingleSelector } from "@/components/_common/Selector";
import { subMyPageTextStyles } from "@/constants/commonStyle";
import { MyReviewKey } from "@/constants/queryKeys";

const MyCommentReview = ({
myReviewData,
title,
}: {
myReviewData: MyReviewsType;
title: string;
}) => {
const [selectedId, setSelectedId] = useState<string | null>(null);
const queryClient = useQueryClient();

const selectedReviews = myReviewData.reviews.find(
(review) => review.steadyId === Number(selectedId),
);

const handlePublicReview = async (reviewId: number) => {
await changeReviewStatus(reviewId.toString());
queryClient.invalidateQueries({ queryKey: MyReviewKey });
};

return (
<div className={cn("flex w-full flex-col gap-30")}>
<div className={cn(subMyPageTextStyles.title)}>{title}</div>
<SingleSelector
items={myReviewData.reviews.map((review) => ({
value: review.steadyId.toString(),
label: review.steadyName,
}))}
initialLabel="전체"
onSelectedChange={(value) => setSelectedId(value)}
className="h-60"
/>
<div
className={`${
selectedReviews
? "border-2 border-st-gray-100"
: "items-center justify-center"
} flex h-230 flex-col gap-20 overflow-auto px-10 py-5`}
>
{selectedReviews &&
selectedReviews.reviews.map((review) => (
<div
key={review.reviewId}
className="flex items-center justify-between"
>
<div className="text-ellipsis text-15 font-bold">
{review.comment}
</div>
<button onClick={() => handlePublicReview(review.reviewId)}>
{review.isPublic ? (
<Icon
name="eye"
size={25}
color="text-black"
/>
) : (
<Icon
name="eye-none"
size={25}
color="text-black"
/>
)}
</button>
</div>
))}
</div>
</div>
);
};

export default MyCommentReview;
Loading