-
Notifications
You must be signed in to change notification settings - Fork 4
[✨feat] 테이블 생성 #6 #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gummmmmy0v0
merged 12 commits into
codeit-FE18-part3:develop
from
gummmmmy0v0:feature/#6-1
Oct 1, 2025
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
70a7d18
✨feat: 테이블 생성, getTime 함수 #6
gummmmmy0v0 0ddc5f7
✨feat: 스토리북 추가 #6
gummmmmy0v0 fb9721f
✨feat: testApi 추가 #6
gummmmmy0v0 00b79a5
🔧chore: tsconfig.json babel 오류로 types 추가 #6
gummmmmy0v0 a5c1e80
🔧 chore: 불필요한 패키지 삭제 및 스토리북 패키지 재설치 #6
gummmmmy0v0 88db714
🔧chore: package-lock.json esbuild 관련 삭제
gummmmmy0v0 e838ef6
🔧chore: node_modules 재설치로 tsconfig.json 원상복구
gummmmmy0v0 d1a2714
🔧chore: package-lock.json 원상복구 #6
gummmmmy0v0 b18e42c
♻️ refactor: 중복 스타일링 상수 변경 #6
gummmmmy0v0 1fa7f04
♻️ refactor: getTime 함수 start / end 구분 #6
gummmmmy0v0 0f5152e
♻️ refactor: TableRow 변경된 getTime 적용 #6
gummmmmy0v0 1005076
♻️ refactor: 테이블 thead 추가 #6
gummmmmy0v0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import Table from '@/components/ui/table/Table'; | ||
| import { TableRowProps } from '@/components/ui/table/TableRowProps'; | ||
| import { Meta, StoryObj } from '@storybook/nextjs'; | ||
| import { useEffect, useState } from 'react'; | ||
| import { fetchTableData, UserType } from './testApi'; | ||
|
|
||
| const meta: Meta<typeof Table> = { | ||
| title: 'UI/Table', | ||
| component: Table, | ||
| argTypes: { | ||
| userType: { | ||
| control: { type: 'radio' }, | ||
| options: ['employer', 'employee'], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof Table>; | ||
|
|
||
| function TableWithTestApi({ userType }: { userType: UserType }) { | ||
| const [headers, setHeaders] = useState<string[]>([]); | ||
| const [data, setData] = useState<TableRowProps[]>([]); | ||
|
|
||
| useEffect(() => { | ||
| const getData = async () => { | ||
| const res = await fetchTableData(userType); | ||
| setHeaders(res.headers); | ||
| setData(res.data as TableRowProps[]); | ||
| }; | ||
| getData(); | ||
| }, [userType]); | ||
|
|
||
| return <Table headers={headers} data={data} userType={userType} />; | ||
| } | ||
|
|
||
| export const TableExample: Story = { | ||
| args: { | ||
| userType: 'employer', | ||
| }, | ||
| render: args => <TableWithTestApi userType={args.userType} />, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import TableRow from '@/components/ui/table/TableRow'; | ||
| import { TableRowProps } from '@/components/ui/table/TableRowProps'; | ||
|
|
||
| interface TableProps { | ||
| data: TableRowProps[]; | ||
| headers: string[]; | ||
| userType: 'employer' | 'employee'; | ||
| } | ||
|
|
||
| // <Table headers={headers} data={data} userType={type} /> type은 확인이 좀 더 필요합니다 | ||
|
|
||
| export default function Table({ data, headers, userType }: TableProps) { | ||
| return ( | ||
| <div className='overflow-x-auto rounded-lg border border-gray-200'> | ||
| <table className='min-w-full'> | ||
| <tbody> | ||
| <tr className='bg-red-100'> | ||
| {headers.map((header, index) => ( | ||
| <th key={index} className='px-2 py-3 text-left text-sm font-normal'> | ||
| {header} | ||
| </th> | ||
| ))} | ||
| </tr> | ||
| {data.map((row, index) => ( | ||
| <TableRow key={index} rowData={row} variant={userType} /> | ||
| ))} | ||
| </tbody> | ||
gummmmmy0v0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </table> | ||
| <div className='flex justify-center px-3 py-2'>페이지네이션</div> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { TableRowProps } from '@/components/ui/table/TableRowProps'; | ||
| import { getTime } from '@/lib/utils/getTime'; | ||
|
|
||
| interface TableTypeVariant { | ||
| rowData: TableRowProps; | ||
| variant: 'employer' | 'employee'; | ||
| } | ||
|
|
||
| export default function TableRow({ rowData, variant }: TableTypeVariant) { | ||
| if (variant === 'employee') { | ||
| return ( | ||
| <tr className='text-left'> | ||
| <td className='border-b px-2 py-3'>{rowData.name}</td> | ||
| <td className='border-b px-2 py-3'> | ||
| {`${getTime(rowData.startsAt, 0)} ~ ${getTime(rowData.startsAt, rowData.workhour)} (${rowData.workhour}시간)`} | ||
| </td> | ||
| <td className='border-b px-2 py-3'>{rowData.hourlyPay}</td> | ||
| <td className='border-b px-2 py-[9px]'>{rowData.status}</td> | ||
| </tr> | ||
| ); | ||
| } | ||
| return ( | ||
| <tr className='text-left'> | ||
| <td className='border-b px-2 py-3'>{rowData.name}</td> | ||
| <td className='border-b px-2 py-3'>{rowData.bio}</td> | ||
| <td className='border-b px-2 py-3'>{rowData.phone}</td> | ||
| <td className='border-b px-2 py-[9px]'>{rowData.status}</td> | ||
| </tr> | ||
| ); | ||
gummmmmy0v0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export type TableRowProps = { | ||
| name: string; | ||
| startsAt: string; | ||
| workhour: number; | ||
| hourlyPay: string; | ||
| status: string | JSX.Element; | ||
| bio: string; | ||
| phone: number; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default as Table } from '@/components/ui/table/Table'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| export type UserType = 'employer' | 'employee'; | ||
gummmmmy0v0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const fetchTableData = async (userType: UserType) => { | ||
| return new Promise<{ headers: string[]; data: unknown[] }>(resolve => { | ||
| setTimeout(() => { | ||
| if (userType === 'employer') { | ||
| resolve({ | ||
| headers: ['신청자', '소개', '전화번호', '상태'], | ||
| data: [ | ||
| { | ||
| name: '김강현', | ||
| bio: '최선을 다해 열심히 일합니다. 다수의 업무 경험을 바탕으로 확실한 일처리 보여드리겠습니다.', | ||
| phone: '010-1234-5678', | ||
| status: '버튼', | ||
| }, | ||
| { | ||
| name: '서혜진', | ||
| bio: '열심히 하겠습니다!', | ||
| phone: '010-0000-0000', | ||
| status: 'rejected', | ||
| }, | ||
| { | ||
| name: '주진혁', | ||
| bio: '성실한 자세로 열심히 일합니다.', | ||
| phone: '010-0000-0000', | ||
| status: 'accepted', | ||
| }, | ||
| { | ||
| name: '장민혁', | ||
| bio: '일을 꼼꼼하게 하는 성격입니다.', | ||
| phone: '010-0000-0000', | ||
| status: 'accepted', | ||
| }, | ||
| { | ||
| name: '고기훈', | ||
| bio: '하루라도 최선을 다해서 일하겠습니다!', | ||
| phone: '010-0000-0000', | ||
| status: 'accepted', | ||
| }, | ||
| ], | ||
| }); | ||
| } else { | ||
| resolve({ | ||
| headers: ['가게', '일자', '시급', '상태'], | ||
| data: [ | ||
| { | ||
| name: '너구리네 라면집', | ||
| startsAt: '2025-10-01T11:00', | ||
| workhour: 2, | ||
| hourlyPay: '12,500원', | ||
| status: 'accepted', | ||
| }, | ||
| { | ||
| name: '너구리네 라면집', | ||
| startsAt: '2025-10-01T11:00', | ||
| workhour: 2, | ||
| hourlyPay: '12,500원', | ||
| status: 'rejected', | ||
| }, | ||
| { | ||
| name: '너구리네 라면집', | ||
| startsAt: '2025-10-01T11:00', | ||
| workhour: 2, | ||
| hourlyPay: '12,500원', | ||
| status: 'accepted', | ||
| }, | ||
| { | ||
| name: '너구리네 라면집', | ||
| startsAt: '2025-10-01T11:00', | ||
| workhour: 2, | ||
| hourlyPay: '12,500원', | ||
| status: 'accepted', | ||
| }, | ||
| { | ||
| name: '너구리네 라면집', | ||
| startsAt: '2025-10-01T11:00', | ||
| workhour: 2, | ||
| hourlyPay: '12,500원', | ||
| status: 'accepted', | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| export function getTime(startsAt: string, workhour: number): string { | ||
| const startDate = new Date(startsAt); | ||
| startDate.setHours(startDate.getHours() + workhour); | ||
|
|
||
| const year = startDate.getFullYear(); | ||
| const month = String(startDate.getMonth() + 1).padStart(2, '0'); | ||
| const day = String(startDate.getDate()).padStart(2, '0'); | ||
| const hours = String(startDate.getHours()).padStart(2, '0'); | ||
| const minutes = String(startDate.getMinutes()).padStart(2, '0'); | ||
|
|
||
| return `${year}.${month}.${day} ${hours}:${minutes}`; | ||
| } | ||
gummmmmy0v0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.