Skip to content

Commit

Permalink
Merge pull request #121 from KUIT-Space/feat#96-space-home
Browse files Browse the repository at this point in the history
feat : ๋ฉค๋ฒ„ ์ดˆ๋Œ€ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
  • Loading branch information
YangJJune authored Aug 20, 2024
2 parents 5aff0c8 + 4e1d1d3 commit 6bf2c03
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import InviteSpace from "./pages/SpacePage/InviteSpace";
import HomePageMemberPage from "./pages/HomePage/HomePageMember";
import HomePageProfile from "./pages/HomePage/HomePageProfile";
import SpecialVoiceRoom from "./pages/VoiceRoomPage/SpecialVoiceRoom";
import InviteSpace2 from "./pages/SpacePage/InviteSpace2";

// will we need constant path in later..?
// const PATH = {
Expand Down Expand Up @@ -139,6 +140,7 @@ function App() {
{ path: "/space/spaceoption/profilemanage", element: <ProfileManage /> },
{ path: "/space/spaceoption/alarmmanage", element: <AlarmManage /> },
{ path: "/invite", element: <InviteSpace /> },
{ path: "/invite/:spaceId", element: <InviteSpace2 /> },
];

const routes_children_login = [
Expand Down
2 changes: 1 addition & 1 deletion src/apis/Space/SpaceJoinInfoApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createRequestOptionsJSON_AUTH, fetchApi } from "@/apis/_createRequestOptions";

interface SpaceJoinInfo {
export interface SpaceJoinInfo {
spaceProfileImg: string | null; // ์ŠคํŽ˜์ด์Šค ์ธ๋„ค์ผ ์ด๋ฏธ์ง€ url
spaceName: string; // ์ŠคํŽ˜์ด์Šค ์ด๋ฆ„
createdAt: string; // ์ŠคํŽ˜์ด์Šค ๊ฐœ์„ค์ผ (yyyy๋…„ mm์›” dd์ผ ํ˜•์‹)
Expand Down
41 changes: 39 additions & 2 deletions src/pages/HomePage/HomePageMember.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import AddMemberImg from "@/assets/ChatPage/btn_add_member.svg";
import TopBarText, { LeftEnum } from "@/components/TopBarText";
import { Member, MemberContainer } from "@/pages/ChatPage/ChatCreatePage/ChatCreatePage.styled";
import { getUserDefaultImageURL } from "@/utils/getUserDefaultImageURL";
import * as s from "@/pages/HomePage/HomePage.styled";
import { ToastContainer, toast } from "react-toastify";

const HomePageMemberPage = () => {
const { id } = useParams();
const navigate = useNavigate();

const [userList, setUserList] = useState<User[]>([]);
Expand All @@ -23,6 +24,23 @@ const HomePageMemberPage = () => {
});
}, []);

