Skip to content

Commit b80ece0

Browse files
authored
Refactor/109/columns (#115)
* 💄 feat : 컬럼 empty list 구현 * ♻️ refactor : 컬럼 중복 이름 생성 방지
1 parent 51c72de commit b80ece0

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

src/components/columns/AddColumnBtn.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { ColumnForm, columnFormSchema } from '@/apis/columns/types';
3+
import { ColumnForm, columnFormSchema, ColumnsResponse } from '@/apis/columns/types';
44
import DashboardButton from '@/components/ui/Button/DashboardButton';
55
import { zodResolver } from '@hookform/resolvers/zod';
66
import { useForm } from 'react-hook-form';
@@ -13,20 +13,28 @@ import { useColumnMutation } from '@/apis/columns/queries';
1313
import { getErrorMessage } from '@/utils/errorMessage';
1414
import xIcon from '@/assets/icons/x.svg';
1515
import Image from 'next/image';
16+
import { some } from 'es-toolkit/compat';
1617

17-
export default function AddColumnBtn({ dashboardId }: { dashboardId: number }) {
18+
interface AddColumnBtnProps {
19+
dashboardId: number;
20+
columns: ColumnsResponse['data'] | void;
21+
}
22+
23+
export default function AddColumnBtn({ dashboardId, columns }: AddColumnBtnProps) {
1824
const {
1925
handleSubmit,
2026
register,
2127
reset,
2228
formState: { errors, isValid, isSubmitting, isDirty },
29+
setError,
2330
} = useForm<ColumnForm>({
2431
resolver: zodResolver(columnFormSchema),
2532
mode: 'onChange',
2633
defaultValues: {
2734
title: '',
2835
},
2936
});
37+
3038
const modalRef = useRef<ModalHandle>(null);
3139
const { create } = useColumnMutation(dashboardId);
3240
const alert = useAlert();
@@ -38,6 +46,14 @@ export default function AddColumnBtn({ dashboardId }: { dashboardId: number }) {
3846

3947
const onSubmit = async (formData: ColumnForm) => {
4048
try {
49+
if (columns) {
50+
const isExist = some(columns, { title: formData.title });
51+
if (isExist) {
52+
setError('title', { message: '중복된 컬럼 이름입니다.' });
53+
return;
54+
}
55+
}
56+
4157
await create(formData);
4258
handleReset();
4359
alert('컬럼이 생성되었습니다!');

src/components/columns/ColumnList.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useColumnsQuery } from '@/apis/columns/queries';
44
import { useParams } from 'next/navigation';
55
import ColumnItem from './ColumnItem';
66
import AddColumnBtn from './AddColumnBtn';
7+
import { isEmpty } from 'es-toolkit/compat';
78

89
export default function ColumnList() {
910
const params = useParams();
@@ -13,12 +14,17 @@ export default function ColumnList() {
1314
return (
1415
<ul className='flex flex-col lg:flex-row'>
1516
{isLoading && Array.from({ length: 3 }, (_, index) => <SkeletionItem key={index} />)}
16-
{data?.data.map((column) => (
17-
<li key={column.id} className='flex flex-col gap-4 border-b border-r-0 p-6 lg:min-h-[calc(100dvh-70px)] lg:border-b-0 lg:border-r'>
18-
<ColumnItem column={column} />
19-
</li>
20-
))}
21-
<AddColumnBtn dashboardId={dashbaordId} />
17+
18+
{!isLoading && isEmpty(data?.data) ? (
19+
<EmptyList />
20+
) : (
21+
data?.data.map((column) => (
22+
<li key={column.id} className='flex flex-col gap-4 border-b border-r-0 p-6 lg:min-h-[calc(100dvh-70px)] lg:border-b-0 lg:border-r'>
23+
<ColumnItem column={column} />
24+
</li>
25+
))
26+
)}
27+
<AddColumnBtn dashboardId={dashbaordId} columns={data?.data} />
2228
</ul>
2329
);
2430
}
@@ -40,3 +46,14 @@ export function SkeletionItem() {
4046
</li>
4147
);
4248
}
49+
50+
function EmptyList() {
51+
return (
52+
<li className='flex animate-pulse flex-col items-center gap-4 border-b border-r-0 p-6 lg:min-h-[calc(100dvh-70px)] lg:border-b-0 lg:border-r'>
53+
<p className='gray-300 w-56 text-center'>컬럼이 비어있습니다.</p>
54+
<div className='flex h-12 w-full items-center justify-center rounded bg-gray-200'>
55+
<div className='h-6 w-6 rounded bg-gray-300' />
56+
</div>
57+
</li>
58+
);
59+
}

0 commit comments

Comments
 (0)