From ef944aa20b88463765e631c5160c0b5a508174aa Mon Sep 17 00:00:00 2001 From: seung365 Date: Thu, 8 Aug 2024 00:57:53 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20response=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/types/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/types/index.ts b/src/types/index.ts index b988a74..71901ac 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -60,3 +60,9 @@ export interface MailGetData { day: string; job: string; } + +export interface MailListResponse { + subjet: string; + body: string; + createDate: string; +} From 8c50d2c736be98c410ec3ffe5b3da2055c426e88 Mon Sep 17 00:00:00 2001 From: seung365 Date: Thu, 8 Aug 2024 00:59:44 +0900 Subject: [PATCH 2/8] =?UTF-8?q?feat:=20useGetMailUniv=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/hooks/Mail/useGetMailUniv.tsx | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/api/hooks/Mail/useGetMailUniv.tsx diff --git a/src/api/hooks/Mail/useGetMailUniv.tsx b/src/api/hooks/Mail/useGetMailUniv.tsx new file mode 100644 index 0000000..889c733 --- /dev/null +++ b/src/api/hooks/Mail/useGetMailUniv.tsx @@ -0,0 +1,3 @@ +import { BASE_URL } from '@/api'; + +export const getMailPath = () => `${BASE_URL}/`; From f7e689426c3b2ca2a60adea41b96bc5ed1d642c6 Mon Sep 17 00:00:00 2001 From: seung365 Date: Thu, 8 Aug 2024 01:00:08 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20=EB=A7=88=EC=9D=B4=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/MyPage/index.tsx | 70 ++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/src/pages/MyPage/index.tsx b/src/pages/MyPage/index.tsx index c21f38b..05f747b 100644 --- a/src/pages/MyPage/index.tsx +++ b/src/pages/MyPage/index.tsx @@ -1,37 +1,55 @@ import { useAuth } from '@/Provider/Auth'; -import { Grid, GridItem } from '@chakra-ui/react'; -import styled from '@emotion/styled'; +import { useMail } from '@/Provider/MailContext'; +import { + Box, + Grid, + GridItem, + VStack, + HStack, + Text, + Avatar, + Heading, + Divider, +} from '@chakra-ui/react'; export const MyPage = () => { const { authInfo } = useAuth(); + const { isActive } = useMail(); + return ( - - - -

User Information

-

{authInfo?.name}

-

{authInfo?.email}

- 사용자 프로필 + + + + + 사용자 정보 + + {authInfo?.name} + {authInfo?.email} + - -

메일 내역

- + + + 메일 내역 + {[1, 2, 3].map((_, index) => ( + + + 메일 제목 {index + 1} + + 2024년 08월 {25 - index}일 + + + + 안녕하세요. 어떠고입니다. 더욱이 아니라, 외려를 써버 드러고자 애썼 드라며 + 되었습니다. 저희 7시에서 5\u0013으로 되었을 채워오셔도 J배열 보펠브져덮이여 상환 + 서업의 떼로작는 거커... + + + + ))} +
-
+ ); }; - -export const Wrapper = styled.div` - width: 100%; - height: 1000px; -`; From d8add261c844a468ae3472b409511afdf22fada1 Mon Sep 17 00:00:00 2001 From: seung365 Date: Thu, 8 Aug 2024 01:01:55 +0900 Subject: [PATCH 4/8] =?UTF-8?q?chore:=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/hooks/Mail/useGetMail.tsx | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 src/api/hooks/Mail/useGetMail.tsx diff --git a/src/api/hooks/Mail/useGetMail.tsx b/src/api/hooks/Mail/useGetMail.tsx deleted file mode 100644 index 889c733..0000000 --- a/src/api/hooks/Mail/useGetMail.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import { BASE_URL } from '@/api'; - -export const getMailPath = () => `${BASE_URL}/`; From 48318444b8cf9ef4a617311d0a47cf816b84b20e Mon Sep 17 00:00:00 2001 From: seung365 Date: Thu, 8 Aug 2024 02:05:43 +0900 Subject: [PATCH 5/8] =?UTF-8?q?feat:=20mail=20get=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/types/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/types/index.ts b/src/types/index.ts index 71901ac..c0b90a0 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -62,7 +62,7 @@ export interface MailGetData { } export interface MailListResponse { - subjet: string; - body: string; - createDate: string; + totalPages: number; + content: [{ subjet: string; body: string; createDate: string }]; + pageable: { pageNumber: number; pageSize: number }; } From d64b19290fa7c07e3791eb05f625464a2b26ebb7 Mon Sep 17 00:00:00 2001 From: seung365 Date: Thu, 8 Aug 2024 02:05:59 +0900 Subject: [PATCH 6/8] =?UTF-8?q?feat:=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/MyPage/index.tsx | 120 +++++++++++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 18 deletions(-) diff --git a/src/pages/MyPage/index.tsx b/src/pages/MyPage/index.tsx index 05f747b..1898116 100644 --- a/src/pages/MyPage/index.tsx +++ b/src/pages/MyPage/index.tsx @@ -1,5 +1,4 @@ import { useAuth } from '@/Provider/Auth'; -import { useMail } from '@/Provider/MailContext'; import { Box, Grid, @@ -10,12 +9,38 @@ import { Avatar, Heading, Divider, + Button, + Spinner, } from '@chakra-ui/react'; +import { useGetMailBusiness } from '@/api/hooks/Mail/useGetMailBusiness'; +import { useGetMailUniv } from '@/api/hooks/Mail/useGetMailUniv'; +import { useState } from 'react'; export const MyPage = () => { const { authInfo } = useAuth(); - const { isActive } = useMail(); + const [isJob, setIsJob] = useState('univ'); + + const [univPage, setUnivPage] = useState(0); + const [businessPage, setBusinessPage] = useState(0); + + const { univData, univLoading, univError } = useGetMailUniv(univPage, 5); + const { businessData, businessLoading, businessError } = useGetMailBusiness(businessPage, 5); + const handlePrev = () => { + if (isJob === 'univ') { + setUnivPage((prev) => Math.max(prev - 1, 0)); + } else { + setBusinessPage((prev) => Math.max(prev - 1, 0)); + } + }; + + const handleNext = () => { + if (isJob === 'univ') { + setUnivPage((prev) => (univData && !univData.totalPages ? prev + 1 : prev)); + } else { + setBusinessPage((prev) => (businessData && !businessData.totalPages ? prev + 1 : prev)); + } + }; return ( @@ -31,22 +56,81 @@ export const MyPage = () => { 메일 내역 - {[1, 2, 3].map((_, index) => ( - - - 메일 제목 {index + 1} - - 2024년 08월 {25 - index}일 - - - - 안녕하세요. 어떠고입니다. 더욱이 아니라, 외려를 써버 드러고자 애썼 드라며 - 되었습니다. 저희 7시에서 5\u0013으로 되었을 채워오셔도 J배열 보펠브져덮이여 상환 - 서업의 떼로작는 거커... - - - - ))} + + + + {isJob === 'univ' ? ( + univLoading ? ( + + ) : univError ? ( + 오류가 발생했습니다. + ) : ( + univData?.content.map((email, index) => ( + + + {email.subjet} + + {email.createDate} + + + {email.body} + + + )) + ) + ) : businessLoading ? ( + + ) : businessError ? ( + 오류가 발생했습니다. + ) : ( + businessData?.content.map((email, index) => ( + + + {email.subjet} + + {email.createDate} + + + {email.body} + + + )) + )} + + + + + From a6ef3e2866440586a02810241f09caaf8a6341d0 Mon Sep 17 00:00:00 2001 From: seung365 Date: Thu, 8 Aug 2024 02:06:17 +0900 Subject: [PATCH 7/8] =?UTF-8?q?feat:=20getmailuniv=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/hooks/Mail/useGetMailUniv.tsx | 36 ++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/api/hooks/Mail/useGetMailUniv.tsx b/src/api/hooks/Mail/useGetMailUniv.tsx index 889c733..17cc5d8 100644 --- a/src/api/hooks/Mail/useGetMailUniv.tsx +++ b/src/api/hooks/Mail/useGetMailUniv.tsx @@ -1,3 +1,37 @@ import { BASE_URL } from '@/api'; +import axios from 'axios'; +import { MailListResponse } from '@/types'; +import { useQuery } from '@tanstack/react-query'; -export const getMailPath = () => `${BASE_URL}/`; +export const getMailPath = (page: number, size: number) => + `${BASE_URL}/emails?page=${page}&size=${size}`; + +const token = sessionStorage.getItem('accessToken'); + +const apiClient = axios.create({ + baseURL: BASE_URL, + headers: { + Authorization: `Bearer ${token}`, + job: `univ`, + }, +}); + +const getMailUniv = async (page: number, size: number) => { + try { + const response = await apiClient.get(getMailPath(page, size)); + return response.data; + } catch (error) { + console.error('Error fetching mail:', error); + throw error; + } +}; + +export const useGetMailUniv = (page: number, size: number) => { + const { + data: univData, + isLoading: univLoading, + isError: univError, + } = useQuery({ queryKey: ['emails', page, size], queryFn: () => getMailUniv(page, size) }); + + return { univData, univLoading, univError }; +}; From 9a0ba6b8e72e95cb444fae0c801b0ac38a2bc5f0 Mon Sep 17 00:00:00 2001 From: seung365 Date: Thu, 8 Aug 2024 02:06:30 +0900 Subject: [PATCH 8/8] =?UTF-8?q?feat:=20getmailbusiness=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/hooks/Mail/useGetMailBusiness.tsx | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/api/hooks/Mail/useGetMailBusiness.tsx diff --git a/src/api/hooks/Mail/useGetMailBusiness.tsx b/src/api/hooks/Mail/useGetMailBusiness.tsx new file mode 100644 index 0000000..95679eb --- /dev/null +++ b/src/api/hooks/Mail/useGetMailBusiness.tsx @@ -0,0 +1,36 @@ +import { BASE_URL } from '@/api'; +import axios from 'axios'; +import { MailListResponse } from '@/types'; +import { useQuery } from '@tanstack/react-query'; + +export const getMailPath = (page: number, size: number) => + `${BASE_URL}/emails?page=${page}&size=${size}`; + +const token = sessionStorage.getItem('accessToken'); + +const apiClient = axios.create({ + baseURL: BASE_URL, + headers: { + Authorization: `Bearer ${token}`, + job: `business`, + }, +}); + +const getMailBusiness = async (page: number, size: number) => { + try { + const response = await apiClient.get(getMailPath(page, size)); + return response.data; + } catch (error) { + console.error('Error fetching mail:', error); + throw error; + } +}; + +export const useGetMailBusiness = (page: number, size: number) => { + const { + data: businessData, + isLoading: businessLoading, + isError: businessError, + } = useQuery({ queryKey: ['emails', page, size], queryFn: () => getMailBusiness(page, size) }); + return { businessData, businessLoading, businessError }; +};