const clickInviteHandler = async () => {
const spaceId = localStorage.getItem("spaceId");
await navigator.clipboard
.writeText(`${window.location.origin}/KUIT-Space-front/invite/${spaceId}`)
.then(() => {
toast.success("ํด๋ฆฝ๋ณด๋“œ์— ์ดˆ๋Œ€๋งํฌ๊ฐ€ ๋ณต์‚ฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!", {
position: "bottom-center",
autoClose: 3000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "dark",
});
});
};
return (
<>
<TopBarText
Expand All @@ -45,7 +63,13 @@ const HomePageMemberPage = () => {

<MemberContainer>
{/* //TODO: ์ž์‹ ์ด ๊ด€๋ฆฌ์ž์ผ ๋•Œ๋งŒ ๋œจ๋Š” ๋ทฐ */}

<s.RowFlexDiv
onClick={clickInviteHandler}
style={{ alignItems: "center", padding: "1rem 0rem 1rem 0rem", cursor: "pointer" }}
>
<img src={AddMemberImg} width={"40px"} height={"40px"}></img>
<div style={{ marginLeft: "1rem" }}>์ŠคํŽ˜์ด์Šค์— ์ดˆ๋Œ€ํ•˜๊ธฐ</div>
</s.RowFlexDiv>
{userList.map((member, index) => (
<Member
key={member.userId}
Expand All @@ -62,6 +86,19 @@ const HomePageMemberPage = () => {
</Member>
))}
</MemberContainer>
<ToastContainer
style={{ width: "50%", left: "50%", transform: "translateX(-50%)" }}
position="top-center"
autoClose={3000}
hideProgressBar={false}
newestOnTop={false}
closeOnClick
rtl={false}
pauseOnFocusLoss
draggable
pauseOnHover
theme="dark"
/>
</>
);
};
Expand Down
209 changes: 209 additions & 0 deletions src/pages/SpacePage/InviteSpace2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
import { ChangeEvent, useEffect, useState } from "react";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import styled from "styled-components";

import { SpaceInfo as SpaceInfoType } from "@/apis/Space/SpaceSelectApi";
import { SpaceUserJoinApi } from "@/apis/Space/SpaceUserJoinApi";
import { CharacterImgs } from "@/assets/Characters";
import ChatroomImg from "@/assets/ChatPage/btn_chatroom_img.svg";
import back from "@/assets/icon_back.svg";
import { BottomBtn } from "@/components/BottomBtn";
import { Input } from "@/components/Input";
import { getUserDefaultImageURL } from "@/utils/getUserDefaultImageURL";
import { svgComponentToFile } from "@/utils/svgComponentToFile";

import { ChatroomAddImgBtn } from "../ChatPage/ChatCreatePage/ChatCreatePage.styled";
import { SpaceJoinInfo, SpaceJoinInfoApi } from "@/apis";

const TopBarContainer = styled.div`
display: flex;
height: 52px;
align-items: center;
`;

const BackBtn = styled.img`
width: 36px;
height: 36px;
cursor: pointer;
`;

const InfoContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
margin-top: 132px;
`;

const SpaceImage = styled.img`
width: 160px;
height: 160px;
border-radius: 12px;
margin-bottom: 20px;
`;

const SpaceTitle = styled.span`
font-size: 24px;
font-weight: semi-bold;
margin-bottom: 20px;
`;
const SpaceInfo = styled.span`
height: 22px;
font-size: 16px;
color: ${({ theme }) => theme.colors.BG500};
`;

const Count = styled.span`
position: absolute;
right: 1rem;
top: 50%;
transform: translateY(-50%);
font-size: 16px;
color: ${({ theme }) => theme.colors.BG500};
`;

const NameInput = styled(Input)`
padding-right: 4rem; /* Count๋ฅผ ์œ„ํ•œ ์—ฌ์œ  ๊ณต๊ฐ„ */
margin-top: 8px;
`;

const SpaceJoinBottomBtn = styled(BottomBtn)`
display: fixed;
bottom: 1;
margin: 0;
`;

const InviteSpace2 = () => {
const navigate = useNavigate();
const { spaceId } = useParams();

const [spaceInfo, setSpaceInfo] = useState<SpaceJoinInfo>();
const [currentStep, setCurrentStep] = useState(1);
const [spacename, setSpacename] = useState("");
const [spaceUserMsg, setSpaceUserMsg] = useState("");
const maxChars = 12;

const [uploadedImage, setUploadedImage] = useState<File | null>(null);
const defaultImage: File = svgComponentToFile(
CharacterImgs[Math.floor(Math.random() * CharacterImgs.length)],
);

useEffect(() => {
//TODO: spaceInfo๊ฐ€ ์—†์„ ๋•Œ์˜ ๋”๋ฏธ ๋ฐ์ดํ„ฐ
console.log(spaceId);
const response = SpaceJoinInfoApi(Number.parseInt(spaceId!)).then((data) => {
setSpaceInfo(data?.result);
});
}, []);

const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
if (value.length <= maxChars) {
setSpacename(value);
}
};

const handleNextButtonClick = () => {
if (currentStep === 2) {
//TODO: ๊ฐ€์ž…ํ•˜๊ธฐ API ํ˜ธ์ถœ / userImg, userName
SpaceUserJoinApi(
Number.parseInt(spaceId!),
uploadedImage ?? defaultImage,
spacename,
spaceUserMsg,
).then((res) => {
if (res) navigate("/");
});
}
setCurrentStep((prevStep) => prevStep + 1);
};

const handlePreviousButtonClick = () => {
setCurrentStep((prevStep) => prevStep - 1);
};

const handleImageImport = (e: React.ChangeEvent<HTMLInputElement>) => {
const image = e.target.files?.[0];
image && setUploadedImage(image);
};

return (
<div>
{currentStep === 1 && (
<InfoContainer>
<SpaceImage
src={spaceInfo?.spaceProfileImg ?? getUserDefaultImageURL(Number.parseInt(spaceId!))}
/>
<SpaceTitle>{spaceInfo?.spaceName}</SpaceTitle>
<div>
<div style={{ marginBottom: "0.5rem" }}>
<SpaceInfo style={{ marginRight: "0.75rem" }}>๊ฐœ์„ค์ผ</SpaceInfo>
<SpaceInfo>
{isNaN(Date.parse(spaceInfo?.createdAt ?? ""))
? spaceInfo?.createdAt
: spaceInfo?.createdAt &&
new Date(spaceInfo?.createdAt).toLocaleDateString("ko-KR")}
</SpaceInfo>
</div>
<div>
<SpaceInfo style={{ marginRight: "0.75rem" }}>๋ฉค๋ฒ„</SpaceInfo>
<SpaceInfo>{spaceInfo?.memberNum}๋ช…</SpaceInfo>
</div>
</div>
</InfoContainer>
)}
{currentStep === 2 && (
<div>
<TopBarContainer>
<BackBtn src={back} onClick={handlePreviousButtonClick} />
</TopBarContainer>

<ChatroomAddImgBtn $backgroundImage={URL.createObjectURL(uploadedImage ?? defaultImage)}>
<img src={ChatroomImg} alt="Chatroom Image" />
<input type="file" accept="image/*" onChange={handleImageImport} />
</ChatroomAddImgBtn>

<div style={{ marginTop: "16px" }}>
์ด๋ฆ„
<div style={{ position: "relative" }}>
<NameInput
value={spacename}
onChange={handleInputChange}
placeholder="์ŠคํŽ˜์ด์Šค์—์„œ ์‚ฌ์šฉํ•  ์ด๋ฆ„"
/>
<Count>
{spacename.length}/{maxChars}
</Count>
</div>
</div>

<div style={{ marginTop: "16px" }}>
์ƒํƒœ ๋ฉ”์„ธ์ง€
<div style={{ position: "relative" }}>
<NameInput
value={spaceUserMsg}
onChange={(e) => {
const value = e.target.value;
if (value.length <= maxChars * 5) {
setSpaceUserMsg(value);
}
}}
placeholder="์ŠคํŽ˜์ด์Šค ์ƒํƒœ ๋ฉ”์„ธ์ง€"
/>
<Count>
{spaceUserMsg.length}/{maxChars * 5}
</Count>
</div>
</div>
</div>
)}
<SpaceJoinBottomBtn
disabled={currentStep === 2 && spacename === "" ? true : false}
onClick={handleNextButtonClick}
>
๊ฐ€์ž…ํ•˜๊ธฐ
</SpaceJoinBottomBtn>
</div>
);
};

export default InviteSpace2;

0 comments on commit 6bf2c03

Please sign in to comment.