Skip to content

Commit 5c5c11c

Browse files
committed
refactor: PostCard 및 Post 유틸함수 적용
1 parent 261b457 commit 5c5c11c

File tree

2 files changed

+15
-43
lines changed

2 files changed

+15
-43
lines changed

src/components/Post/Post.tsx

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
import { cn } from "@/utils/cn";
22
import { Link } from "react-router-dom";
33
import { formatTimeRange, isPastDate } from "@/utils/datetime";
4-
import IconTime from "@/assets/icon/time.svg?react";
5-
import IconLocation from "@/assets/icon/location.svg?react";
6-
import IconArrow from "@/assets/icon/arrow-up.svg?react";
7-
import IconArrowBold from "@/assets/icon/arrow-up-bold.svg?react";
8-
9-
const getPayRateText = (
10-
hourlyPay: number,
11-
originalPay: number,
12-
): {
13-
rawRate: number;
14-
displayRate: number;
15-
rateText: string;
16-
} => {
17-
const rawRate = ((hourlyPay - originalPay) / originalPay) * 100;
18-
const displayRate = Math.min(Math.round(rawRate), 100);
19-
const rateText = `기존 시급보다 ${displayRate}%`;
20-
21-
return { rawRate, displayRate, rateText };
22-
};
4+
import { getPayRateText } from "@/utils/payRate";
5+
import { Location, Time, ArrowUp, ArrowUpBold } from "@/assets/icon";
236

247
interface PostProps {
258
name: string;
@@ -76,11 +59,11 @@ export default function Post({
7659
<div className="mt-3 flex flex-col gap-2 md:mt-5">
7760
<h3 className="text-base md:text-xl">{name}</h3>
7861
<p className="flex items-start gap-[6px] text-xs font-normal text-gray-50 md:text-[14px] md:leading-[22px]">
79-
<IconTime className="h-4 w-4 md:h-5 md:w-5" />
62+
<Time className="h-4 w-4 md:h-5 md:w-5" />
8063
{timeRange}
8164
</p>
8265
<p className="flex items-start gap-[6px] text-xs font-normal text-gray-50 md:text-[14px] md:leading-[22px]">
83-
<IconLocation className="h-4 w-4 md:h-5 md:w-5" />
66+
<Location className="h-4 w-4 md:h-5 md:w-5" />
8467
{address1}
8568
</p>
8669
</div>
@@ -102,8 +85,8 @@ export default function Post({
10285
)}
10386
>
10487
{rateText}
105-
<IconArrow className="hidden h-5 w-5 md:block" />
106-
<IconArrowBold className="h-4 w-4 md:hidden" />
88+
<ArrowUp className="hidden h-5 w-5 md:block" />
89+
<ArrowUpBold className="h-4 w-4 md:hidden" />
10790
</span>
10891
)}
10992
</div>

src/components/Post/PostCard.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
import { cn } from "@/utils/cn";
22
import { formatTimeRange } from "@/utils/datetime";
3-
import IconLocation from "@/assets/icon/location.svg?react";
4-
import IconTime from "@/assets/icon/time.svg?react";
5-
import IconArrow from "@/assets/icon/arrow-up.svg?react";
6-
7-
const getPayRateText = (hourlyPay?: number, originalPay?: number): string => {
8-
if (hourlyPay === undefined || originalPay === undefined) {
9-
return "";
10-
}
11-
12-
const rawRate = ((hourlyPay - originalPay) / originalPay) * 100;
13-
const displayRate = Math.min(Math.round(rawRate), 100);
14-
return `기존 시급보다 ${displayRate}%`;
15-
};
3+
import { getPayRateText } from "@/utils/payRate";
4+
import { Location, Time, ArrowUp } from "@/assets/icon";
165

176
interface PostCardProps {
187
name: string;
@@ -25,7 +14,7 @@ interface PostCardProps {
2514
workhour?: number;
2615
isShopInfo?: boolean;
2716
backgroundColor?: string;
28-
children?: React.ReactNode;
17+
buttons?: React.ReactNode;
2918
}
3019

3120
export default function PostCard({
@@ -39,9 +28,9 @@ export default function PostCard({
3928
workhour,
4029
isShopInfo = false,
4130
backgroundColor = "#ffffff",
42-
children = null,
31+
buttons = null,
4332
}: PostCardProps) {
44-
const rateText = getPayRateText(hourlyPay, originalHourlyPay);
33+
const { rateText } = getPayRateText(hourlyPay, originalHourlyPay);
4534

4635
const timeRange =
4736
startsAt && workhour !== undefined
@@ -75,12 +64,12 @@ export default function PostCard({
7564
</h2>
7665
<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">
7766
{rateText}
78-
<IconArrow className="w-4 h-4 md:w-5 md:h-5" />
67+
<ArrowUp className="w-4 h-4 md:w-5 md:h-5" />
7968
</span>
8069
</div>
8170
</div>
8271
<div className="flex items-center gap-[6px] text-gray-50 body2-regular md:body1-regular">
83-
<IconTime className="w-4 h-4 md:w-5 md:h-5" />
72+
<Time className="w-4 h-4 md:w-5 md:h-5" />
8473
{timeRange}
8574
</div>
8675
</>
@@ -89,14 +78,14 @@ export default function PostCard({
8978
)}
9079
{isShopInfo && <h2 className="text-[28px] font-bold">{name}</h2>}
9180
<div className="flex items-center gap-[6px] text-gray-50 body2-regular md:body1-regular">
92-
<IconLocation className="w-4 h-4 md:w-5 md:h-5" />
81+
<Location className="w-4 h-4 md:w-5 md:h-5" />
9382
{address1}
9483
</div>
9584
<p className="text-black body2-regular md:body1-regular">
9685
{description}
9786
</p>
9887
</div>
99-
{children && <div className="flex gap-2 mt-3">{children}</div>}
88+
{buttons && <div className="flex gap-2 mt-3">{buttons}</div>}
10089
</div>
10190
</article>
10291
);

0 commit comments

Comments
 (0)