Skip to content

Commit

Permalink
Merge pull request #98 from KUIT-Space/feat#51-chat_detail
Browse files Browse the repository at this point in the history
Fix: signup user flow & verification logic
  • Loading branch information
Turtle-Hwan authored Aug 19, 2024
2 parents d87f064 + d40eac6 commit f80a37c
Show file tree
Hide file tree
Showing 12 changed files with 412 additions and 289 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function Layout({ routes_children }: { routes_children: RouteChildren[] }) {
<LayoutContainer>
<div id="content">
<Outlet />
<LoginModal />
<LoginModal exceptionRouters={["/login", "/signup"]} />
</div>
{routes_children.find((child) => matchPath(child.path, pathname))?.hasBottomBar && (
<BottomNavBar />
Expand Down
14 changes: 14 additions & 0 deletions src/apis/Chat/Socket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Stomp } from "@stomp/stompjs";
import SockJS from "sockjs-client";

import { createRequestOptionsJSON_AUTH, fetchApi } from "@/apis/_createRequestOptions";

export const SocketConnect = (
stompClient: any,
chatRoomId: string,
Expand All @@ -13,6 +15,7 @@ export const SocketConnect = (
if (!token || !stompClient.current.onConnect) {
//๋กœ๊ทธ์ธ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ
//alert("๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.");
console.log("!token || !stompClient.current.onConnect, ๋กœ๊ทธ์ธ ์˜ค๋ฅ˜");
return;
}

Expand All @@ -37,3 +40,14 @@ export const SocketDisconnect = (stompClient: any) => {
stompClient.current.disconnect();
}
};

/** */
export const ChatroomLeave = async (chatRoomId: number) => {
const requestOptions = createRequestOptionsJSON_AUTH("POST");
const spaceId = Number(localStorage.getItem("spaceId"));
if (!requestOptions || !spaceId) return null;

const url = `${import.meta.env.VITE_API_BACK_URL}/space/${spaceId}/chat/${chatRoomId}/leave`;

return await fetchApi(url, requestOptions);
};
17 changes: 14 additions & 3 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
export * from "@/apis/LoginApi";
export * from "@/apis/voiceroomApi";
export * from "@/apis/GetUserProfileApi";

export * from "@/apis/Chat/ChatroomSearchAllApi";
export * from "@/apis/Chat/ChatroomCreateApi";
export * from "@/apis/Chat/ChatType";
export * from "@/apis/Chat/ChatroomUpdateNameApi";
export * from "@/apis/Chat/ChatroomCreateApi";
export * from "@/apis/Chat/ChatroomExitDelete";
export * from "@/apis/Chat/ChatroomSearchAllApi";
export * from "@/apis/Chat/ChatroomSearchAllUserApi";
export * from "@/apis/Chat/ChatroomUpdateNameApi";

export * from "@/apis/Chat/Socket";

export * from "@/apis/Pay/PayPageAPI";

export * from "@/apis/Space/SpaceCreateApi";
export * from "@/apis/Space/SpaceJoinInfoApi";
export * from "@/apis/Space/SpaceSearchAllUserApi";
export * from "@/apis/Space/SpaceSearchUserProfile";
export * from "@/apis/Space/SpaceSelectApi";
export * from "@/apis/Space/SpaceUserJoinApi";

export * from "@/apis/_createRequestOptions";
64 changes: 32 additions & 32 deletions src/components/SignUpHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
import React from "react";
import styled from "styled-components";

import back from "@/assets/icon_back.svg";
import { useNavigate } from "react-router-dom";

const HeaderContainer = styled.div`
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 3.25rem;
padding: 0.5rem 0;
position: relative;
max-width: 40rem;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 3.25rem;
padding: 0.5rem 0;
position: relative;
max-width: 40rem;
margin: 0 auto;
`;

const Back = styled.button`
position: absolute;
left: 0.63rem;
width: 2.25rem;
height: 2.25rem;
cursor: pointer;
position: absolute;
left: 0.63rem;
width: 2.25rem;
height: 2.25rem;
cursor: pointer;
`;

const Title = styled.div`
color: #fff;
font-family: Freesentation;
font-size: 1.25rem;
font-style: normal;
font-weight: 500;
line-height: 120%;
letter-spacing: 0.05rem;
color: #fff;
font-family: Freesentation;
font-size: 1.25rem;
font-style: normal;
font-weight: 500;
line-height: 120%;
letter-spacing: 0.05rem;
`;

interface HeaderProps {
title: string;
onBackClick: () => void;
title: string;
onBackClick: () => void;
}

const SignUpHeader: React.FC<HeaderProps> = ({ title, onBackClick }) => {
return (
<HeaderContainer>
<Back onClick={onBackClick}>
<img src={back} alt="Back" />
</Back>
<Title>{title}</Title>
</HeaderContainer>
);
return (
<HeaderContainer>
<Back onClick={onBackClick}>
<img src={back} alt="Back" />
</Back>
<Title>{title}</Title>
</HeaderContainer>
);
};

export default SignUpHeader;
10 changes: 10 additions & 0 deletions src/pages/ChatPage/ChatPage.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const ChatContainer = styled.div`
}
.chat--container {
position: relative;
display: flex;
flex-direction: column;
flex-grow: 1;
Expand Down Expand Up @@ -77,6 +78,7 @@ export const ChatContainer = styled.div`
.chat-btn-detail {
max-width: 13.5rem;
max-height: 4.125rem;
color: var(--Foundation-Gray-gray300, var(--GRAY-300, #d4d4d9));
/* text/Regular 14pt */
Expand All @@ -85,6 +87,14 @@ export const ChatContainer = styled.div`
font-weight: 400;
line-height: 140%; /* 19.6px */
letter-spacing: 0.035rem;
img {
width: auto;
height: 100%;
position: absolute;
right: 4rem;
top: 0;
}
}
.chat-btn-chatNum {
Expand Down
7 changes: 5 additions & 2 deletions src/pages/ChatPage/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ const ChatPage = () => {

// fetch๋กœ data ๋ฐ›์•„์˜ค๋Š” ๋ถ€๋ถ„
// ์ž„์‹œ๋กœ LOCALSTORAGE์— spaceId 3์œผ๋กœ ์ €์žฅ
localStorage.setItem("spaceId", "3");
// localStorage.setItem("spaceId", "3");
//
const spaceId = localStorage.getItem("spaceId");
if (spaceId !== null) {
if (spaceId === null) {
console.log("spacdId === null");
navigate("/space");
} else if (spaceId !== null) {
chatroomSearchAllApi(Number.parseInt(spaceId))
.then((res) => {
if (res === null) {
Expand Down
8 changes: 6 additions & 2 deletions src/pages/ChatPage/ChattingPage/ChattingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ChatPay,
ChatPost,
Chatroom,
ChatroomLeave,
ChatSendRequestFrame,
ChatText,
SocketConnect,
Expand Down Expand Up @@ -78,8 +79,11 @@ const ChattingPage = () => {
});

SocketConnect(stompClient, param.id || "", handleChatMessage);
return () => SocketDisconnect(stompClient);
}, [param.id, spaceId]);
return () => {
SocketDisconnect(stompClient);
ChatroomLeave(chatroomInfo.id).then((res) => console.log(res)); //์‚ฌ์šฉ์ž ์ฑ„ํŒ…๋ฐฉ ๋– ๋‚จ ์•Œ๋ ค์ฃผ๊ธฐ (unsubscribe..?)
};
}, [param.id, spaceId, chatroomInfo.id]);

//
//
Expand Down
4 changes: 2 additions & 2 deletions src/pages/LoginPage/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { useLocation, useNavigate } from "react-router-dom";

import StopModal from "@/components/StopModal";

export const LoginModal = () => {
export const LoginModal = ({ exceptionRouters }: { exceptionRouters: string[] }) => {
const navigate = useNavigate();
const location = useLocation(); // ํ˜„์žฌ ๊ฒฝ๋กœ๋ฅผ ๊ฐ€์ ธ์˜ด

const [isModalOpen, setIsModalOpen] = useState(false);

useEffect(() => {
if (location.pathname === "/login") {
if (exceptionRouters.includes(location.pathname)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const LoginPage = () => {
const handleLogin = async () => {
if (!isButtonActive) return;
loginApi(email, password).then((res) =>
res.status === "OK" ? navigate("/") : alert("login error: " + res.message),
res.status === "OK" ? navigate("/space") : alert("login error: " + res.message),
);
};

Expand Down
Loading

0 comments on commit f80a37c

Please sign in to comment.