From d9594980af1fe2eaf32dcd3f2d3119cf178b161f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EA=B2=BD?= Date: Sun, 3 Mar 2024 12:07:29 +0900 Subject: [PATCH] =?UTF-8?q?feat=20#18=20fetch=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/goods.ts | 87 +++++++++++++------ src/api/mypage.ts | 31 +++++-- src/api/register.ts | 42 ++++++--- src/api/user.ts | 77 ++++++++++------ .../components/GoodsNoticeModify/index.tsx | 17 +++- src/{utils.ts => utils.tsx} | 1 + 6 files changed, 177 insertions(+), 78 deletions(-) rename src/{utils.ts => utils.tsx} (99%) diff --git a/src/api/goods.ts b/src/api/goods.ts index dc11658..b3c9ea9 100644 --- a/src/api/goods.ts +++ b/src/api/goods.ts @@ -27,9 +27,13 @@ export const getGoodsList = async ( longitudeDelta: (arr[3] - arr[2]).toFixed(6), }); - const response = await jigumeAxios.get(`/api/goods/marker?${query}`, { - headers: axiosHeaderAuth, - }); + const response = await jigumeAxios + .get(`/api/goods/marker?${query}`, { + headers: axiosHeaderAuth, + }) + .catch((res) => { + throw Error(res); + }); return response.data; }; @@ -41,7 +45,10 @@ export const getSheetGoods = async ( const response = await jigumeAxios .get(`/api/goods/${preViewer.goodsId}`, { headers: axiosHeaderAuth }) - .then((res) => res.data); + .then((res) => res.data) + .catch((res) => { + throw Error(res); + }); return response; }; @@ -75,9 +82,13 @@ export const getSheetList = async ( longitudeDelta: (arr[3] - arr[2]).toFixed(6), }); - const response = await jigumeAxios.get(`/api/goods/marker/list?${query}`, { - headers: axiosHeaderAuth, - }); + const response = await jigumeAxios + .get(`/api/goods/marker/list?${query}`, { + headers: axiosHeaderAuth, + }) + .catch((res) => { + throw Error(res); + }); return response.data; }; @@ -87,7 +98,10 @@ export const getGoodsPage = async ( ): Promise => { const response = await jigumeAxios .get(`/api/goods/${id}`, { headers: axiosHeaderAuth }) - .then((res) => res.data); + .then((res) => res.data) + .catch((res) => { + throw Error(res); + }); return response; }; @@ -102,12 +116,16 @@ export const setWishGoods = async ({ // await console.log('hello', isWished); const response = !isWished - ? await jigumeAxios.post( - `/api/wish/${id}`, - {}, - { headers: axiosHeaderAuth } - ) - : await jigumeAxios.delete(`/api/wish/${id}`, { headers: axiosHeaderAuth }); + ? await jigumeAxios + .post(`/api/wish/${id}`, {}, { headers: axiosHeaderAuth }) + .catch((res) => { + throw Error(res); + }) + : await jigumeAxios + .delete(`/api/wish/${id}`, { headers: axiosHeaderAuth }) + .catch((res) => { + throw Error(res); + }); return response.data; }; @@ -115,7 +133,10 @@ export const setWishGoods = async ({ export const deleteWishGoods = async (id: number | string) => { const response = await jigumeAxios .delete(`/api/wish/${id}`, { headers: axiosHeaderAuth }) - .then((res) => res.data); + .then((res) => res.data) + .catch((res) => { + throw Error(res); + }); return response; }; @@ -126,7 +147,10 @@ export const getNotice = async ( ): Promise => { const response = await jigumeAxios .get(`/api/goods/${goodsId}/board/${boardId}`, { headers: axiosHeaderAuth }) - .then((res) => res.data); + .then((res) => res.data) + .catch((res) => { + throw Error(res); + }); return response; }; @@ -139,7 +163,10 @@ export const getComment = async ( .get(`/api/goods/${goodsId}/board/${boardId}/comment`, { headers: axiosHeaderAuth, }) - .then((res) => res.data); + .then((res) => res.data) + .catch((res) => { + throw Error(res); + }); return response; }; @@ -157,7 +184,10 @@ export const postCommentAtBoard = async ( }, { headers: axiosHeaderAuth } ) - .then((res) => res.data); + .then((res) => res.data) + .catch((res) => { + throw Error(res); + }); return response; }; @@ -182,7 +212,10 @@ export const postCommentAtComment = async ({ }, { headers: axiosHeaderAuth } ) - .then((res) => res.data); + .then((res) => res.data) + .catch((res) => { + throw Error(res); + }); return response; }; @@ -190,24 +223,24 @@ export const postCommentAtComment = async ({ export const postModifyNotice = async ({ goodsId, boardId, - parentCommentId, - content, + boardContent, }: { goodsId: number | string; boardId: number | string; - parentCommentId: number; - content: string; + boardContent: string; }) => { const response = await jigumeAxios .post( - `/api/goods/${goodsId}/board/${boardId}/comment/reply`, + `/api/goods/${goodsId}/board/${boardId}`, { - parentCommentId, - content, + boardContent, }, { headers: axiosHeaderAuth } ) - .then((res) => res.data); + .then((res) => res.data) + .catch((res) => { + throw Error(res); + }); return response; }; diff --git a/src/api/mypage.ts b/src/api/mypage.ts index 0951c02..9952e77 100644 --- a/src/api/mypage.ts +++ b/src/api/mypage.ts @@ -3,24 +3,37 @@ import { OrderHistoryDto, SellHistoryDto } from '@src/types/mypage'; import { axiosHeaderAuth, jigumeAxios } from './axios'; export const getProfile = async (): Promise => { - const response = await jigumeAxios.get('/api/member/profile', { - headers: axiosHeaderAuth, - }); + const response = await jigumeAxios + .get('/api/member/profile', { + headers: axiosHeaderAuth, + }) + .catch((res) => { + throw Error(res); + }); return response.data; }; export const getProgressLead = async (): Promise => { - const response = await jigumeAxios.get('/api/sell/PROCESSING', { - headers: axiosHeaderAuth, - }); + const response = await jigumeAxios + .get('/api/sell/PROCESSING', { + headers: axiosHeaderAuth, + }) + .catch((res) => { + throw Error(res); + }); return response.data; }; export const getProgressJoin = async (): Promise => { - const response = await jigumeAxios.get('/api/order/PROCESSING', { - headers: axiosHeaderAuth, - }); + const response = await jigumeAxios + .get('/api/order/PROCESSING', { + headers: axiosHeaderAuth, + }) + .catch((res) => { + throw Error(res); + }); + return response.data; }; diff --git a/src/api/register.ts b/src/api/register.ts index be15da9..a81f212 100644 --- a/src/api/register.ts +++ b/src/api/register.ts @@ -32,7 +32,7 @@ export const postGoods = async ( }) .then(async (res) => { const goodsId = res.data; - console.log('GOODS ID', goodsId); + // console.log('GOODS ID', goodsId); await jigumeAxios .post( `/api/goods/${goodsId}/coordinate/new`, @@ -43,15 +43,25 @@ export const postGoods = async ( { headers: axiosHeaderAuth } ) .then(async () => { - await jigumeAxios.post( - `/api/goods/${goodsId}/board`, - { - content: goodsDto_.boardContent, - }, - { headers: axiosHeaderAuth } - ); + await jigumeAxios + .post( + `/api/goods/${goodsId}/board`, + { + content: goodsDto_.boardContent, + }, + { headers: axiosHeaderAuth } + ) + .catch((err) => { + throw Error(err); + }); + }) + .catch((err) => { + throw Error(err); }); return res.data; + }) + .catch((err) => { + throw Error(err); }); return response; @@ -78,12 +88,16 @@ export const getPlaces = async ({ Authorization: `KakaoAK ${KAKAO_KEY}`, }, }).then((res) => { - return res.data.documents.map((item: NearPlacesType) => ({ - ...item, - distance: Number(item.distance), - x: Number(item.x), - y: Number(item.y), - })); + return res.data.documents + .map((item: NearPlacesType) => ({ + ...item, + distance: Number(item.distance), + x: Number(item.x), + y: Number(item.y), + })) + .catch((err: Error) => { + throw Error(err.message); + }); }); return response; }; diff --git a/src/api/user.ts b/src/api/user.ts index 5745f5e..177fbc0 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -15,11 +15,15 @@ export const updateMemberInfo = async (param: { latitude: number; longitude: number; }) => { - const response = await jigumeAxios.post('/api/member/info', { - nickname: param.nickname, - longitude: 0, - latitude: 0, - }); + const response = await jigumeAxios + .post('/api/member/info', { + nickname: param.nickname, + longitude: 0, + latitude: 0, + }) + .catch((err) => { + throw Error(err); + }); return response.data; }; @@ -35,9 +39,13 @@ export const handleRefreshToken = async (auth: AuthType) => { ) return 'valid'; - const response = await jigumeAxios.post('/api/member/token', { - refreshToken: auth.refreshToken, - }); + const response = await jigumeAxios + .post('/api/member/token', { + refreshToken: auth.refreshToken, + }) + .catch((err) => { + throw Error(err); + }); return response.data; }; @@ -58,28 +66,41 @@ export const codeProvide = async ( {}, { headers: axiosHeaderAuth } ) - .then((res) => res.data); + .then((res) => res.data) + .catch((err) => { + throw Error(err); + }); return response; }; export const kakaoLogout = async () => { // kakao 서버에 요청 - const response = await axios.post( - 'https://kapi.kakao.com/v1/user/logout', - {}, - { headers: axiosHeaderAuth } - ); + const response = await axios + .post( + 'https://kapi.kakao.com/v1/user/logout', + {}, + { headers: axiosHeaderAuth } + ) + .catch((err) => { + throw Error(err); + }); + return response; }; export const checkNickname = async (nickname: string) => { - const response = await jigumeAxios.get('/api/member/nickname', { - headers: axiosHeaderAuth, - params: { - nickname, - }, - }); + const response = await jigumeAxios + .get('/api/member/nickname', { + headers: axiosHeaderAuth, + params: { + nickname, + }, + }) + .catch((err) => { + throw Error(err); + }); + return response; }; @@ -93,12 +114,16 @@ export const updateProfile = async (file?: File) => { formData.append('multipartFile', file as File); } - const response = await jigumeAxios.post('/api/member/profile', formData, { - headers: { - ...axiosHeaderAuth, - 'Content-Type': 'multipart/form-data', - }, - }); + const response = await jigumeAxios + .post('/api/member/profile', formData, { + headers: { + ...axiosHeaderAuth, + 'Content-Type': 'multipart/form-data', + }, + }) + .catch((err) => { + throw Error(err); + }); return response.data; }; diff --git a/src/pages/Goods/components/GoodsNoticeModify/index.tsx b/src/pages/Goods/components/GoodsNoticeModify/index.tsx index 78b829b..56ae2f5 100644 --- a/src/pages/Goods/components/GoodsNoticeModify/index.tsx +++ b/src/pages/Goods/components/GoodsNoticeModify/index.tsx @@ -9,7 +9,7 @@ import ConfirmAlert from '../ConfirmAlert'; import NoticeModifyHeader from './components/NoticeModifyHeader'; export default function GoodsNoticeModify() { - const { isSuccess, isNoticeSuccess, notice } = + const { goods, isSuccess, isNoticeSuccess, notice } = useOutletContext(); const [newNotice, setNewNotice] = useState(''); const [isConfirm, setIsConfirm] = useState(false); @@ -23,6 +23,15 @@ export default function GoodsNoticeModify() { postModifyNotice ); + const handleModifyNotice = () => { + if (newNotice !== notice.content && newNotice.length === 0) + modifyNotice({ + goodsId: goods.goodsPageDto.goodsId, + boardId: goods.goodsPageDto.boardId, + boardContent: newNotice, + }); + }; + useEffect(() => { if (isSuccess && isNoticeSuccess) setNewNotice(notice.content); }, [isSuccess, isNoticeSuccess]); @@ -37,7 +46,11 @@ export default function GoodsNoticeModify() { return (
완료} + rightMenu={ + + } curr={newNotice} prev={notice.content} setIsConfirm={setIsConfirm} diff --git a/src/utils.ts b/src/utils.tsx similarity index 99% rename from src/utils.ts rename to src/utils.tsx index a2cf050..14d50e3 100644 --- a/src/utils.ts +++ b/src/utils.tsx @@ -142,6 +142,7 @@ export const stringLatLng2Arr = (bound: kakao.maps.LatLngBounds) => { }; export const getToken = (): { accessToken: string; refreshToken: string } => { + // const [token] = useRecoilState(authState); try { const local = localStorage.getItem('recoil-persist'); const token = JSON.parse(local as string)?.jigumeAuth;