diff --git a/src/shared/model/footerActions.ts b/src/shared/model/footerActions.ts index 07c991b..4a6e11f 100644 --- a/src/shared/model/footerActions.ts +++ b/src/shared/model/footerActions.ts @@ -49,6 +49,7 @@ export const deleteActions = (fetchExpoList: () => Promise) => ({ } }, }); + export const routeActions = ( router: ReturnType, navigation: string, diff --git "a/src/shared/types/\bSignUp/type.ts" "b/src/shared/types/\bSignUp/type.ts" deleted file mode 100644 index c2a73fa..0000000 --- "a/src/shared/types/\bSignUp/type.ts" +++ /dev/null @@ -1,7 +0,0 @@ -export interface SignUpItem extends Record { - id: number; - name: string; - nickname: string; - email: string; - phoneNumber: string; -} diff --git a/src/shared/types/admin/type.ts b/src/shared/types/admin/type.ts new file mode 100644 index 0000000..b27f276 --- /dev/null +++ b/src/shared/types/admin/type.ts @@ -0,0 +1,16 @@ +export interface ExpoItem extends Record { + id: number; + coverImage: string; + title: string; + description: string; + startedDay: string; + finishedDay: string; +} + +export interface SignUpItem extends Record { + id: number; + name: string; + nickname: string; + email: string; + phoneNumber: string; +} diff --git a/src/shared/types/Expo/type.ts b/src/shared/types/main/type.ts similarity index 100% rename from src/shared/types/Expo/type.ts rename to src/shared/types/main/type.ts diff --git a/src/widgets/admin/api/getAdminData.ts b/src/widgets/admin/api/getAdminData.ts new file mode 100644 index 0000000..e331be3 --- /dev/null +++ b/src/widgets/admin/api/getAdminData.ts @@ -0,0 +1,12 @@ +import axios from 'axios'; +import { ExpoItem, SignUpItem } from '@/shared/types/admin/type'; + +export const getExpoList = async (): Promise => { + const response = await axios.get('/api/expo'); + return response.data; +}; + +export const getRequestSignUp = async (): Promise => { + const response = await axios.get('/api/admin'); + return response.data; +}; diff --git a/src/widgets/admin/model/category.ts b/src/widgets/admin/model/category.ts new file mode 100644 index 0000000..b1a1e5e --- /dev/null +++ b/src/widgets/admin/model/category.ts @@ -0,0 +1,15 @@ +export const expoListCategories = [ + '번호', + '박람회이름', + '박람회 설명', + '모집 시작 날짜', + '모집 종료 날짜', +]; + +export const requestSignUpCategories = [ + '번호', + '성명', + '아이디', + '이메일', + '연락처', +]; diff --git a/src/widgets/admin/model/useAdminData.ts b/src/widgets/admin/model/useAdminData.ts new file mode 100644 index 0000000..d63e561 --- /dev/null +++ b/src/widgets/admin/model/useAdminData.ts @@ -0,0 +1,19 @@ +import { useQuery } from '@tanstack/react-query'; +import { ExpoItem, SignUpItem } from '@/shared/types/admin/type'; +import { getExpoList, getRequestSignUp } from '../api/getAdminData'; + +export const useAdminData = () => { + const expoListData = useQuery({ + queryKey: ['expoList'], + queryFn: getExpoList, + }); + + const requestSignUpData = useQuery({ + queryKey: ['requestSignUp'], + queryFn: getRequestSignUp, + }); + + const isLoading = expoListData.isLoading || requestSignUpData.isLoading; + + return { expoListData, requestSignUpData, isLoading }; +}; diff --git a/src/widgets/admin/ui/AdminPageWrapper/index.tsx b/src/widgets/admin/ui/AdminPageWrapper/index.tsx index 0b7b4c5..d61cddb 100644 --- a/src/widgets/admin/ui/AdminPageWrapper/index.tsx +++ b/src/widgets/admin/ui/AdminPageWrapper/index.tsx @@ -1,84 +1,60 @@ 'use client'; -import axios from 'axios'; -import React, { useEffect, useState } from 'react'; +import withLoading from '@/shared/hocs/withLoading'; import { checkActions, deleteActions } from '@/shared/model/footerActions'; -import { SignUpItem } from '@/shared/types/\bSignUp/type'; -import { ExpoItem } from '@/shared/types/Expo/type'; import { TableForm } from '@/shared/ui/Table'; +import { + expoListCategories, + requestSignUpCategories, +} from '../../model/category'; +import { useAdminData } from '../../model/useAdminData'; const AdminPageWrapper = () => { - const [expoList, setExpoList] = useState([]); - const [requestSignUp, setRequestSignUp] = useState([]); - - const fetchExpoList = async () => { - const response = await axios.get('/api/expo'); - setExpoList( - response.data.map( - ({ coverImage: _coverImage, ...rest }: ExpoItem) => rest, - ), - ); - }; - - const fetchRequestSignUp = async () => { - const response = await axios.get('/api/admin'); - setRequestSignUp(response.data); - }; - - useEffect(() => { - fetchExpoList(); - fetchRequestSignUp(); - }, []); - - const expoListCategories = [ - '번호', - '박람회이름', - '박람회 설명', - '모집 시작 날짜', - '모집 종료 날짜', - ]; - - const requestSignUpCategories = [ - '번호', - '성명', - '아이디', - '이메일', - '연락처', - ]; - - const checkSignupActions = checkActions(fetchRequestSignUp); - const deleteExpoActions = deleteActions(fetchExpoList); - - return ( -
-
-

회원가입 요청

-
- + const { expoListData, requestSignUpData, isLoading } = useAdminData(); + + const checkSignupActions = checkActions(async () => { + await requestSignUpData.refetch(); + }); + const deleteExpoActions = deleteActions(async () => { + await expoListData.refetch(); + }); + + const expoList = expoListData.data || []; + const requestSignUp = requestSignUpData.data || []; + + return withLoading({ + isLoading, + children: ( +
+
+

회원가입 요청

+
+ +
-
-
-

등록된 박람회

-
- +
+

등록된 박람회

+
+ +
-
- ); + ), + }); }; export default AdminPageWrapper; diff --git a/src/widgets/main/api/getExpoList.ts b/src/widgets/main/api/getExpoList.ts index 1027234..9d6ded5 100644 --- a/src/widgets/main/api/getExpoList.ts +++ b/src/widgets/main/api/getExpoList.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { ExpoItem } from '@/shared/types/Expo/type'; +import { ExpoItem } from '@/shared/types/main/type'; export const getExpoList = async (): Promise => { const response = await axios.get('/api/expo'); diff --git a/src/widgets/main/model/useExpoList.ts b/src/widgets/main/model/useExpoList.ts index d919956..ab4827f 100644 --- a/src/widgets/main/model/useExpoList.ts +++ b/src/widgets/main/model/useExpoList.ts @@ -1,5 +1,5 @@ import { useQuery } from '@tanstack/react-query'; -import { ExpoItem } from '@/shared/types/Expo/type'; +import { ExpoItem } from '@/shared/types/main/type'; import { getExpoList } from '../api/getExpoList'; export const useExpoList = () => {