Skip to content

Commit

Permalink
Merge pull request #121 from Hanaemong/#120
Browse files Browse the repository at this point in the history
[feat] QnA 페이지 추가
  • Loading branch information
abcxj123 authored Jul 10, 2024
2 parents 9c72abb + 626c926 commit d0fea42
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 34 deletions.
7 changes: 7 additions & 0 deletions src/apis/domains/chatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ export class chatApi extends ApiClient {
const response = await this.axiosInstance<ChatType>(`/chat/last/${teamId}`);
return response;
}

async getNickDupl(nickname: string) {
const response = await this.axiosInstance<boolean>(
`/chat/dupl?nickname=${nickname}`
);
return response;
}
}
62 changes: 42 additions & 20 deletions src/components/chat/ChatTopbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ interface IProps {
title: string;
member: number;
teamId: number;
isQnA?: boolean;
}

const ChatTopbar: FC<IProps> = ({ title, member, teamId }) => {
const ChatTopbar: FC<IProps> = ({ title, member, teamId, isQnA }) => {
const navigate = useNavigate();

const onClickTeam = () => {
Expand All @@ -23,27 +24,48 @@ const ChatTopbar: FC<IProps> = ({ title, member, teamId }) => {

return (
<div className="sticky top-0 left-0 w-full z-10">
<div className="flex flex-row bg-white px-2 py-7 gap-4 items-center">
<div
className="cursor-pointer"
onClick={() => {
navigate(-1);
}}
>
<GoChevronLeft size={30} />
</div>
<div
className={`flex flex-row bg-white px-2 py-7 gap-4 items-center ${
isQnA && "justify-center"
} `}
>
{!isQnA && (
<div
className="cursor-pointer"
onClick={() => {
navigate(-1);
}}
>
<GoChevronLeft size={30} />
</div>
)}
<div className="flex flex-col gap-2">
<p className="text-3xl font-hanaBold">{title}</p>
<p
className={`text-3xl font-hanaBold ${
isQnA && "w-full text-center"
}`}
>
{title}
</p>
<div className="flex flex-row gap-2 font-hanaRegular text-hanaPurple text-2xl">
<p>{member}명 참여중</p>
<p>|</p>
<div
className="flex flex-row cursor-pointer"
onClick={() => onClickTeam()}
>
<p>모임 바로가기</p>
<GoChevronRight size={20} />
</div>
{!isQnA && (
<>
<p>{member}명 참여중</p>
<p>|</p>
<div
className="flex flex-row cursor-pointer"
onClick={() => onClickTeam()}
>
<p>모임 바로가기</p>
<GoChevronRight size={20} />
</div>
</>
)}
{isQnA && (
<p className="w-full text-center pt-1">
🎉6개월 동안 다들 고생하셨습니다.🎉
</p>
)}
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
Members,
My,
Plan,
QnA,
Qrcode,
Search,
Sending,
Expand Down Expand Up @@ -44,6 +45,7 @@ const router = createBrowserRouter([
{ path: "sending", element: <Sending /> },
{ path: "create-plan", element: <Plan /> },
{ path: "qrcode", element: <Qrcode /> },
{ path: "QnA", element: <QnA /> },
{
element: <Navbar />,
children: [
Expand Down
119 changes: 119 additions & 0 deletions src/pages/QnA.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { useRef, useState } from "react";
import { Button, Topbar } from "../components";
import { useNavigate } from "react-router-dom";
import { chatApi } from "../apis/domains/chatApi";
import { setCookie } from "../utils/cookie";

const QnA = () => {
const navigate = useNavigate();

const [dupl, setDupl] = useState<boolean>(false);
const [isActive, setIsActive] = useState<boolean>(false);
const inputRef = useRef<HTMLInputElement | null>(null);
const [image, setImage] = useState<number>(0);

const urls = [
"https://hanalinkbucket.s3.ap-northeast-2.amazonaws.com/image+(5).png",
"https://hanalinkbucket.s3.ap-northeast-2.amazonaws.com/image+(2).png",
"https://hanalinkbucket.s3.ap-northeast-2.amazonaws.com/image+(4).png",
"https://hanalinkbucket.s3.ap-northeast-2.amazonaws.com/image+(3).png",
];

const onClickDupl = () => {
try {
chatApi
.getInstance()
.getNickDupl(inputRef.current!.value)
.then((res) => {
if (res.data) {
setIsActive(false);
setDupl(true);
} else {
setIsActive(true);
setDupl(false);
}
});
} catch (err) {
console.log(err);
}
};

const onClickButton = () => {
setCookie("nickname", inputRef.current!.value);
setCookie("profile", urls[image]);
navigate("/chat-room", {
state: {
teamId: -1,
memberCnt: 0,
teamName: "알파코 하나링크 QnA",
},
});
};

const onChangeInput = () => {
isActive && setIsActive(false);
};

return (
<section className="border-[1px] border-hanaPurple">
<div className="flex flex-col">
<Topbar title="QnA" prohibit />
<div className="w-full bg-custom-light-gradient h-[0.15rem]" />
<div className="flex flex-col min-h-real-screen2 p-10 justify-between">
<div className="flex flex-col mt-10 gap-32">
{/* 닉네임 영역 */}
<div className="flex flex-col items-center gap-4 mt-10 pr-7">
<p className="text-3xl font-hanaRegular">닉네임</p>
<div className="flex flex-row pl-32 items-center gap-7">
<input
type="text"
className="p-3 w-64 h-16 border-2 border-hanaPurple text-2xl rounded-3xl"
maxLength={8}
onChange={() => onChangeInput()}
ref={inputRef}
/>
<div
className="cursor-pointer bg-hanaPurple text-white text-xl font-hanaRegular flex items-center p-3 rounded-3xl"
onClick={() => onClickDupl()}
>
중복검사
</div>
</div>
{dupl && (
<p className="text-xl text-red-500">
중복된 닉네임이 있습니다.
</p>
)}
</div>
{/* 사진 영역 */}
<div className="flex flex-col items-center gap-4 mt-10">
<p className="text-3xl font-hanaRegular">프로필사진</p>
<div className="flex flex-row gap-4">
{urls.map((item, index) => (
<img
key={index}
src={item}
alt="profile"
className={`p-2 cursor-pointer size-28 border-hanaPurple rounded-2xl ${
index === image ? "border-[3px]" : "border-[1px]"
}`}
onClick={() => setImage(index)}
/>
))}
</div>
</div>
</div>
<div className="flex justify-center">
<Button
text="입장"
isActive={isActive}
onClick={() => onClickButton()}
/>
</div>
</div>
</div>
</section>
);
};

export default QnA;
1 change: 1 addition & 0 deletions src/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export { default as ChatRoom } from "./team/ChatRoom";
export { default as Plan } from "./team/Plan";
export { default as Landing } from "./Landing";
export { default as Qrcode } from "./team/Qrcode";
export { default as QnA } from "./QnA";
44 changes: 30 additions & 14 deletions src/pages/team/ChatRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SockJS from "sockjs-client";
import { timeConvertor } from "../../utils/datetimeFormat";
import { teamMemberApi } from "../../apis/domains/teamMemberApi";
import { useLocation } from "react-router-dom";
import { getCookie } from "../../utils/cookie";

const ChatRoom = () => {
const location = useLocation();
Expand Down Expand Up @@ -80,19 +81,33 @@ const ChatRoom = () => {
(divRef.current.scrollTop =
divRef.current.scrollHeight - divRef.current.clientHeight);
try {
teamMemberApi
.getInstance()
.getMyTeamNickname(locationState.teamId)
.then((res) => {
setMyNickname(res.data?.nickname!);
setMyProfile(res.data?.profile!);
chatApi
.getInstance()
.getChatHistory(locationState.teamId)
.then((res) => {
setOldMsg(toChatArr(res.data));
});
});
if (
getCookie("nickname") == undefined &&
getCookie("profile") == undefined
) {
teamMemberApi
.getInstance()
.getMyTeamNickname(locationState.teamId)
.then((res) => {
setMyNickname(res.data?.nickname!);
setMyProfile(res.data?.profile!);
chatApi
.getInstance()
.getChatHistory(locationState.teamId)
.then((res) => {
setOldMsg(toChatArr(res.data));
});
});
} else {
setMyNickname(getCookie("nickname"));
setMyProfile(getCookie("profile"));
chatApi
.getInstance()
.getChatHistory(locationState.teamId)
.then((res) => {
setOldMsg(toChatArr(res.data));
});
}
} catch (err) {
console.log(err);
}
Expand Down Expand Up @@ -159,6 +174,7 @@ const ChatRoom = () => {
title={locationState.teamName}
member={locationState.memberCnt}
teamId={locationState.teamId}
isQnA={getCookie("nickname") != undefined}
/>
<div
className="flex-grow flex flex-col overflow-auto scrollbar-hide"
Expand Down Expand Up @@ -186,7 +202,7 @@ const ChatRoom = () => {
className={`bg-[#D9D9D9] w-11/12 font-hanaRegular text-xl focus:outline-none py-4 pl-4 pr-14 rounded-3xl overflow-y-hidden`}
/>
<div
className="absolute right-9 text-hanaPurple text-2xl font-hanaMedium"
className="absolute right-11 text-hanaPurple text-2xl font-hanaMedium"
onClick={() => sendHandler()}
>
전송
Expand Down

0 comments on commit d0fea42

Please sign in to comment.