Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 27 additions & 12 deletions src/pages/employer/shops/[shopId]/notices/[noticeId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,15 @@ export const getServerSideProps: GetServerSideProps<{ notice: NoticeCard }> = as
const noticeRes = await axiosInstance.get(`shops/${shopId}/notices/${noticeId}`);
return { props: { notice: toNoticeCard(noticeRes.data) } };
} catch {
return {
notFound: true,
};
return { notFound: true };
}
};

const EmployerNoticeDetailPage = ({ notice }: { notice: NoticeCard }) => {
const headers = ['μ‹ μ²­μž', 'μ†Œκ°œ', 'μ „ν™”λ²ˆν˜Έ', 'μƒνƒœ'];
const [data, setData] = useState<TableRowProps[]>([]);
const [offset, setOffset] = useState(0);
const [total, setTotal] = useState(0); // βœ… 전체 개수
const limit = 5;

const { role, isLogin, user } = useAuth();
Expand All @@ -109,7 +108,6 @@ const EmployerNoticeDetailPage = ({ notice }: { notice: NoticeCard }) => {
const isOwner = user?.shop?.item.id === notice.shopId;
const canEdit = useMemo(() => status === 'open' && isOwner, [status, isOwner]);

// 곡고 νŽΈμ§‘ν•˜κΈ°
const handleEditClick = useCallback(() => {
if (!canEdit) return;

Expand Down Expand Up @@ -149,14 +147,17 @@ const EmployerNoticeDetailPage = ({ notice }: { notice: NoticeCard }) => {
router.push(`/employer/shops/${notice.shopId}/notices/${notice.id}/edit`);
}, [canEdit, isLogin, role, user, notice, router]);

// μ‹ μ²­μž 뢈러였기

// μ‹ μ²­μž 뢈러였기 (νŽ˜μ΄μ§€λ„€μ΄μ…˜)
useEffect(() => {
const fetchApplications = async () => {
const res = await axiosInstance.get<{ items: ApplicationTableApiResponse[] }>(
`/shops/${notice.shopId}/notices/${notice.id}/applications`,
{ params: { offset, limit } }
);
const res = await axiosInstance.get<{
items: ApplicationTableApiResponse[];
total?: number;
count?: number;
hasNext?: boolean;
}>(`/shops/${notice.shopId}/notices/${notice.id}/applications`, {
params: { offset, limit },
});

const tableData: TableRowProps[] = res.data.items.map(app => {
const userItem = app.item.user?.item;
Expand All @@ -180,11 +181,24 @@ const EmployerNoticeDetailPage = ({ notice }: { notice: NoticeCard }) => {
});

setData(tableData);

// total 적용
const apiTotal = res.data.total ?? res.data.count;
if (typeof apiTotal === 'number') {
setTotal(apiTotal);
} else {
const hasNext = res.data.hasNext ?? tableData.length === limit;
const guessed = offset + tableData.length + (hasNext ? 1 : 0);
setTotal(guessed);
}
};

fetchApplications();
}, [notice.shopId, notice.id, offset, limit]);

// 첫 νŽ˜μ΄μ§€μ—μ„œλ„ νŽ˜μ΄μ§€λ„€μ΄μ…˜ 보이도둝 ν‘œμ‹œμš© offset
const displayOffset = total > limit ? (offset === 0 ? 2 : offset) : offset;

return (
<>
<Notice notice={notice} className='py-10 tablet:py-16'>
Expand All @@ -209,14 +223,15 @@ const EmployerNoticeDetailPage = ({ notice }: { notice: NoticeCard }) => {
onSecondary={modal?.onSecondary}
/>
</Notice>

<Container isPage>
<Table
headers={headers}
tableData={data}
userRole='employer'
total={data.length}
total={total} // βœ… 전체 개수
limit={limit}
offset={offset}
offset={displayOffset} // βœ… ν‘œμ‹œμš© offset
onPageChange={setOffset}
onStatusUpdate={(id, newStatus) =>
setData(prev => prev.map(row => (row.id === id ? { ...row, status: newStatus } : row)))
Expand Down
4 changes: 2 additions & 2 deletions src/pages/my-profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function MyProfileDetailPage() {
const currentTotal = rows.length > 0 ? applications.length : stableTotal;

const pagedRows = useMemo(() => currentRows.slice(offset, offset + limit), [currentRows, offset]);

const displayOffset = currentTotal > limit ? (offset === 0 ? 2 : offset) : offset;
return (
<>
{/* ───────────────── 상단 μ˜μ—­ ───────────────── */}
Expand Down Expand Up @@ -197,7 +197,7 @@ export default function MyProfileDetailPage() {
userRole={userType}
total={currentTotal}
limit={limit}
offset={offset}
offset={displayOffset}
onPageChange={setOffset}
onStatusUpdate={() => {}} // βœ… 이 νŽ˜μ΄μ§€μ—μ„œλŠ” μƒνƒœ λ³€κ²½ μ—†μŒ(ν•„μˆ˜ prop λ¬΄ν•΄ν•œ no-op)
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/my-profile/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default function MyProfileRegisterPage() {
{/* μ„ ν˜Έ μ§€μ—­ */}
<div className='flex flex-col'>
<label htmlFor='region' className='mb-2 text-body-m'>
μ„ ν˜Έ μ§€μ—­ {/* ← * 제거 */}
μ„ ν˜Έ μ§€μ—­* {/* ← * 제거 */}
</label>
<Dropdown<AddressCode>
name='region'
Expand Down
Loading