diff --git a/src/apis/loaders/notice.ts b/src/apis/loaders/notice.ts index c09b4ab..ff6868e 100644 --- a/src/apis/loaders/notice.ts +++ b/src/apis/loaders/notice.ts @@ -2,6 +2,7 @@ import { getShopApplications } from "../services/applicationService"; import { getNotice } from "../services/noticeService"; import { PostData } from "@/components/Post/PostList"; +import { UserType } from "@/types/user"; import { getLocalStorageValue } from "@/utils/localStorage"; interface LoadNoticeParams { @@ -19,12 +20,20 @@ export const loadNotice = async ({ shopId, noticeId }: LoadNoticeParams) => { const MAX_VISIBLE_RECENT_NOTICES = 6; -export const loadRecentNotices = (noticeId: string) => { +export const loadRecentNotices = (noticeId: string, userType?: UserType) => { const allRecentNotices = getLocalStorageValue("recentNotices") ?? []; const recentNotices = allRecentNotices .filter(({ id }) => id !== noticeId) + .map(({ link, ...restNoticeInfo }) => { + const type = userType ?? "employee"; + const splittedLink = link.split("/"); + splittedLink[splittedLink.length - 1] = type; + + const updatedLink = splittedLink.join("/"); + return { link: updatedLink, ...restNoticeInfo }; + }) .slice(0, MAX_VISIBLE_RECENT_NOTICES); return recentNotices; diff --git a/src/components/NoticeDetailInfo/NoticeDetailInfo.tsx b/src/components/NoticeDetailInfo/NoticeDetailInfo.tsx index 0c172a9..78a1ada 100644 --- a/src/components/NoticeDetailInfo/NoticeDetailInfo.tsx +++ b/src/components/NoticeDetailInfo/NoticeDetailInfo.tsx @@ -14,6 +14,7 @@ interface NoticeDetailInfoCardProps { noticeId: string; user?: User | null; isEmployerPage?: boolean; + isStartApplication?: boolean; } function NoticeDetailInfoCard({ @@ -22,6 +23,7 @@ function NoticeDetailInfoCard({ noticeInfo, user, isEmployerPage, + isStartApplication = false, }: NoticeDetailInfoCardProps) { const { hourlyPay, @@ -42,7 +44,7 @@ function NoticeDetailInfoCard({ const applicationId = currentUserApplication?.item.id ?? ""; const applicationStatus = currentUserApplication?.item.status; - const isPast = isPastDate(startsAt, workhour); + const isPast = isPastDate(startsAt); const isDisabledNotice = isPast || closed || @@ -71,9 +73,11 @@ function NoticeDetailInfoCard({ buttons={ isEmployerPage ? ( ) : ( { - navigate(`/notice/edit/${noticeId}`); + if (isMyShop && !isPastNotice && isClosed && !isStartApplication) { + navigate(`/notice/edit/${noticeId}`); + } }; return ( @@ -26,9 +47,9 @@ function NoticeEmployerActionButton({ variant="white" className={"py-[14px]"} onClick={moveToEditNoticePage} - disabled={!isMyShop} + disabled={isDisabled} > - {isMyShop ? "공고 편집하기" : "다른 가게의 공고 편집 불가"} + {buttonText} ); } diff --git a/src/pages/NoticeEmployeePage/NoticeEmployeePage.tsx b/src/pages/NoticeEmployeePage/NoticeEmployeePage.tsx index 1dcb3c1..64954e2 100644 --- a/src/pages/NoticeEmployeePage/NoticeEmployeePage.tsx +++ b/src/pages/NoticeEmployeePage/NoticeEmployeePage.tsx @@ -37,7 +37,7 @@ export default function NoticeEmployeePage() {

최근에 본 공고

- {recentNotices.length > 0 ? ( + {recentNotices?.length > 0 ? ( ) : (
diff --git a/src/pages/NoticeEmployeePage/loader/noticeEmployeeLoader.ts b/src/pages/NoticeEmployeePage/loader/noticeEmployeeLoader.ts index 3409d5e..17351ce 100644 --- a/src/pages/NoticeEmployeePage/loader/noticeEmployeeLoader.ts +++ b/src/pages/NoticeEmployeePage/loader/noticeEmployeeLoader.ts @@ -1,15 +1,17 @@ import { LoaderFunction } from "react-router-dom"; import { loadNotice, loadRecentNotices } from "@/apis/loaders/notice"; +import { useUserStore } from "@/hooks/useUserStore"; const noticeEmployeeLoader: LoaderFunction = async ({ params }) => { + const user = useUserStore.getState().user; const { shopId, noticeId } = params as { shopId: string; noticeId: string; }; const noticeInfo = await loadNotice({ shopId, noticeId }); - const recentNotices = loadRecentNotices(noticeId); + const recentNotices = loadRecentNotices(noticeId, user?.type); return { noticeInfo, recentNotices }; }; diff --git a/src/pages/NoticeEmployerPage/NoticeEmployerPage.tsx b/src/pages/NoticeEmployerPage/NoticeEmployerPage.tsx index 9c2d6e0..72e52b0 100644 --- a/src/pages/NoticeEmployerPage/NoticeEmployerPage.tsx +++ b/src/pages/NoticeEmployerPage/NoticeEmployerPage.tsx @@ -2,7 +2,8 @@ import { useLoaderData, useParams } from "react-router-dom"; import NoticeDetailInfo from "../../components/NoticeDetailInfo/NoticeDetailInfo"; -import NoticeApplicationTableContainer from "./components/NoticeApplicationTableContainer"; +import NoticeApplicationTable from "./components/NoticeApplicationTable"; +import useShopApplications from "./hooks/useShopApplications"; import PostList, { PostData } from "@/components/Post/PostList"; import useUpdateRecentNotices from "@/hooks/useUpdateRecentNotices"; @@ -19,6 +20,15 @@ export default function NoticeEmployerPage() { noticeId: string; }; const { user } = useUserStore(); + const { + refetch: refetchShopApplications, + shopApplications, + totalCount, + } = useShopApplications({ + shopId, + noticeId, + type: user?.type, + }); const isMyShop = user?.shopId === shopId; @@ -37,6 +47,7 @@ export default function NoticeEmployerPage() { noticeInfo={noticeInfo} user={user} isEmployerPage + isStartApplication={shopApplications?.length > 0} />
@@ -47,14 +58,15 @@ export default function NoticeEmployerPage() { {isMyShop ? "신청자 목록" : "최근에 본 공고"} {isMyShop && ( - )} {!isMyShop && - (recentNotices.length > 0 ? ( + (recentNotices?.length > 0 ? ( ) : (
diff --git a/src/pages/NoticeEmployerPage/components/NoticeApplicationTableContainer.tsx b/src/pages/NoticeEmployerPage/components/NoticeApplicationTableContainer.tsx deleted file mode 100644 index 4b3a14f..0000000 --- a/src/pages/NoticeEmployerPage/components/NoticeApplicationTableContainer.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import useShopApplications from "../hooks/useShopApplications"; - -import NoticeApplicationTable from "./NoticeApplicationTable"; - -interface NoticeApplicationTableContainerProps { - shopId: string; - noticeId: string; -} - -function NoticeApplicationTableContainer({ - shopId, - noticeId, -}: NoticeApplicationTableContainerProps) { - const { - refetch: refetchShopApplications, - shopApplications, - totalCount, - } = useShopApplications({ - shopId, - noticeId, - }); - - return ( - - ); -} - -export default NoticeApplicationTableContainer; diff --git a/src/pages/NoticeEmployerPage/hooks/useShopApplications.ts b/src/pages/NoticeEmployerPage/hooks/useShopApplications.ts index 2bde58c..9bac752 100644 --- a/src/pages/NoticeEmployerPage/hooks/useShopApplications.ts +++ b/src/pages/NoticeEmployerPage/hooks/useShopApplications.ts @@ -4,8 +4,10 @@ import { useSearchParams } from "react-router-dom"; import { getShopApplications } from "@/apis/services/applicationService"; import { ApplicationItem } from "@/types/application"; +import { UserType } from "@/types/user"; interface UseShopApplicationsParams { + type?: UserType; shopId: string; noticeId: string; offset?: number; @@ -13,6 +15,7 @@ interface UseShopApplicationsParams { } const useShopApplications = ({ + type, shopId, noticeId, offset = 5, @@ -45,8 +48,10 @@ const useShopApplications = ({ }; useEffect(() => { - fetchShopApplication(); - }, [shopId, noticeId, offset, limit, page]); + if (type === "employer") { + fetchShopApplication(); + } + }, [type, shopId, noticeId, offset, limit, page]); return { refetch: fetchShopApplication, diff --git a/src/pages/NoticeEmployerPage/loader/noticeEmployerLoader.ts b/src/pages/NoticeEmployerPage/loader/noticeEmployerLoader.ts index ec8cb36..95d4b90 100644 --- a/src/pages/NoticeEmployerPage/loader/noticeEmployerLoader.ts +++ b/src/pages/NoticeEmployerPage/loader/noticeEmployerLoader.ts @@ -16,7 +16,7 @@ const noticeEmployerLoader: LoaderFunction = async ({ params }) => { return { noticeInfo }; } - const recentNotices = loadRecentNotices(noticeId); + const recentNotices = loadRecentNotices(noticeId, user?.type); return { noticeInfo, recentNotices }; };