@daeryun/dr_components 1.1.38 → 1.1.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
 
3
- import React from 'react';
3
+ import React, { useState, useEffect } from 'react';
4
+ import { useRouter } from 'next/router';
4
5
 
5
6
  // 스토리북용 전역 타입 선언
6
7
  declare global {
@@ -11,11 +12,11 @@ declare global {
11
12
  }
12
13
  }
13
14
  import Link from 'next/link';
14
- import Pagination from '../../Pagination/Pagination';
15
+ import SearchBar from '../../SearchBar/SearchBar';
16
+ import PaginationComponent from '../../page/MyCase/_component/_pagination/PaginationComponent';
15
17
  import PageTitleBox from '../../PageTitleBox/PageTitleBox';
16
18
  import { ImgTypes } from '../../PageTitleBox/ImgTypes';
17
19
  import PageWrapper from '../../Layout/PageWrapper';
18
- import SearchBar from '../../SearchBar/SearchBar';
19
20
 
20
21
  // 공지사항 데이터 타입 정의
21
22
  interface INoticeTypes {
@@ -27,52 +28,98 @@ interface INoticeTypes {
27
28
  timestamp?: string;
28
29
  }
29
30
 
30
- interface ISearchBarProps {
31
- handleInputChange: (e: React.FormEvent<HTMLInputElement>) => void;
32
- handleSearch: () => void;
33
- searchInput: string;
34
- }
35
- interface IPaginationProps {
36
- onPaginationChange: (pageNum: number) => void;
37
- currentPage: number;
38
- totalCount: number;
31
+ interface NoticeCategory {
32
+ code: string;
33
+ code_name: string | null;
34
+ [key: string]: any;
39
35
  }
40
36
 
41
37
  interface NoticeListProps {
42
- SearchBarProps: ISearchBarProps;
43
- PaginationProps: IPaginationProps;
44
- noticeName: {
45
- code: string;
46
- code_name: string | null;
47
- [key: string]: any;
48
- }[];
49
38
  noticeList: INoticeTypes[];
50
- currentCodeDesc?: string;
51
- isUseHeaderComponent?: boolean;
52
- nameFilter: { code_name: string; code: string };
53
- search: string;
54
- indexOfFirstPost: number;
55
- indexOfLastPost: number;
56
- postPerPage: number;
57
- currentPage: number;
58
- router: any;
39
+ noticeName: NoticeCategory[];
59
40
  }
60
41
 
61
- const NoticeList = ({
62
- SearchBarProps,
63
- PaginationProps,
64
- noticeName,
65
- noticeList,
66
- currentCodeDesc,
67
- isUseHeaderComponent,
68
- nameFilter,
69
- search,
70
- indexOfFirstPost,
71
- indexOfLastPost,
72
- postPerPage,
73
- currentPage,
74
- router
75
- }: NoticeListProps) => {
42
+ const NoticeList = ({ noticeList, noticeName }: NoticeListProps) => {
43
+ const router = useRouter();
44
+
45
+ // 내부 상태 관리
46
+ const [search, setSearch] = useState<string>('');
47
+ const [searchInput, setSearchInput] = useState<string>('');
48
+ const [nameFilter, setNameFilter] = useState<{ code_name: string; code: string }>({
49
+ code_name: '전체',
50
+ code: ''
51
+ });
52
+ const [currentPage, setCurrentPage] = useState<number>(1);
53
+ const [filteredList, setFilteredList] = useState<INoticeTypes[]>(noticeList);
54
+ const [total, setTotal] = useState<number>(noticeList.length);
55
+
56
+ const postPerPage = 10;
57
+ const indexOfLastPost = currentPage * postPerPage;
58
+ const indexOfFirstPost = indexOfLastPost - postPerPage;
59
+
60
+ // 검색 및 필터링 로직
61
+ useEffect(() => {
62
+ const searchTxt = String(router.query.search || '').toLowerCase();
63
+ const searchFilter = String(router.query.nameFilter || '');
64
+
65
+ let searchResultList = [];
66
+
67
+ if (!searchFilter || searchFilter === '전체') {
68
+ searchResultList = noticeList?.filter(
69
+ (item: any) =>
70
+ item.title?.toLowerCase().includes(searchTxt) || item.summary?.toLowerCase().includes(searchTxt)
71
+ );
72
+ setNameFilter({ code_name: '전체', code: '' });
73
+ } else {
74
+ const filterNameList = noticeList.filter((item: any) => item.code_name === searchFilter);
75
+ searchResultList = filterNameList?.filter(
76
+ (item: any) =>
77
+ item.title?.toLowerCase().includes(searchTxt) || item.summary?.toLowerCase().includes(searchTxt)
78
+ );
79
+ const code = noticeName.find((name: any) => name.code_name === searchFilter)?.code || '';
80
+ setNameFilter({ code_name: searchFilter, code });
81
+ }
82
+
83
+ setFilteredList(searchResultList);
84
+ setTotal(searchResultList.length);
85
+ setSearch(searchTxt || '');
86
+ setSearchInput(searchTxt || '');
87
+ setCurrentPage(Number(router.query.page) || 1);
88
+ }, [router.query.search, router.query.nameFilter, router.query.page, noticeList, noticeName]);
89
+
90
+ // 핸들러 함수들
91
+ const handleInputChange = (e: React.FormEvent<HTMLInputElement>) => {
92
+ setSearchInput(e.currentTarget.value);
93
+ };
94
+
95
+ const handleSearch = () => {
96
+ router.push({
97
+ pathname: '/notice',
98
+ query: searchInput
99
+ ? { page: 1, search: searchInput, nameFilter: nameFilter.code_name }
100
+ : { page: 1, nameFilter: nameFilter.code_name }
101
+ });
102
+ setSearch(searchInput);
103
+ };
104
+
105
+ const handlePaginationChange = (pageNum: number) => {
106
+ router.push({
107
+ pathname: '/notice',
108
+ query: search
109
+ ? { page: pageNum, search: search, nameFilter: nameFilter.code_name }
110
+ : { page: pageNum, nameFilter: nameFilter.code_name }
111
+ });
112
+ };
113
+
114
+ const handleCategoryClick = (categoryName: string) => {
115
+ router.push({
116
+ pathname: '/notice',
117
+ query: search
118
+ ? { page: 1, search: search, nameFilter: categoryName }
119
+ : { page: 1, nameFilter: categoryName }
120
+ });
121
+ };
122
+
76
123
  return (
77
124
  <>
78
125
  <PageTitleBox
@@ -90,9 +137,9 @@ const NoticeList = ({
90
137
  <PageWrapper>
91
138
  <SearchBar
92
139
  label={'검색어를 입력해주세요.'}
93
- onChange={SearchBarProps.handleInputChange}
94
- onClick={SearchBarProps.handleSearch}
95
- search={SearchBarProps.searchInput}
140
+ onChange={handleInputChange}
141
+ onClick={handleSearch}
142
+ search={searchInput}
96
143
  placeholder={'검색어를 입력해주세요.'}
97
144
  isKeyPress={true}
98
145
  marginTop={[70, 50, 50]}
@@ -109,22 +156,10 @@ const NoticeList = ({
109
156
  ? 'bg-[#285FA7] text-[#fff]'
110
157
  : "after:absolute after:right-[-1px] after:z-[-1] after:h-[45%] after:w-[1px] after:bg-[#DBDBDB] after:content-['']"
111
158
  } relative w-[20%] py-3 text-[13px] 2xs:text-[16px] xs:py-4 sm:text-[22px]`}
112
- onClick={() => {
113
- router.push({
114
- pathname: '/notice',
115
- query: search
116
- ? { page: 1, search: search, nameFilter: '전체' }
117
- : { page: 1, nameFilter: '전체' }
118
- });
119
- }}
159
+ onClick={() => handleCategoryClick('전체')}
120
160
  onKeyDown={(e: any) => {
121
161
  if (e.key === 'Enter') {
122
- router.push({
123
- pathname: '/notice',
124
- query: search
125
- ? { page: 1, search: search, nameFilter: '전체' }
126
- : { page: 1, nameFilter: '전체' }
127
- });
162
+ handleCategoryClick('전체');
128
163
  }
129
164
  }}
130
165
  >
@@ -139,22 +174,10 @@ const NoticeList = ({
139
174
  ? 'bg-[#285FA7] text-[#fff] '
140
175
  : "after:absolute after:right-[-1px] after:z-[-1] after:h-[45%] after:w-[1px] after:bg-[#DBDBDB] after:content-['']"
141
176
  } relative w-[20%] py-3 text-[13px] 2xs:text-[16px] xs:py-4 sm:text-[22px]`}
142
- onClick={() => {
143
- router.push({
144
- pathname: '/notice',
145
- query: search
146
- ? { page: 1, search: search, nameFilter: item.code_name }
147
- : { page: 1, nameFilter: item.code_name }
148
- });
149
- }}
177
+ onClick={() => handleCategoryClick(item.code_name)}
150
178
  onKeyDown={(e: any) => {
151
179
  if (e.key === 'Enter') {
152
- router.push({
153
- pathname: '/notice',
154
- query: search
155
- ? { page: 1, search: search, nameFilter: item.code_name }
156
- : { page: 1, nameFilter: item.code_name }
157
- });
180
+ handleCategoryClick(item.code_name);
158
181
  }
159
182
  }}
160
183
  >
@@ -167,7 +190,6 @@ const NoticeList = ({
167
190
  <colgroup className={''}>
168
191
  <col className={'sm:w-[10%]'} />
169
192
  <col width="55" className={'w-[75%] max-xs:w-[70%]'} />
170
- {/* <col className={'w-[15%] max-xs:w-[20%]'} /> */}
171
193
  </colgroup>
172
194
 
173
195
  <thead>
@@ -188,52 +210,40 @@ const NoticeList = ({
188
210
  >
189
211
  제목
190
212
  </th>
191
- {/* <th
192
- scope="col"
193
- className={
194
- 'py-[15px] border-b-[1px] border-[#d2d2d2] border-solid text-[16px] font-[800] max-sm:text-xs'
195
- }
196
- >
197
- 작성일
198
- </th> */}
199
213
  </tr>
200
214
  </thead>
201
215
 
202
216
  <tbody>
203
- {noticeList.length > 0 && noticeList.slice(indexOfFirstPost, indexOfLastPost).length > 0 ? (
204
- noticeList.slice(indexOfFirstPost, indexOfLastPost).map((item: any, index: number) => (
205
- <tr key={item.id} className={''}>
206
- <td
207
- className={
208
- 'border-b-[1px] border-solid border-[#d2d2d2] py-[15px] text-center sm:text-[16px]'
209
- }
210
- >
211
- {noticeList.length -
212
- (index + 1 + currentPage * postPerPage) +
213
- postPerPage +
214
- 1}
215
- </td>
216
- <td
217
- className={
218
- 'border-b-[1px] border-solid border-[#d2d2d2] py-[15px] sm:text-[16px]'
219
- }
220
- >
221
- <Link href={'/notice/' + item.id}>
222
- <div>
223
- <div className={'truncate'}>{item.title}</div>
224
- </div>
225
- </Link>
226
- </td>
227
- {/* <td
217
+ {filteredList.length > 0 &&
218
+ filteredList.slice(indexOfFirstPost, indexOfLastPost).length > 0 ? (
219
+ filteredList
220
+ .slice(indexOfFirstPost, indexOfLastPost)
221
+ .map((item: any, index: number) => (
222
+ <tr key={item.id} className={''}>
223
+ <td
224
+ className={
225
+ 'border-b-[1px] border-solid border-[#d2d2d2] py-[15px] text-center sm:text-[16px]'
226
+ }
227
+ >
228
+ {filteredList.length -
229
+ (index + 1 + currentPage * postPerPage) +
230
+ postPerPage +
231
+ 1}
232
+ </td>
233
+ <td
228
234
  className={
229
- 'text-center py-[15px] border-b-[1px] border-[#d2d2d2] border-solid sm:text-[16px] tracking-[-1px]'
235
+ 'border-b-[1px] border-solid border-[#d2d2d2] py-[15px] sm:text-[16px]'
230
236
  }
231
237
  >
232
- {item.timestamp}
233
- </td> */}
234
- </tr>
235
- ))
236
- ) : noticeList.length < 1 ? (
238
+ <Link href={'/notice/' + item.id}>
239
+ <div>
240
+ <div className={'truncate'}>{item.title}</div>
241
+ </div>
242
+ </Link>
243
+ </td>
244
+ </tr>
245
+ ))
246
+ ) : filteredList.length < 1 ? (
237
247
  <tr>
238
248
  <td
239
249
  colSpan={2}
@@ -263,20 +273,16 @@ const NoticeList = ({
263
273
  )}
264
274
  </tbody>
265
275
  </table>
266
- {noticeList && noticeList.length > 0 ? (
267
- <div className={'mb-[100px] max-lg:mb-[70px] max-xs:mb-[64px]'}>
268
- <Pagination
269
- currentPage={PaginationProps.currentPage}
270
- onPageChange={PaginationProps.onPaginationChange}
271
- totalPages={Math.ceil(PaginationProps.totalCount / 9)}
272
- />
273
- </div>
274
- ) : (
275
- <></>
276
- )}
276
+ <PaginationComponent
277
+ pageSize={postPerPage}
278
+ total={total}
279
+ onChange={handlePaginationChange}
280
+ current={currentPage}
281
+ />
277
282
  </div>
278
283
  </PageWrapper>
279
284
  </>
280
285
  );
281
286
  };
287
+
282
288
  export default NoticeList;
@@ -107,7 +107,7 @@
107
107
  }
108
108
 
109
109
  /*
110
- ! tailwindcss v3.4.18 | MIT License | https://tailwindcss.com
110
+ ! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com
111
111
  */
112
112
 
113
113
  /*
@@ -3283,10 +3283,6 @@ html {
3283
3283
  width: 14px;
3284
3284
  }
3285
3285
 
3286
- .w-\[15\%\] {
3287
- width: 15%;
3288
- }
3289
-
3290
3286
  .w-\[150px\] {
3291
3287
  width: 150px;
3292
3288
  }
@@ -9031,16 +9027,20 @@ html {
9031
9027
 
9032
9028
  .backdrop-blur-\[4px\] {
9033
9029
  --tw-backdrop-blur: blur(4px);
9030
+ -webkit-backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);
9034
9031
  backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);
9035
9032
  }
9036
9033
 
9037
9034
  .backdrop-blur-sm {
9038
9035
  --tw-backdrop-blur: blur(4px);
9036
+ -webkit-backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);
9039
9037
  backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);
9040
9038
  }
9041
9039
 
9042
9040
  .transition {
9041
+ transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, -webkit-backdrop-filter;
9043
9042
  transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
9043
+ transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter, -webkit-backdrop-filter;
9044
9044
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
9045
9045
  transition-duration: 150ms;
9046
9046
  }
@@ -17903,10 +17903,6 @@ body {
17903
17903
  margin-bottom: 60px;
17904
17904
  }
17905
17905
 
17906
- .max-xs\:mb-\[64px\] {
17907
- margin-bottom: 64px;
17908
- }
17909
-
17910
17906
  .max-xs\:mb-\[70px\] {
17911
17907
  margin-bottom: 70px;
17912
17908
  }
@@ -18163,10 +18159,6 @@ body {
18163
18159
  width: 192px;
18164
18160
  }
18165
18161
 
18166
- .max-xs\:w-\[20\%\] {
18167
- width: 20%;
18168
- }
18169
-
18170
18162
  .max-xs\:w-\[200px\] {
18171
18163
  width: 200px;
18172
18164
  }