Skip to content
Merged
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
128 changes: 51 additions & 77 deletions src/pages/my-profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import Image from 'next/image';
import Link from 'next/link';
import { useEffect, useMemo, useState } from 'react';

import { Container } from '@/components/layout'; // โœ… my-shop๊ณผ ๋™์ผ ํŒจํ„ด
import Frame from '@/components/layout/frame/frame';
import Button from '@/components/ui/button/button';
import Table from '@/components/ui/table/Table';
import type { TableRowProps } from '@/components/ui/table/TableRowProps';

import { ICONS, ICON_SIZES } from '@/constants/icon';
import { useUserApplications } from '@/context/userApplicationsProvider';
import useAuth from '@/hooks/useAuth';

import type { TableRowProps } from '@/components/ui/table/TableRowProps';
import type { ApiResponse } from '@/types/api';
import type { ApplicationItem } from '@/types/applications';
import type { User, UserType } from '@/types/user';
Expand All @@ -22,8 +25,6 @@ export default function MyProfileDetailPage() {
const [offset, setOffset] = useState(0);
const limit = 5;

const [tableRows, setTableRows] = useState<TableRowProps[]>([]);

// ํ”„๋กœํ•„ ๋น„์—ˆ๋Š”์ง€ ํŒ๋‹จ (User | null ์•ˆ์ „)
function isProfileEmpty(u: User | null): boolean {
const name = u?.name?.trim() ?? '';
Expand All @@ -37,12 +38,13 @@ export default function MyProfileDetailPage() {
const headers: string[] = ['๊ฐ€๊ฒŒ๋ช…', '๊ทผ๋ฌด์ผ์‹œ', '์‹œ๊ธ‰', '์ƒํƒœ'];
const userType: UserType = 'employee';

// ์„œ๋ฒ„ ์‘๋‹ต โ†’ TableRowProps ๋งคํ•‘
// ์„œ๋ฒ„ ์‘๋‹ต โ†’ TableRowProps ๋งคํ•‘ (shopId/noticeId ํฌํ•จ)
const rows: TableRowProps[] = useMemo(() => {
return applications.map((app: ApiResponse<ApplicationItem>) => {
const a = app.item;
const status =
a.status === 'accepted' ? 'approved' : a.status === 'rejected' ? 'rejected' : 'pending';

return {
id: a.id,
name: a.shop.item.name,
Expand All @@ -52,6 +54,7 @@ export default function MyProfileDetailPage() {
status,
bio: '',
phone: '',
// โœ… TableRow๊ฐ€ ์š”๊ตฌํ•˜๋Š” ํ‚ค ์ฑ„์›€
shopId: a.shop.item.id,
noticeId: a.notice.item.id,
};
Expand All @@ -78,46 +81,20 @@ export default function MyProfileDetailPage() {

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

useEffect(() => {
const mappedRows: TableRowProps[] = applications.map(app => {
const a = app.item;
const status =
a.status === 'accepted' ? 'approved' : a.status === 'rejected' ? 'rejected' : 'pending';
return {
id: a.id,
name: a.shop.item.name,
hourlyPay: `${a.notice.item.hourlyPay.toLocaleString()}์›`,
startsAt: a.notice.item.startsAt,
workhour: a.notice.item.workhour,
status,
bio: '',
phone: '',
shopId: a.shop.item.id,
noticeId: a.notice.item.id,
};
});

setTableRows(mappedRows);
}, [applications]);

return (
<main className='mx-auto w-full max-w-[1440px] py-6 tablet:py-8'>
{/* ๊ณตํ†ต ์ปจํ…Œ์ด๋„ˆ: Table๊ณผ ์ขŒ์ธก์„ /ํญ ๋™์ผ */}
<div className='mx-auto w-full max-w-full px-8 md:px-10 lg:mx-auto lg:max-w-[1000px] lg:px-0'>
{profileIsEmpty ? (
<>
<h1 className='mb-6 text-heading-l font-semibold'>๋‚ด ํ”„๋กœํ•„</h1>
<div className='mx-auto w-full'>
<Frame
title=''
content='๋‚ด ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ  ์›ํ•˜๋Š” ๊ฐ€๊ฒŒ์— ์ง€์›ํ•ด ๋ณด์„ธ์š”.'
buttonText='๋‚ด ํ”„๋กœํ•„ ๋“ฑ๋กํ•˜๊ธฐ'
href='/my-profile/register'
/>
</div>
</>
) : (
// โœ… ๋ฐ์Šคํฌํƒ‘์—์„œ ์ œ๋ชฉ๊ณผ ์นด๋“œ๊ฐ€ ๊ฐ™์€ flex ๋ผ์ธ์— ๋†“์ด๋„๋ก
{/* โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ ์ƒ๋‹จ ์˜์—ญ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ */}
{profileIsEmpty ? (
// โœ… 2์ค‘ ์ปจํ…Œ์ด๋„ˆ ์ œ๊ฑฐ: Frame๋งŒ ๋‹จ๋… ๋ Œ๋”
<Frame
title='๋‚ด ํ”„๋กœํ•„'
content='๋‚ด ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ  ์›ํ•˜๋Š” ๊ฐ€๊ฒŒ์— ์ง€์›ํ•ด ๋ณด์„ธ์š”.'
buttonText='๋‚ด ํ”„๋กœํ•„ ๋“ฑ๋กํ•˜๊ธฐ'
href='/my-profile/register'
/>
) : (
// โœ… ๊ณต์šฉ Container๋กœ ๊ฐ์‹ธ์„œ my-shop๊ณผ ๋™์ผํ•œ ๋ ˆ์ด์•„์›ƒ ํŒจํ„ด
<Container as='section' isPage>
<div className='desktop:flex desktop:items-start desktop:gap-8'>
<h1 className='mb-6 text-heading-l font-semibold desktop:mb-0 desktop:w-[200px] desktop:shrink-0 desktop:pt-2'>
๋‚ด ํ”„๋กœํ•„
Expand Down Expand Up @@ -185,52 +162,49 @@ export default function MyProfileDetailPage() {
</div>
</section>
</div>
)}
</div>
</Container>
)}

{/* ํ•˜๋‹จ: ์‹ ์ฒญ ๋‚ด์—ญ โ€” ํ”„๋กœํ•„ ์žˆ๊ณ  ๋กœ๊ทธ์ธ ์ƒํƒœ์ผ ๋•Œ๋งŒ */}
{/* โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ ํ•˜๋‹จ: ์‹ ์ฒญ ๋‚ด์—ญ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ */}
{!profileIsEmpty && isLogin && (
<section className='mt-8 bg-[var(--gray-50)] py-8'>
<div className='mx-auto w-full max-w-full px-8 md:px-10 lg:mx-auto lg:max-w-[1000px] lg:px-0'>
{isLoading && currentRows.length === 0 ? (
<>
<div className='px-0 text-xl font-bold'>
<h2 className='text-heading-l font-semibold'>์‹ ์ฒญ ๋‚ด์—ญ</h2>
</div>
<div className='m-7 overflow-hidden rounded-lg border bg-white lg:mx-auto lg:max-w-[1000px]'>
<div className='h-[48px] bg-[var(--red-100)]' />
{[...Array(5)].map((_, i) => (
<div key={i} className='h-[56px] border-t bg-white last:border-b' />
))}
<div className='flex justify-center px-3 py-2' />
</div>
</>
) : currentRows.length === 0 ? (
<Frame
title='์‹ ์ฒญ ๋‚ด์—ญ'
content='๋งˆ์Œ์— ๋“œ๋Š” ๊ณต๊ณ ๋ฅผ ์ฐพ์•„ ์ง€์›ํ•ด ๋ณด์„ธ์š”.'
buttonText='๊ณต๊ณ  ๋ณด๋Ÿฌ๊ฐ€๊ธฐ'
href='/notices'
/>
) : (
<div className='mx-auto w-full desktop:max-w-[964px]'>
<section className='mt-8 bg-[var(--gray-50)] pb-8 pt-0 tablet:pt-8'>
{isLoading && currentRows.length === 0 ? (
<Container as='section' isPage className='pt-0'>
<div className='px-0 text-xl font-bold'>
<h2 className='text-heading-l font-semibold'>์‹ ์ฒญ ๋‚ด์—ญ</h2>
</div>
<div className='m-7 overflow-hidden rounded-lg border bg-white lg:mx-auto lg:max-w-[1000px]'>
<div className='h-[48px] bg-[var(--red-100)]' />
{[...Array(5)].map((_, i) => (
<div key={i} className='h-[56px] border-t bg-white last:border-b' />
))}
<div className='flex justify-center px-3 py-2' />
</div>
</Container>
) : currentRows.length === 0 ? (
// โœ… 2์ค‘ ์ปจํ…Œ์ด๋„ˆ ์ œ๊ฑฐ: Frame๋งŒ ๋‹จ๋… ๋ Œ๋”
<Frame
title='์‹ ์ฒญ ๋‚ด์—ญ'
content='๋งˆ์Œ์— ๋“œ๋Š” ๊ณต๊ณ ๋ฅผ ์ฐพ์•„ ์ง€์›ํ•ด ๋ณด์„ธ์š”.'
buttonText='๊ณต๊ณ  ๋ณด๋Ÿฌ๊ฐ€๊ธฐ'
href='/notices'
/>
) : (
<Container as='section' isPage className='pt-0'>
<div className='mx-auto w-full lg:mx-auto lg:max-w-[1000px]'>
<Table
headers={headers}
tableData={pagedRows}
userRole={userType}
total={applications.length}
total={currentTotal}
limit={limit}
offset={offset}
onPageChange={setOffset}
onStatusUpdate={(id, newStatus) =>
setTableRows(prev =>
prev.map(row => (row.id === id ? { ...row, status: newStatus } : row))
)
}
onStatusUpdate={() => {}} // โœ… ์ด ํŽ˜์ด์ง€์—์„œ๋Š” ์ƒํƒœ ๋ณ€๊ฒฝ ์—†์Œ(ํ•„์ˆ˜ prop ๋ฌดํ•ดํ•œ no-op)
/>
</div>
)}
</div>
</Container>
)}
</section>
)}
</main>
Expand Down
Loading