diff --git a/public/icons/RatingIcon.tsx b/public/icons/RatingIcon.tsx index 4582487b..14ae97b0 100644 --- a/public/icons/RatingIcon.tsx +++ b/public/icons/RatingIcon.tsx @@ -12,7 +12,7 @@ function RatingIcon({ checked = false, ...props }: RatingIconProps) { - const heartColor = checked ? '#EA580C' : '#D1D5DB'; + const heartColor = checked ? '#00a991' : '#d8d9db'; return ( ; export default meta; -type Story = StoryObj; +type Story = StoryObj; -export const CreatedReview: Story = { +export const FindClubReview: Story = { + render: (args) => ( + +
+ + + +
+ + ), args: { ratingCount: 4, comment: - '따듯하게 느껴지는 공간이에요 :) 평소에 달램 이용해보고 싶었는데 이렇게 같이 달램 생기니까 너무 좋아요! 프로그램이 더 많이 늘어났으면 좋겠어요.', + '아침부터 자기발전을 위한 시간을 가져서 좋았어요. 각자의 길 위에서 달려가는 생생한 순간을 공유해주셔서 감사합니다!', + profileImage: + 'https://cdn.pixabay.com/photo/2024/02/17/00/18/cat-8578562_1280.jpg', + userName: '다람쥐', + createdAt: '2024.01.25', + }, +}; + +export const MypageReview: Story = { + render: (args) => ( +
+ +
+ +
+ + + + +
+
+
+
+ ), + args: { profileImage: 'https://cdn.pixabay.com/photo/2024/02/17/00/18/cat-8578562_1280.jpg', - userName: '럽윈즈올', + userName: '다람쥐', + ratingCount: 4, + comment: + '아침부터 자기발전을 위한 시간을 가져서 좋았어요. 각자의 길 위에서 달려가는 생생한 순간을 공유해주셔서 감사합니다!', createdAt: '2024.01.25', + clubImage: + 'https://cdn.pixabay.com/photo/2024/02/17/00/18/cat-8578562_1280.jpg', + clubName: '달램핏 오피스 스트레칭', + clubImageAlt: '달램핏 이미지', + location: '을지로 3가', }, }; diff --git a/src/components/written-review/WrittenReview.test.tsx b/src/components/written-review/WrittenReview.test.tsx deleted file mode 100644 index 35a40d3e..00000000 --- a/src/components/written-review/WrittenReview.test.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { render, screen } from '@testing-library/react'; -import '@testing-library/jest-dom'; -import WrittenReview from './WrittenReview'; -import { act } from 'react'; - -describe('WrittenReview Component', () => { - const defaultProfileImage = - 'https://cdn.pixabay.com/photo/2018/02/12/10/45/heart-3147976_1280.jpg'; - const validProfileImage = - 'https://cdn.pixabay.com/photo/2024/02/17/00/18/cat-8578562_1280.jpg'; - const brokenProfileImage = 'https://broken-url.com/image.jpg'; - - it('유효한 이미지 경우 정상적으로 렌더링', () => { - render( - , - ); - const imgElement = screen.getByAltText("Test User's profile picture"); - - expect(imgElement.getAttribute('src')).toContain( - encodeURIComponent(validProfileImage), - ); - }); - - it('유효하지 않은 이미지 경우 기본 이미지로 대체', async () => { - render( - , - ); - - const imgElement = screen.getByAltText("Test User's profile picture"); - - expect(imgElement.getAttribute('src')).toContain( - encodeURIComponent(brokenProfileImage), - ); - - await act(async () => { - imgElement.dispatchEvent(new Event('error')); - }); - - expect(imgElement.getAttribute('src')).toContain( - encodeURIComponent(defaultProfileImage), - ); - }); -}); diff --git a/src/components/written-review/WrittenReview.tsx b/src/components/written-review/WrittenReview.tsx index df4d53ec..c77a5231 100644 --- a/src/components/written-review/WrittenReview.tsx +++ b/src/components/written-review/WrittenReview.tsx @@ -1,59 +1,107 @@ -'use client'; - import Image from 'next/image'; import RatingDisplay from '../rating-display/RatingDisplay'; -import { useState, useEffect } from 'react'; - -// 디자인 확정시, 기본 이미지 변경 -const defaultProfileImage = - 'https://cdn.pixabay.com/photo/2018/02/12/10/45/heart-3147976_1280.jpg'; - -interface WrittenReviewProps { - ratingCount: number; - comment: string; - profileImage?: string; - userName: string; - createdAt: string; +import { LocationIcon } from '../../../public/icons'; +import { + ClubImageProps, + ClubInfoProps, + CommentProps, + RatingProps, + UserProfileProps, +} from './types/writtenReview'; + +// 기본 이미지 (변경될 수 있음) +const defaultProfileImage = '/images/profile.png'; +const defaultClubImage = '/images/profile.png'; + +function handleImageError( + event: React.SyntheticEvent, + defaultSrc: string, +) { + event.currentTarget.src = defaultSrc; } export default function WrittenReview({ - ratingCount, - comment, - profileImage, - userName, - createdAt, -}: WrittenReviewProps) { - const [imgSrc, setImgSrc] = useState(profileImage || defaultProfileImage); + children, +}: { + children: React.ReactNode; +}) { + return ( +
+ {children} +
+
+ ); +} - useEffect(() => { - setImgSrc(profileImage || defaultProfileImage); - }, [profileImage]); +function Rating({ ratingCount }: RatingProps) { + return ; +} - const handleImageError = () => { - setImgSrc(defaultProfileImage); - }; +function Comment({ text }: CommentProps) { + return ( +

+ {text} +

+ ); +} +function UserProfile({ + profileImage, + userName, + createdAt, + className, +}: UserProfileProps) { return ( -
- -

- {comment} -

-
+
+ {profileImage && ( {`${userName}'s handleImageError(e, defaultProfileImage)} /> -

- {userName} -

-

{createdAt}

+ )} +

+ {userName} +

+

{createdAt}

+
+ ); +} + +function ClubImage({ src, alt }: ClubImageProps) { + return ( + {alt handleImageError(e, defaultClubImage)} + /> + ); +} + +function ClubInfo({ clubName, location }: ClubInfoProps) { + return ( +
+

{clubName}

+
+ + + {location} +
-
-
+ ); } + +// WrittenReview의 자식 컴포넌트 연결 +WrittenReview.Rating = Rating; +WrittenReview.Comment = Comment; +WrittenReview.UserProfile = UserProfile; +WrittenReview.ClubInfo = ClubInfo; +WrittenReview.ClubImage = ClubImage; diff --git a/src/components/written-review/types/writtenReview.ts b/src/components/written-review/types/writtenReview.ts new file mode 100644 index 00000000..0f22dacc --- /dev/null +++ b/src/components/written-review/types/writtenReview.ts @@ -0,0 +1,24 @@ +export interface UserProfileProps { + profileImage?: string; + userName?: string; + createdAt: string; + className?: string; +} + +export interface ClubImageProps { + src: string; + alt?: string; +} + +export interface ClubInfoProps { + clubName: string; + location: string; +} + +export interface CommentProps { + text: string; +} + +export interface RatingProps { + ratingCount: number; +}