Skip to content

Commit bdf5e66

Browse files
committed
feat : 문의보기 preview 별도 훅으로 생성
1 parent 4dcf410 commit bdf5e66

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

src/api/customerService.api.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ export const getNotice = async (params: NoticeSearch) => {
2929
}
3030
};
3131

32+
export const getNoticePreview = async () => {
33+
try {
34+
const response = await httpClient.get<ApiNotice>(`/notice`);
35+
36+
return response.data.data;
37+
} catch (e) {
38+
console.error(e);
39+
throw e;
40+
}
41+
};
42+
3243
export const getNoticeDetail = async (id: string) => {
3344
try {
3445
const response = await httpClient.get<ApiNoticeDetail>(`/notice/${id}`);

src/components/admin/previewComponent/noticePreview/NoticePreview.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import * as S from './NoticePreview.styled';
2-
import { useGetNotice } from '../../../../hooks/user/useGetNotice';
32
import line from '../../../../assets/line.svg';
43
import { Spinner } from '../../../common/loadingSpinner/LoadingSpinner.styled';
4+
import { useGetNoticePreview } from '../../../../hooks/admin/useGetAllNoticePreview';
55

66
const NoticePreview = () => {
7-
const { noticeData, isLoading, isFetching } = useGetNotice({
8-
keyword: '',
9-
page: 1,
10-
});
7+
const { noticeData, isLoading, isFetching } = useGetNoticePreview();
118

129
if (isLoading || isFetching) {
1310
return (
@@ -17,13 +14,13 @@ const NoticePreview = () => {
1714
);
1815
}
1916

20-
if (!noticeData?.notices || noticeData.notices.length === 0) {
17+
if (!noticeData) {
2118
return <S.Container>공지사힝이 없습니다.</S.Container>;
2219
}
2320

2421
return (
2522
<S.Container>
26-
{noticeData.notices.map((notice) => (
23+
{noticeData.map((notice) => (
2724
<S.Wrapper key={notice.id}>
2825
<S.Dot src={line} />
2926
<S.NoticeTitle>{notice.title}</S.NoticeTitle>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
import { CustomerService } from '../queries/keys';
3+
import { getNoticePreview } from '../../api/customerService.api';
4+
5+
export const useGetNoticePreview = () => {
6+
const {
7+
data: noticeData,
8+
isLoading,
9+
isFetching,
10+
} = useQuery({
11+
queryKey: [CustomerService.noticePreview],
12+
queryFn: () => getNoticePreview(),
13+
select: (notice) => notice.notices.slice(0, 5),
14+
staleTime: Infinity,
15+
gcTime: Infinity,
16+
});
17+
18+
return { noticeData, isLoading, isFetching };
19+
};

0 commit comments

Comments
 (0)