From d25f2d2c96e506afdb753beb7375258b72737cb0 Mon Sep 17 00:00:00 2001 From: jisu Seo Date: Fri, 10 Nov 2023 15:47:28 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/axios.ts | 4 ++++ apis/chatListAPI.ts | 14 ++++++++++++++ pages/all-chat-list/chatList.module.scss | 0 pages/all-chat-list/index.tsx | 23 +++++++++++++++++++++++ pages/my-chat-list/MyChatList.module.scss | 0 pages/my-chat-list/index.tsx | 23 +++++++++++++++++++++++ 6 files changed, 64 insertions(+) create mode 100644 apis/chatListAPI.ts create mode 100644 pages/all-chat-list/chatList.module.scss create mode 100644 pages/all-chat-list/index.tsx create mode 100644 pages/my-chat-list/MyChatList.module.scss create mode 100644 pages/my-chat-list/index.tsx diff --git a/apis/axios.ts b/apis/axios.ts index ad5413c1..ae969ec7 100644 --- a/apis/axios.ts +++ b/apis/axios.ts @@ -1,10 +1,14 @@ import axios from 'axios'; +const accessToken = + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImNiN2ZiMTExZTp1c2VyMyIsImlhdCI6MTY5OTUzMzExMiwiZXhwIjoxNzAwMTM3OTEyfQ.4eslctzcBGQAwkcKT97IbF0i-9-MZ0kvhjY4A6sK8Wo'; + const instance = axios.create({ baseURL: 'https://fastcampus-chat.net', // 여기에 공통 설정을 추가할 수 있습니다. headers: { 'Content-Type': 'application/json', + Authorization: `Bearer ${accessToken}`, serverId: process.env.NEXT_PUBLIC_API_KEY, }, }); diff --git a/apis/chatListAPI.ts b/apis/chatListAPI.ts new file mode 100644 index 00000000..dbada7bc --- /dev/null +++ b/apis/chatListAPI.ts @@ -0,0 +1,14 @@ +import instance from './axios'; + +const chatListAPI = { + // 로그인 + getAllChatList() { + return instance.get('/chat/all'); + }, + // 회원가입 + getMyChatList() { + return instance.get('/chat'); + }, +}; + +export default chatListAPI; diff --git a/pages/all-chat-list/chatList.module.scss b/pages/all-chat-list/chatList.module.scss new file mode 100644 index 00000000..e69de29b diff --git a/pages/all-chat-list/index.tsx b/pages/all-chat-list/index.tsx new file mode 100644 index 00000000..0b57347e --- /dev/null +++ b/pages/all-chat-list/index.tsx @@ -0,0 +1,23 @@ +import { useState, useEffect } from 'react'; +import Link from 'next/link'; +import chatListAPI from '../../apis/chatListAPI'; + +export default function AllChatList() { + const [allChatList, setAllChatList] = useState([]); + const getAllChat = async () => { + const chatAllList = await chatListAPI.getAllChatList(); + setAllChatList(chatAllList.data.chats); + }; + useEffect(() => { + getAllChat(); + }, []); + return ( + <> + {allChatList.map(chat => ( + +
{chat.name}
+ + ))} + + ); +} diff --git a/pages/my-chat-list/MyChatList.module.scss b/pages/my-chat-list/MyChatList.module.scss new file mode 100644 index 00000000..e69de29b diff --git a/pages/my-chat-list/index.tsx b/pages/my-chat-list/index.tsx new file mode 100644 index 00000000..021b5286 --- /dev/null +++ b/pages/my-chat-list/index.tsx @@ -0,0 +1,23 @@ +import { useState, useEffect } from 'react'; +import Link from 'next/link'; +import chatListAPI from '../../apis/chatListAPI'; + +export default function MyChatList() { + const [myChatList, setMyChatList] = useState([]); + const getMyChat = async () => { + const ChatMyList = await chatListAPI.getMyChatList(); + setMyChatList(ChatMyList.data.chats); + }; + useEffect(() => { + getMyChat(); + }, []); + return ( + <> + {myChatList.map(chat => ( + +
{chat.name}
+ + ))} + + ); +}