diff --git a/src/api/noticeApi.ts b/src/api/noticeApi.ts index cacc72c..fdb35fd 100644 --- a/src/api/noticeApi.ts +++ b/src/api/noticeApi.ts @@ -32,7 +32,7 @@ export interface NoticeShopItem extends NoticeItem { // application까지 포함된 상세형 Notice (상세 조회 시 사용) export interface NoticeDetailItem extends NoticeShopItem { - currentUserApplication?: { + currentUserApplication: null | { item: ApplicationItem; }; } diff --git a/src/components/common/PostLarge.tsx b/src/components/common/PostLarge.tsx new file mode 100644 index 0000000..56b2850 --- /dev/null +++ b/src/components/common/PostLarge.tsx @@ -0,0 +1,139 @@ +import type { ReactNode } from 'react'; +import formatWorkTime from '@/utils/formatWorkTime'; +import ic_clock from '@/assets/icons/clock-red.svg'; +import ic_location from '@/assets/icons/location-red.svg'; +import ic_arrow from '@/assets/icons/arrow-up-white.svg'; +import PostImg from '@/assets/images/post-default.png'; +import type { NoticeDetailItem } from '@/api/noticeApi'; + +// 상태 계산 +function getStatus( + startsAt: string, + closed: boolean, +): 'ACTIVE' | 'CLOSED' | 'EXPIRED' { + const now = new Date(); + const startDate = new Date(startsAt); + + if (closed) return 'CLOSED'; // 인원 다 찼으면 마감 + if (now >= startDate) return 'EXPIRED'; // 기간 종료되면 마감 + return 'ACTIVE'; +} + +export default function PostLarge({ + className = '', + data, + children, +}: { + className?: string; + data: NoticeDetailItem; + children?: ReactNode; +}) { + const { + hourlyPay, + workhour, + startsAt, + closed, + description: noticeDescription, + shop: { + item: { + address1, + imageUrl, + originalHourlyPay, + description: shopDescription, + }, + }, + } = data; + + const status = getStatus(startsAt, closed); + const overlayText = + status === 'ACTIVE' ? '' : status === 'CLOSED' ? '마감 완료' : '지난 공고'; + + const dateTime = `${formatWorkTime({ startsAt, workhour })} (${workhour}시간)`; + + const percent = Math.floor( + ((hourlyPay - originalHourlyPay) / originalHourlyPay) * 100, + ); + const isHigherPay = percent > 0; // 이전 시급보다 높을 때만 표시 + + const background = imageUrl ?? PostImg; + + let badgeBgColor = ''; + if (percent >= 50) { + badgeBgColor = 'bg-red-40'; + } else if (percent >= 30) { + badgeBgColor = 'bg-red-30'; + } else if (percent >= 1) { + badgeBgColor = 'bg-red-20 '; + } + + return ( +