Skip to content

Commit 580259a

Browse files
authored
Merge pull request #50 from CodeitPart3/PROFILE-49-JIN
[feat] UserApplicationTable 컴포넌트 구현 (내 프로필 신청 내역), StatusBadge, numberCommaFormatter 구현
2 parents 2c0ef18 + ec6d969 commit 580259a

File tree

5 files changed

+105
-4
lines changed

5 files changed

+105
-4
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"lint": "eslint .",
1010
"preview": "vite preview",
1111
"postinstall": "node scripts/setup-git-hooks.cjs",
12-
"prepare": "husky"
12+
"prepare": "husky install"
1313
},
1414
"lint-staged": {
15-
"**/*.{js,jsx}": [
15+
"**/*.{ts,tsx,js.jsx}": [
1616
"eslint --fix",
1717
"prettier --write"
1818
],

src/components/Pagination.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default function Pagination({
5252
const isLastPage = currentPage === totalPages;
5353

5454
return (
55-
<ul className="flex items-center md:gap-1 sm:gap-0.5 select-none text-black">
55+
<ul className="flex items-center md:gap-1 gap-0.5 select-none text-black">
5656
{isTotalPagesMoreThanLimit && (
5757
<li className="flex items-center mr-4">
5858
<button
@@ -80,7 +80,7 @@ export default function Pagination({
8080
disabled={isActive}
8181
aria-current={isActive ? "page" : undefined}
8282
className={cn(
83-
"md:w-10 md:h-10 sm:w-8 sm:h-8 grid place-content-center rounded-sm md:text-sm sm:text-xs",
83+
"md:w-10 md:h-10 w-8 h-8 grid place-content-center rounded-sm md:text-sm text-xs",
8484
"cursor-pointer disabled:cursor-default transition-colors duration-150 active:scale-95",
8585
isActive ? "bg-red-30 text-white" : "hover:bg-gray-100",
8686
)}

src/components/StatusBadge.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { ApplicationStatus } from "../types";
2+
3+
import { cn } from "@/utils/cn";
4+
5+
interface StatusBadgeProps {
6+
status: ApplicationStatus;
7+
}
8+
9+
const statusMap: {
10+
[key in ApplicationStatus]: { text: string; className: string };
11+
} = {
12+
accepted: { text: "승인 완료", className: "bg-blue-10 text-blue-20" },
13+
pending: { text: "대기중", className: "bg-green-10 text-green-20" },
14+
canceled: { text: "취소", className: " bg-yellow-100 text-yellow-500" },
15+
rejected: { text: "거절", className: "bg-red-40 text-red-10" },
16+
} as const;
17+
18+
function StatusBadge({ status }: StatusBadgeProps) {
19+
return (
20+
<span
21+
className={cn(
22+
"inline-block py-1.5 px-2.5 rounded-full text-xs md:text-sm font-bold",
23+
statusMap[status].className,
24+
)}
25+
>
26+
{statusMap[status].text}
27+
</span>
28+
);
29+
}
30+
31+
export default StatusBadge;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import Pagination from "@/components/Pagination";
2+
import StatusBadge from "@/components/StatusBadge";
3+
import Table from "@/components/Table";
4+
import { ApplicationItem } from "@/types/application";
5+
import { formatTimeRange } from "@/utils/datetime";
6+
import { numberCommaFormatter } from "@/utils/number";
7+
8+
interface UserApplicationTableProps {
9+
data: ApplicationItem[];
10+
pageCount: number;
11+
pageLimit: number;
12+
itemCountPerPage?: number;
13+
}
14+
15+
function UserApplicationTable({
16+
data,
17+
pageCount,
18+
pageLimit,
19+
itemCountPerPage = 5,
20+
}: UserApplicationTableProps) {
21+
return (
22+
<Table
23+
data={data}
24+
headRow={() => (
25+
<Table.Tr>
26+
<Table.Th className="min-w-[10rem] max-w-[14.25rem]">가게</Table.Th>
27+
<Table.Th className="min-w-[18rem]">일자</Table.Th>
28+
<Table.Th className="min-w-[8.5rem] max-w-[12.5rem]">시급</Table.Th>
29+
<Table.Th className="min-w-[8.5rem] max-w-[14.75rem]">상태</Table.Th>
30+
</Table.Tr>
31+
)}
32+
bodyRow={({ id, notice, shop, status }) => (
33+
<Table.Tr
34+
key={id}
35+
className="text-sm md:text-[1rem]"
36+
showLastBottomBorder
37+
>
38+
<Table.Td>{shop.item.name}</Table.Td>
39+
<Table.Td>
40+
{formatTimeRange(notice.item.startsAt, notice.item.workhour)}
41+
</Table.Td>
42+
<Table.Td>{numberCommaFormatter(notice.item.hourlyPay)}</Table.Td>
43+
<Table.Td>
44+
<StatusBadge status={status} />
45+
</Table.Td>
46+
</Table.Tr>
47+
)}
48+
footerRow={() => (
49+
<Table.Tr className="flex justify-center">
50+
<Table.Td colSpan={3}>
51+
<Pagination
52+
count={pageCount}
53+
limit={pageLimit}
54+
itemCountPerPage={itemCountPerPage}
55+
/>
56+
</Table.Td>
57+
</Table.Tr>
58+
)}
59+
/>
60+
);
61+
}
62+
63+
export default UserApplicationTable;

src/utils/number.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* 숫자를 전달받아 콤마(,)를 더해 반환합니다.
3+
* @example numberCommaFormatter(20000) -> 20,000
4+
*/
5+
export const numberCommaFormatter = Intl.NumberFormat("ko-kr", {
6+
compactDisplay: "long",
7+
}).format;

0 commit comments

Comments
 (0)