Skip to content
Merged
Changes from 1 commit
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
103 changes: 103 additions & 0 deletions src/components/Post/PostCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { cn } from "@/utils/cn";
import { formatTimeRange } from "@/utils/datetime";
import IconLocation from "@/assets/icon/location.svg?react";
import IconTime from "@/assets/icon/time.svg?react";
import IconArrow from "@/assets/icon/arrow-up.svg?react";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import IconLocation from "@/assets/icon/location.svg?react";
import IconTime from "@/assets/icon/time.svg?react";
import IconArrow from "@/assets/icon/arrow-up.svg?react";
import { Location, Time, ArrowUp } from "@/assets/icon";

수빈님께서 일괄 export를 해주셔서 위 처럼 아이콘을 사용할 수 있어요! 👍


const getPayRateText = (hourlyPay?: number, originalPay?: number): string => {
if (hourlyPay === undefined || originalPay === undefined) {
return "";
}

const rawRate = ((hourlyPay - originalPay) / originalPay) * 100;
const displayRate = Math.min(Math.round(rawRate), 100);
return `기존 시급보다 ${displayRate}%`;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post 컴포넌트에도 거의 유사항 로직이 있었는데, 해당 로직을 util 함수로 분리해서 재사용하면 어떨까요? 🤔


interface PostCardProps {
name: string;
imageUrl: string;
address1: string;
description: string;
originalHourlyPay?: number;
hourlyPay?: number;
startsAt?: string;
workhour?: number;
isShopInfo?: boolean;
backgroundColor?: string;
children?: React.ReactNode;
}

export default function PostCard({
name,
imageUrl,
address1,
description,
hourlyPay,
originalHourlyPay,
startsAt,
workhour,
isShopInfo = false,
backgroundColor = "#ffffff",
children = null,
}: PostCardProps) {
const rateText = getPayRateText(hourlyPay, originalHourlyPay);

const timeRange =
startsAt && workhour !== undefined
? formatTimeRange(startsAt, workhour)
: "";

return (
<article
className={cn(
"grid p-5 md:p-6 lg:grid-cols-[1fr_346px] lg:gap-[31px] rounded-2xl",
backgroundColor,
backgroundColor === "#ffffff" && "border border-gray-20 shadow-sm",
)}
>
<div className="w-full overflow-hidden rounded-xl">
<img
src={imageUrl}
alt={name}
className="w-full h-[180px] object-cover md:h-[360px] lg:h-[308px]"
/>
</div>
<div className="flex flex-col justify-between mt-3 h-[251px] md:mt-4 md:h-[252px] lg:h-[292px]">
<div className="space-y-2 md:space-y-3">
{!isShopInfo ? (
<>
<div className="flex flex-col gap-[2px]">
<p className="text-primary body2-bold md:body1-bold">시급</p>
<div className="flex items-center gap-2">
<h2 className="text-[20px] font-bold md:text-[28px]">
{hourlyPay?.toLocaleString()}원
</h2>
<span className="inline-flex items-center gap-[2px] rounded-[20px] bg-primary px-3 py-1 text-[12px] font-normal leading-[16px] text-white md:body2-bold">
{rateText}
<IconArrow className="w-4 h-4 md:w-5 md:h-5" />
</span>
</div>
</div>
<div className="flex items-center gap-[6px] text-gray-50 body2-regular md:body1-regular">
<IconTime className="w-4 h-4 md:w-5 md:h-5" />
{timeRange}
</div>
</>
) : (
<p className="text-primary body2-bold md:body1-bold">식당</p>
)}
{isShopInfo && <h2 className="text-[28px] font-bold">{name}</h2>}
<div className="flex items-center gap-[6px] text-gray-50 body2-regular md:body1-regular">
<IconLocation className="w-4 h-4 md:w-5 md:h-5" />
{address1}
</div>
<p className="text-black body2-regular md:body1-regular">
{description}
</p>
</div>
{children && <div className="flex gap-2 mt-3">{children}</div>}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

children prop에는 어떤 내용이 들어가면 되는건지 잘 모르겠어요 하핳 😅
코드를 천천히 살펴보니 버튼 요소가 들어가야 할 것 같긴 하네요! 🤔

PostCard 컴포넌트가 자식 요소로 가져갈 수 있는 것은 많은데,
이미 많은 부분을 위의 코드로 구체화하고 계셔서 어떤 요소가 children으로 전달되어야 할 지 직관적이지 않은 것 같아요 🥲

Copy link
Collaborator Author

@ghdtnals ghdtnals Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 꼼꼼하게 리뷰해주셔서 감사합니다!😊 말씀해주신 부분들 참고하여 코드를 개선해보도록 하겠습니다!!

</div>
</article>
);
}